From 8460f2205e9cd574c665fec545303a3ffc002b38 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 16 Aug 2014 08:54:33 -0700 Subject: [PATCH] Remake test_object -> testObject.cc This was a *really* old class... --- test/testObject.cc | 6 +++ test/test_object.c | 94 ---------------------------------------------- 2 files changed, 6 insertions(+), 94 deletions(-) create mode 100644 test/testObject.cc delete mode 100644 test/test_object.c diff --git a/test/testObject.cc b/test/testObject.cc new file mode 100644 index 0000000..87d7da8 --- /dev/null +++ b/test/testObject.cc @@ -0,0 +1,6 @@ +/* test_object.cc + * vim: set tw=80: + * Eryn Wells + */ + + diff --git a/test/test_object.c b/test/test_object.c deleted file mode 100644 index 7aa655a..0000000 --- a/test/test_object.c +++ /dev/null @@ -1,94 +0,0 @@ -/* test_object.c - * - * Unit tests for the object module. - * - * Eryn Wells - */ - -#include - -#include - -#include "object.h" -#include "test_asserts.h" -#include "test_suites.h" - - -void check_sphere_intersection(Object *sphere, Ray ray, Vector3 *tvectors, int ntvectors); - - -START_TEST(test_sphere_does_intersect) -{ - // Create a sphere at the origin of radius 1. - Object *sphere = object_init(ObjectTypeSphere); - object_sphere_set_radius(sphere, 1.0); - - Vector3 loc, dir; - Vector3 tvectors[2]; - Ray ray; - - loc = vector_init(0, 0, -5); - dir = vector_init(0, 0, 1); - ray = ray_init(loc, dir); - tvectors[0] = vector_init(0, 0, -1); - tvectors[1] = vector_init(0, 0, 1); - check_sphere_intersection(sphere, ray, tvectors, 2); - - loc = vector_init(0, -5, 0); - dir = vector_init(0, 1, 0); - ray = ray_init(loc, dir); - tvectors[0] = vector_init(0, -1, 0); - tvectors[1] = vector_init(0, 1, 0); - check_sphere_intersection(sphere, ray, tvectors, 2); -} -END_TEST - - -void -check_sphere_intersection(Object *sphere, Ray ray, Vector3 *tvectors, int ntvectors) -{ - float *t; - int nints = object_does_intersect(sphere, ray, &t); - ck_assert(nints == ntvectors); - - Vector3 rp; - for (int i = 0; i < nints; i++) { - rp = ray_parameterize(ray, t[i]); - test_assert_within_epsilon(rp.x, tvectors[i].x, 1e-4); - test_assert_within_epsilon(rp.y, tvectors[i].y, 1e-4); - test_assert_within_epsilon(rp.z, tvectors[i].z, 1e-4); - } - - if (nints > 0) { - free(t); - } -} - - -START_TEST(test_sphere_point_lies_on_surface) -{ - ck_assert(0); -} -END_TEST - - -START_TEST(test_sphere_compute_normal) -{ - ck_assert(0); -} -END_TEST - - -Suite * -test_object_create_suite() -{ - Suite *s = suite_create("object"); - - TCase *tc_sphere = tcase_create("sphere"); - tcase_add_test(tc_sphere, test_sphere_does_intersect); - tcase_add_test(tc_sphere, test_sphere_point_lies_on_surface); - tcase_add_test(tc_sphere, test_sphere_compute_normal); - suite_add_tcase(s, tc_sphere); - - return s; -}