world_test.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * World unit tests
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <world.h>
  10. #include <light.h>
  11. #include <sphere.h>
  12. #include <material.h>
  13. #include <transformation.h>
  14. #include <worldbuilder.h>
  15. #include <math.h>
  16. #include <gtest/gtest.h>
  17. TEST(WorldTest, Creating_a_world)
  18. {
  19. World w;
  20. ASSERT_EQ(w.lightCount, 0);
  21. ASSERT_EQ(w.objectCount, 0);
  22. }
  23. TEST(WorldTest, The_default_world)
  24. {
  25. World w = DefaultWorld();
  26. Light l = Light(POINT_LIGHT, Point(-10, 10, -10), Colour(1, 1, 1));
  27. Sphere s1 = Sphere();
  28. Sphere s2 = Sphere();
  29. Material s1Mat = Material();
  30. s1Mat.colour = Colour(0.8, 1.0, 0.6);
  31. s1Mat.diffuse = 0.7;
  32. s1Mat.specular = 0.2;
  33. s1.setMaterial(s1Mat);
  34. s2.setTransform(scaling(0.5, 0.5,0.5));
  35. ASSERT_TRUE(w.lightIsIn(l));
  36. ASSERT_TRUE(w.objectIsIn(s1));
  37. ASSERT_TRUE(w.objectIsIn(s2));
  38. };
  39. TEST(WorldTest, Intersect_a_world_with_a_ray)
  40. {
  41. World w = DefaultWorld();
  42. Ray r = Ray(Point(0, 0, -5), Vector(0, 0, 1));
  43. Intersect xs = w.intersect(r);
  44. ASSERT_EQ(xs.count(), 4);
  45. ASSERT_EQ(xs[0].t, 4);
  46. ASSERT_EQ(xs[1].t, 4.5);
  47. ASSERT_EQ(xs[2].t, 5.5);
  48. ASSERT_EQ(xs[3].t, 6);
  49. }