int main(void) { int ntest = 0, exitval = 0; struct c_rbtree *r; /* Create hashtable. */ testresult("create rbtree", r = c_rbtree_new(c_stringequals)); /* Insert data. */ testresult("insert rbtree 1", c_rbtree_insert(r, strdup("charly"), strdup("bacon"))); testresult("insert rbtree 2", c_rbtree_insert(r, strdup("charlene"), strdup("apple"))); /* Fetch data. */ test_expect_str("lookup rbtree 1", c_rbtree_lookup(r, "charly"), "bacon"); test_expect_str("lookup rbtree 2", c_rbtree_lookup(r, "charlene"), "apple"); /* Replace it. */ testresult("replace rbtree existing", c_rbtree_replace(r, strdup("charly"), strdup("fries"))); /* Fetch it again. */ test_expect_str("lookup rbtree 3", c_rbtree_lookup(r, "charly"), "fries"); test_expect_str("lookup rbtree 4", c_rbtree_lookup(r, "charlene"), "apple"); /* Insert new data with replace. */ testresult("replace rbtree new", c_rbtree_replace(r, strdup("elephant"), strdup("peanuts"))); /* Fetch that too. */ test_expect_str("lookup rbtree 5", c_rbtree_lookup(r, "elephant"), "peanuts"); /* Remove it all. - not implemented yet */ /* testresult("clear rbtree", c_rbtree_remove_all(r)); */ /* Destroy rbtree. - not implemented yet */ /* c_rbtree_destroy(r); */ /* testresult("destroy rbtree", 1); */ exit(exitval ? EXIT_FAILURE : EXIT_SUCCESS); }
int main(int argc, char *argv[]){ double r; int i; int *lut_c; int *lut_f; polynom *erg; /* getopt */ int c; opterr = 0; while((c=getopt(argc, argv, "r:m:s:")) != -1) { switch(c) { case 'r': R0=atof(optarg); break; case 'm': AD_MAX=atoi(optarg); break; case 's': AD_STEP=atoi(optarg); break; case '?': if (optopt == 'r' || optopt == 'm' || optopt == 's'){ fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else if (isprint (optopt)) { fprintf(stderr, "Unknown option '-%c'.\n", optopt); } else { fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt); } /* fall through */ default: usage(argv[0]); return 1; } } if(optind != argc-1 || R0 <=0 || AD_MAX <=0 || AD_STEP <= 0){ usage(argv[0]); return 1; } printf("Using: R0 = %lf, AD_MAX = %d, AD_STEP = %d\n", R0, AD_MAX, AD_STEP); readtable(argv[optind]); orthonormal(basis); erg = approx(); testresult(erg); for(i=0; i<4; i++){ a[i] = (*erg)[i]; } lut_c = malloc(sizeof(int) * LUT_SIZE); lut_f = malloc(sizeof(int) * LUT_SIZE); lut_c[0]=0; lut_f[0]=0; for(i=1; i<LUT_SIZE; i++){ r = rtot(ad_to_r(i*AD_STEP)); lut_c[i] = (int)round(r * 10.0); lut_f[i] = (int)round(C_TO_F(r) * 10.0); } printf("//Celsius\n"); printf("const int ad_lookup[] = { 0"); for(i=1; i<LUT_SIZE; i++){ printf(", %d", lut_c[i]); } printf(" };\n"); printf("//Fahrenheit\n"); printf("const int ad_lookup[] = { 0"); for(i=1; i<LUT_SIZE; i++){ printf(", %d", lut_f[i]); } printf(" };\n"); }