boundingbox_test.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Boundingbox unit tests
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. /*
  10. * DoRayMe - a quick and dirty Raytracer
  11. * Camera unit tests
  12. *
  13. * Created by Manoël Trapier
  14. * Copyright (c) 2020 986-Studio.
  15. *
  16. */
  17. #include <math.h>
  18. #include <math_helper.h>
  19. #include <ray.h>
  20. #include <transformation.h>
  21. #include <stdint.h>
  22. #include <boundingbox.h>
  23. #include <gtest/gtest.h>
  24. TEST(BoundingBoxTest, Creating_an_empty_bounding_box)
  25. {
  26. BoundingBox bb;
  27. ASSERT_TRUE(bb.isEmpty());
  28. ASSERT_EQ(bb.min, Point(INFINITY, INFINITY, INFINITY));
  29. ASSERT_EQ(bb.max, Point(-INFINITY, -INFINITY, -INFINITY));
  30. }
  31. TEST(BoundingBoxTest, Crteating_a_bounding_box_with_volume)
  32. {
  33. BoundingBox bb = BoundingBox(Point(-1, -2, -3), Point(3, 2, 1));
  34. ASSERT_FALSE(bb.isEmpty());
  35. ASSERT_EQ(bb.min, Point(-1, -2, -3));
  36. ASSERT_EQ(bb.max, Point(3, 2, 1));
  37. }
  38. TEST(BoundingBoxTest, Adding_on_bouding_to_an_empty_bounding_box)
  39. {
  40. BoundingBox bb;
  41. bb | BoundingBox(Point(-1, -1, -1), Point(1, 1, 1));
  42. ASSERT_FALSE(bb.isEmpty());
  43. ASSERT_EQ(bb.min, Point(-1, -1, -1));
  44. ASSERT_EQ(bb.max, Point(1, 1, 1));
  45. }
  46. TEST(BoundingBoxTest, Adding_boudingbox_to_another)
  47. {
  48. BoundingBox bb(Point(-1, -1, 0), Point(4, 0, 1));
  49. bb | BoundingBox(Point(-2, 0, -5), Point(4, 5, 0.5));
  50. ASSERT_FALSE(bb.isEmpty());
  51. ASSERT_EQ(bb.min, Point(-2, -1, -5));
  52. ASSERT_EQ(bb.max, Point(4, 5, 1));
  53. }
  54. TEST(BoundingBoxTest, Adding_points_to_an_empty_bounding_box)
  55. {
  56. BoundingBox bb;
  57. bb | Point(-5, 2, 0);
  58. bb | Point(7, 0, -3);
  59. ASSERT_FALSE(bb.isEmpty());
  60. ASSERT_EQ(bb.min, Point(-5, 0, -3));
  61. ASSERT_EQ(bb.max, Point(7, 2, 0));
  62. }
  63. TEST(BoundingBoxTest, A_smaller_bb_should_fit_in_a_bigger)
  64. {
  65. BoundingBox bigBb = BoundingBox(Point(-10, -10, -10), Point(10, 10, 10));
  66. BoundingBox smallBb = BoundingBox(Point(-2, -2, -2), Point(2, 2, 2));
  67. ASSERT_TRUE(bigBb.fitsIn(smallBb));
  68. }
  69. TEST(BoundingBoxTest, A_big_bb_should_not_fit_in_a_smaller)
  70. {
  71. BoundingBox bigBb = BoundingBox(Point(-10, -10, -10), Point(10, 10, 10));
  72. BoundingBox smallBb = BoundingBox(Point(-2, -2, -2), Point(2, 2, 2));
  73. ASSERT_FALSE(smallBb.fitsIn(bigBb));
  74. }