void test_distance(void){ struct point s[3]; s[0] = create_point(1,1,0); s[1] = create_point(1,0,0); s[2] = create_point(2.3,4.4,-1.3); checkit_double(distance(s[1],s[2]),4.768648); checkit_double(distance(s[1],s[0]),1); }
void test_distance_all() { struct point p1 = create_point(-2.3,1.1); struct point p2 = create_point(-3.3,-4.5); struct point p3 = create_point(3.6,1.2); struct point input5[]={p1,p2,p3}; double result5[3]; distance_all(input5,3,result5); checkit_double(result5[0],2.54950976); checkit_double(result5[1],5.580322571); checkit_double(result5[2],3.79473319220); struct point p4 = create_point(4.5,2.2); struct point p5 = create_point(0,-3.2); struct point p6 = create_point(-2.2,1.9); struct point p7 = create_point(3.4,-6.5); struct point p8 = create_point(-6.6,-7.7); struct point p9 = create_point(2.1,0); struct point input6[]={p4,p5,p6,p7,p8,p9}; double result6[6]; distance_all(input6,6,result6); checkit_double(result6[0],5.00899191454); checkit_double(result6[1],3.2); checkit_double(result6[2],2.906883); checkit_double(result6[3],7.3355299); checkit_double(result6[4],10.14149890); checkit_double(result6[5],2.1); }
void test_cases(void) { checkit_int(0 + 1, 1); checkit_int(2 * 2, 4); checkit_int(19 / 3, 6); checkit_double(19.0 / 3, 6.333333); checkit_double(19 / 3.0, 6.333333); checkit_double(19.0 / 3.0, 6.333333); checkit_int(4 * 2 +27 / 3 + 4, 21); checkit_int(4 * (2 + 27) / 3 + 4, 42); }
void max_test_cases(void) { double a = 1.0; double b = 2.0; double max1 = max(a, b); checkit_double(max1, 2.0); double a1 = 4.0; double b1 = 3.0; double max2 = max(a1, b1); checkit_double(max2, 4.0); }
void min_test_cases(void) { double a = 1.0; double b = 2.0; double min1 = min(a,b); checkit_double(min1, 1.0); double a1 = 4.0; double b1 = 3.0; double min2 = min(a1, b1); checkit_double(min2, 3.0); }
void test_cases(void) {struct vehicle vehicle2d; double x1 = 1.0; double y1 = 2.0; double x2 = 3.0; double y2 = 4.0; vehicle2d = create_vehicle(x1, y1, x2, y2); checkit_double(vehicle2d.x1, 1.0); checkit_double(vehicle2d.y1, 2.0); checkit_double(vehicle2d.x2, 3.0); checkit_double(vehicle2d.y2, 4.0); }
void max_of_three_test_cases(void) { double a = 1.0; double b = 2.0; double c = 3.0; double max1 = max(a, max(b, c)); checkit_double(max1, 3.0); double a1 = 4.0; double b1 = 3.0; double c1 = 2.0; double max2 = max(a1, max(b1, c1)); checkit_double(max2, 4.0); }
void test_convert_double() { char s1[]={"3.4\0"}; double a = convert_double(s1,4.2); checkit_double(a,3.4); char s2[]={"asdfcxzv\0"}; double b = convert_double(s2,3.2); checkit_double(b,3.2); char s3[]={"asdfdfs3.4asdfasdf\0"}; double c = convert_double(s3,32.1); checkit_double(c,32.1); char s4[]={"-3.2\0"}; double d = convert_double(s4,4.2); checkit_double(d,-3.2); }
void test_cases(void) { struct monster l= create_monster(2,3,4.5,6); checkit_int(l.numEyes, 2); checkit_int(l.numArms,3); checkit_double(l.height, 4.5); checkit_int(l.numTails, 6); }
void poly_mult2_test_cases() { double poly1[3] = {2, 1, 3}; double poly2[3] = {1, 2, 3}; double result[5]; poly_mult2(poly1, poly2, result); checkit_double(result[0], 2); checkit_double(result[1], 5); checkit_double(result[2], 11); checkit_double(result[3], 10); checkit_double(result[4], 6); double poly1_1[3] = {3, 4, 5}; double poly1_2[3] = {5, 6, 7}; poly_mult2(poly1_1, poly1_2, result); checkit_double(result[0], 15); checkit_double(result[1], 38); checkit_double(result[2], 70); checkit_double(result[3], 41); checkit_double(result[4], 12); }
void test_sphere_intersection_point(void){ struct ray r = create_ray(create_point(0,0,0),create_vector(1.3,0,0)); struct sphere s = create_sphere(create_point(2.5,0,0),1.2); struct maybe_point test = sphere_intersection_point(r,s); checkit_double(test.p.x,1.3); checkit_double(test.p.y,0); checkit_double(test.p.z,0); checkit_int(test.isPoint,1); struct ray r2 = create_ray(create_point(-2.4,-2.9,-4.4),create_vector(-1,0,0)); struct sphere s2 = create_sphere(create_point(2.3,5.7,8.2),1); struct maybe_point test2 = sphere_intersection_point(r2,s2); checkit_int(test2.isPoint,0); struct ray r3 = create_ray(create_point(-4.3,0,4.7),create_vector(3.5,0,0)); struct sphere s3 = create_sphere(create_point(2.1,0,0),4.7); struct maybe_point test3 = sphere_intersection_point(r3,s3); checkit_int(test3.isPoint,1); struct ray r4 = create_ray(create_point(1.2,-5.4,4.2),create_vector(1.1,1.2,1.3)); struct sphere s4 = create_sphere(create_point(4.7,6.4,2.2),13.5); struct maybe_point test4 = sphere_intersection_point(r4,s4); checkit_double(test4.p.x,9.871860); checkit_double(test4.p.y,4.060210); checkit_double(test4.p.z,14.448561); checkit_int(test4.isPoint,1); }
void test_create_sphere(void){ struct sphere s = create_sphere(create_point(1.9,3.9,7.9), 45.55); checkit_double(s.center.x,1.9); checkit_double(s.center.y,3.9); checkit_double(s.center.z,7.9); checkit_double(s.radius,45.55); struct sphere s2 = create_sphere(create_point(5.8,9.8,1.8), 23.23); checkit_double(s2.center.x,5.8); checkit_double(s2.center.y,9.8); checkit_double(s2.center.z,1.8); checkit_double(s2.radius,23.23); }
void test_add_n_all() { double input3[]={-3.2,1.4,0.0,4.5}; double result3[4]; add_n_all(3.1,input3,4,result3); checkit_double(result3[0],-0.1); checkit_double(result3[1],4.5); checkit_double(result3[2],3.1); checkit_double(result3[3],7.6); double input4[]={3.5,-6.2,0.0,9.8,-10.2}; double result4[5]; add_n_all(-1.3,input4,5,result4); checkit_double(result4[0],2.2); checkit_double(result4[1],-7.5); checkit_double(result4[2],-1.3); checkit_double(result4[3],8.5); checkit_double(result4[4],-11.5); }
void test_square_all() { double input[]={1.3,3.2,-2.1,0.0}; double result[4]; square_all(input,4,result); checkit_double(result[0],1.69); checkit_double(result[1],10.24); checkit_double(result[2],4.41); checkit_double(result[3],0); double input2[]={-4.2,1.4,0.0,9.1,-2.1}; double result2[5]; square_all(input2,5,result2); checkit_double(result2[0],17.64); checkit_double(result2[1],1.96); checkit_double(result2[2],0.0); checkit_double(result2[3],82.81); checkit_double(result2[4],4.41); }
void test_create_point(void){ struct point p1 = create_point(1.5,2.5,3.5); checkit_double(p1.x,1.5); checkit_double(p1.y,2.5); checkit_double(p1.z,3.5); struct point p2 = create_point(23.2,35.4,12.32); checkit_double(p2.x,23.2); checkit_double(p2.y,35.4); checkit_double(p2.z,12.32); }
void test_create_vector(void){ struct vector v = create_vector(5.43,2.34,10.43); checkit_double(v.x,5.43); checkit_double(v.y,2.34); checkit_double(v.z,10.43); struct vector v2 = create_vector(234.3,435.3,1.3); checkit_double(v2.x,234.3); checkit_double(v2.y,435.3); checkit_double(v2.z,1.3); }
void test(void){ struct point p1 = create_point(1,3); struct point p2 = create_point(3,6); struct point p3 = create_point(5,0); struct point p4 = create_point(7,1); checkit_int(p1.x,1); checkit_int(p2.y,6); struct rect r1 = create_rect(p1, 3,2); struct rect r2 = create_rect(p2, 4,1); struct rect r3 = create_rect(p3,1,1); struct rect r4 = create_rect(p4,1,1); checkit_int(r1.w, 3); checkit_int(r2.h, 1); checkit_double(distance(p1,p3),5); struct rect r[3] = {r1,r2,r3}; checkit_int(largest_rect(r,3),0); struct point p[2]; closest_corners(r1,r2,p); checkit_int(p[0].x,4); checkit_int(p[0].y,5); checkit_int(p[1].x,3); checkit_int(p[1].y,6); struct point pt[2]; closest_corners(r2,r3,pt); checkit_int(pt[0].x,3); checkit_int(pt[0].y,6); checkit_int(pt[1].x,5); checkit_int(pt[1].y,1); struct point pts[2]; closest_corners(r3,r4,pts); checkit_int(pts[0].x,6); checkit_int(pts[0].y,1); checkit_int(pts[1].x,7); checkit_int(pts[1].y,1); }
void poly_add2_test_cases() { double poly1[3] = {2, 3.1, 2.7}; double poly2[3] = {1.2, 2.4, 0}; double result[3]; poly_add2(poly1, poly2, result); checkit_double(result[0], 3.2); checkit_double(result[1], 5.5); checkit_double(result[2], 2.7); double poly1_1[3] = {1, 2, 3}; double poly1_2[3] = {2, 3, 4}; double result1[3]; poly_add2(poly1_1, poly1_2, result1); checkit_double(result1[0], 3); checkit_double(result1[1], 5); checkit_double(result1[2], 7); }
void test_sphere_normal_at_point(void){ struct sphere s = create_sphere(create_point(4.2,3.5,6.5),5.715767665); struct point p = create_point(5.3,2.4,5.4); struct vector v = sphere_normal_at_point(s,p); checkit_double(v.x,.57735); checkit_double(v.y,-.57735); checkit_double(v.z,-.57735); struct sphere s2 = create_sphere(create_point(1.2,0,0),4.45); struct point p2 = create_point(6.65,0,0); struct vector v2 = sphere_normal_at_point(s2,p2); checkit_double(v2.x,1); checkit_double(v2.y,0); checkit_double(v2.z,0); }
void test_f(void){ checkit_double(f(1), 9.0); checkit_double(f(.5),2.75); }
void test_square(void){ checkit_double(square(3),9.0); checkit_double(square(1.2),1.44); }
void test_hypotenuse(void){ checkit_double(hypotenuse(3,4),5); checkit_double(hypotenuse(3.45,1.2),3.652738699); }
void test_g(void){ checkit_double(g(1,3),10.0); checkit_double(g(2.5,1.1),7.46); }
void test_find_intersection_points(void){ struct sphere s1 = create_sphere(create_point(4.2,0,0),1.3); struct sphere s2 = create_sphere(create_point(2.6,0,0),5.4); struct ray r = create_ray(create_point(-23.2,0,0),create_vector(.2,0,0)); struct sphere spheres[2] = {s1,s2}; struct sphere hit[2]; struct point pts[2]; checkit_int(find_intersection_points(spheres,2,r,hit,pts),2); checkit_double(pts[0].x, 2.9); checkit_double(pts[0].y, 0); checkit_double(pts[0].z, 0); checkit_double(pts[1].x, -2.8); checkit_double(pts[1].y, 0); checkit_double(pts[1].z, 0); checkit_double(hit[0].center.x, 4.2); checkit_double(hit[0].center.y, 0); checkit_double(hit[0].center.z, 0); checkit_double(hit[0].radius, 1.3); checkit_double(hit[1].center.x, 2.6); checkit_double(hit[1].center.y, 0); checkit_double(hit[1].center.z, 0); checkit_double(hit[1].radius, 5.4); struct sphere s3 = create_sphere(create_point(4.5,1.4,3.2),1.8); struct sphere s4 = create_sphere(create_point(2,4.3,5.4),3.2); struct sphere s5 = create_sphere(create_point(2.9,3.4,2.1),2.3); struct ray r2 = create_ray(create_point(1,1.3,.5),create_vector(1.3,1.4,1.8)); struct sphere spheres2[3] = {s3,s4,s5}; struct sphere hit2[3]; struct point pts2[3]; checkit_int(find_intersection_points(spheres2,3,r2,hit2,pts2),2); checkit_double(pts2[0].x, 2.489528); checkit_double(pts2[0].y, 2.904107); checkit_double(pts2[0].z, 2.562423); checkit_double(pts2[1].x, 1.492227); checkit_double(pts2[1].y, 1.830091); checkit_double(pts2[1].z, 1.181545); checkit_double(hit2[0].center.x, 2); checkit_double(hit2[0].center.y, 4.3); checkit_double(hit2[0].center.z, 5.4); checkit_double(hit2[0].radius, 3.2); checkit_double(hit2[1].center.x, 2.9); checkit_double(hit2[1].center.y, 3.4); checkit_double(hit2[1].center.z, 2.1); checkit_double(hit2[1].radius, 2.3); }
void test_create_ray(void){ struct ray r = create_ray(create_point(2.3,4.3,2.1),create_vector(2.5,3.5,4.5)); checkit_double(r.p.x, 2.3); checkit_double(r.p.y, 4.3); checkit_double(r.p.z, 2.1); checkit_double(r.dir.x,2.5); checkit_double(r.dir.y,3.5); checkit_double(r.dir.z,4.5); struct ray r2 = create_ray(create_point(3.4,4.5,2.5),create_vector(1.1,4.1,5.1)); checkit_double(r2.p.x, 3.4); checkit_double(r2.p.y, 4.5); checkit_double(r2.p.z, 2.5); checkit_double(r2.dir.x,1.1); checkit_double(r2.dir.y,4.1); checkit_double(r2.dir.z,5.1); }