示例#1
0
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);
}
/* 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);  

}