intersect_test.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Intersect unit tests
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <intersect.h>
  10. #include <sphere.h>
  11. #include <gtest/gtest.h>
  12. TEST(IntersectTest, Creating_an_intersect_and_do_some_check)
  13. {
  14. Intersect i;
  15. ASSERT_EQ(i.count(), 0);
  16. i.add(newIntersection(1.0, nullptr));
  17. i.add(newIntersection(4.2, nullptr));
  18. ASSERT_EQ(i.count(), 2);
  19. ASSERT_EQ(i[0]->t, 1.0);
  20. ASSERT_EQ(i[1]->t, 4.2);
  21. }
  22. TEST(IntersectTest, An_intersection_encapsulate_t_and_object)
  23. {
  24. Sphere s = Sphere();
  25. Intersection *i = newIntersection(3.5, &s);
  26. ASSERT_EQ(i->t, 3.5);
  27. ASSERT_EQ(i->object, (Object *)&s);
  28. }
  29. TEST(IntersectTest, Aggregating_intersections)
  30. {
  31. Sphere s = Sphere();
  32. Intersection *i1 = newIntersection(1, &s);
  33. Intersection *i2 = newIntersection(2, &s);
  34. Intersect xs = Intersect();
  35. xs.add(i1);
  36. xs.add(i2);
  37. ASSERT_EQ(xs.count(), 2);
  38. ASSERT_EQ(xs[0]->t, 1);
  39. ASSERT_EQ(xs[1]->t, 2);
  40. }