void evidence_cl_cons() { color *c1 = (color*)malloc(sizeof(color)); c1->r = 1; c1->g = 2; c1->b = 3; color *c2 = (color*)malloc(sizeof(color)); c2->r = 2; c2->g = 1; c2->b = 4; colorlist *root = (colorlist*)malloc(sizeof(colorlist)); root->next = 0; root->c = *c2; colorlist *test_cl = (colorlist*)malloc(sizeof(colorlist)); test_cl->c = *c1; test_cl->next = root; printf("*** testing cl_cons\n"); colorlist *my_cl = cl_cons(c1, test_cl); cl_print(my_cl); printf("\n"); colorlist *my_cl1 = cl_cons(c2, test_cl); cl_print(my_cl1); printf("\n"); free(c1); free(c2); free(root); free(test_cl); }
/* test the colorlist structs and its functions */ void evidence_colorlist() { printf("TESTING COLORLIST\n\n"); int size = 6; color* colors [6]; double param = 0.2; for(int i = 0; i < size; ++i) { colors[i] = color_new(i * param, i * param, i * param); } colorlist* cl = cl_cons( colors[0], NULL); colorlist* tmp = cl; for(int i = 1; i < 6; ++i) { tmp -> next = cl_cons( colors[i], NULL); tmp = tmp -> next; } cl_print(cl); printf("expected length: 6\t|actual: %d\n", cl_length(cl) ); printf("expected max red: 1.000\t|actual: %.3f\n", cl_max_red(cl) ); //test null cl colorlist* nada = NULL; printf("expected length: 0\t|actual: %d\n", cl_length(nada) ); cl_max_red(nada); }
void evidence_cl_max_red() { colorlist *test_cl = (colorlist*)malloc(sizeof(colorlist)); color *c1 = (color*)malloc(sizeof(color)); c1->r = 0.1; c1->g = 1; c1->b = 1; color *c2 = (color*)malloc(sizeof(color)); c2->r = 0.12; c2->g = 0.5; c2->b = 0.7; test_cl->c = *c1; colorlist *root = (colorlist*)malloc(sizeof(colorlist)); root->next = 0; root->c = *c2; test_cl->next = root; colorlist *my_cl = cl_cons(c2, test_cl); printf("*** testing cl_max_red\n"); printf("- expecting 0.12: %lf\n", cl_max_red(test_cl)); printf("- expecting 0.12: %lf\n", cl_max_red(my_cl)); printf("\n"); free(c1); free(c2); free(root); free(test_cl); }
void evidence_cl_length() { colorlist *test_cl = (colorlist*)malloc(sizeof(colorlist)); color *c1 = (color*)malloc(sizeof(color)); c1->r = 1; c1->g = 1; c1->b = 1; color *c2 = (color*)malloc(sizeof(color)); c2->r = 0; c2->g = 0.5; c2->b = 0.7; test_cl->c = *c1; colorlist *root = (colorlist*)malloc(sizeof(colorlist)); root->next = 0; root->c = *c2; test_cl->next = root; colorlist *my_cl = cl_cons(c1, test_cl); printf("*** testing cl_length\n"); printf("- expecting 2: %d\n", cl_length(test_cl)); printf("- expecting 3: %d\n", cl_length(my_cl)); printf("\n"); free(c1); free(c2); free(root); free(test_cl); }
cl_object cl_function_lambda_expression(cl_object fun) { cl_env_ptr the_env = ecl_process_env(); cl_object output, name = ECL_NIL, lex = ECL_NIL; switch(ecl_t_of(fun)) { case t_bclosure: lex = fun->bclosure.lex; fun = fun->bclosure.code; case t_bytecodes: name = fun->bytecodes.name; output = fun->bytecodes.definition; if (name == ECL_NIL) output = cl_cons(ECL_SYM("LAMBDA",452), output); else if (name != ECL_SYM("SI::BYTECODES",1659)) output = cl_listX(3, ECL_SYM("EXT::LAMBDA-BLOCK",1339), name, output); break; case t_cfun: case t_cfunfixed: name = fun->cfun.name; lex = ECL_NIL; output = ECL_NIL; break; case t_cclosure: name = ECL_NIL; lex = ECL_T; output = ECL_NIL; break; #ifdef CLOS case t_instance: if (fun->instance.isgf) { name = ECL_NIL; lex = ECL_NIL; output = ECL_NIL; break; } #endif default: FEinvalid_function(fun); } ecl_return3(the_env, output, lex, name); }