[WIP] tests transform it into BDD Style
This commit is contained in:
@@ -35,31 +35,59 @@ using namespace Raytracer;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Creating and querying a ray", "[Rays]")
|
||||
SCENARIO("Creating and querying a ray", "[features/rays.feature]")
|
||||
{
|
||||
Tuple origin = Tuple::Point(1, 2, 3);
|
||||
Tuple direction = Tuple::Vector(4, 5, 6);
|
||||
Ray r(origin, direction);
|
||||
|
||||
REQUIRE(r.origin() == origin);
|
||||
REQUIRE(r.direction() == direction);
|
||||
GIVEN("origin <- point(1, 2, 3)")
|
||||
{
|
||||
Tuple origin = Tuple::Point(1, 2, 3);
|
||||
AND_GIVEN("direction <- vector(4, 5, 6)")
|
||||
{
|
||||
Tuple direction = Tuple::Vector(4, 5, 6);
|
||||
WHEN("r <- ray(origin, direction)")
|
||||
{
|
||||
Ray r(origin, direction);
|
||||
THEN("r.origin = origin")
|
||||
{
|
||||
REQUIRE(r.origin() == origin);
|
||||
}
|
||||
AND_THEN("r.direction = direction")
|
||||
{
|
||||
REQUIRE(r.direction() == direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Computing a point from a distance", "[Rays]")
|
||||
SCENARIO("Computing a point from a distance", "[features/rays.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(2, 3, 4), Tuple::Vector(1, 0, 0));
|
||||
|
||||
REQUIRE(r.position(0) == Tuple::Point(2, 3, 4));
|
||||
REQUIRE(r.position(1) == Tuple::Point(3, 3, 4));
|
||||
REQUIRE(r.position(-1) == Tuple::Point(1, 3, 4));
|
||||
REQUIRE(r.position(2.5) == Tuple::Point(4.5, 3, 4));
|
||||
GIVEN("r <- ray(point(2, 3, 4), vector(1, 0, 0))")
|
||||
{
|
||||
Ray r(Tuple::Point(2, 3, 4), Tuple::Vector(1, 0, 0));
|
||||
THEN("position(r,0) = point(2, 3, 4)")
|
||||
{
|
||||
REQUIRE(r.position(0) == Tuple::Point(2, 3, 4));
|
||||
}
|
||||
AND_THEN("position(r,1) == point(3, 3, 4)")
|
||||
{
|
||||
REQUIRE(r.position(1) == Tuple::Point(3, 3, 4));
|
||||
}
|
||||
AND_THEN("position(r,-1) = point(1, 3, 4)")
|
||||
{
|
||||
REQUIRE(r.position(-1) == Tuple::Point(1, 3, 4));
|
||||
}
|
||||
AND_THEN("position(r,2.5) == point(4.5, 3, 4)")
|
||||
{
|
||||
REQUIRE(r.position(2.5) == Tuple::Point(4.5, 3, 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] a ray intersects a sphere at two points", "[Sphere]")
|
||||
SCENARIO("A ray intersects a sphere at two points", "[features/spheres.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
@@ -72,7 +100,7 @@ TEST_CASE("[05][Rays] a ray intersects a sphere at two points", "[Sphere]")
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] a ray intersects a sphere at a tangent", "[Sphere]")
|
||||
SCENARIO("A ray intersects a sphere at a tangent", "[features/spheres.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 1, -5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
@@ -85,7 +113,7 @@ TEST_CASE("[05][Rays] a ray intersects a sphere at a tangent", "[Sphere]")
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] a ray misses a sphere", "[Sphere]")
|
||||
SCENARIO("A ray misses a sphere", "[features/spheres.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 2, -5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
@@ -96,7 +124,7 @@ TEST_CASE("[05][Rays] a ray misses a sphere", "[Sphere]")
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] a originates inside a sphere", "[Sphere]")
|
||||
SCENARIO("A originates inside a sphere", "[features/spheres.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, 0), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
@@ -109,7 +137,7 @@ TEST_CASE("[05][Rays] a originates inside a sphere", "[Sphere]")
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] a sphere is behind a ray", "[Sphere]")
|
||||
SCENARIO("A sphere is behind a ray", "[features/spheres.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, 5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
@@ -122,7 +150,7 @@ TEST_CASE("[05][Rays] a sphere is behind a ray", "[Sphere]")
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Test Sphere Object", "[Sphere]")
|
||||
SCENARIO("Test Sphere Object", "[features/spheres.feature]")
|
||||
{
|
||||
Sphere s1;
|
||||
Sphere s2 = s1;
|
||||
@@ -134,7 +162,7 @@ TEST_CASE("[05][Rays] Test Sphere Object", "[Sphere]")
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] An intersection encapsulates t and object", "[Intersections]")
|
||||
SCENARIO("An intersection encapsulates t and object", "[features/intersections.feature]")
|
||||
{
|
||||
Sphere s;
|
||||
Intersection i(3.5, s);
|
||||
@@ -145,7 +173,7 @@ TEST_CASE("[05][Rays] An intersection encapsulates t and object", "[Intersection
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Aggregating intersections", "[Intersections]")
|
||||
SCENARIO("Aggregating intersections", "[features/intersections.feature]")
|
||||
{
|
||||
Sphere s;
|
||||
Intersection i1(1, s);
|
||||
@@ -159,7 +187,7 @@ TEST_CASE("[05][Rays] Aggregating intersections", "[Intersections]")
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Intersect set the object on the intersection", "[Intersections]")
|
||||
SCENARIO("Intersect sets the object on the intersection", "[features/spheres.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, 5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
@@ -172,7 +200,7 @@ TEST_CASE("[05][Rays] Intersect set the object on the intersection", "[Intersect
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] The hit, when all intersections have positive t", "[Intersections]")
|
||||
SCENARIO("The hit, when all intersections have positive t", "[features/intersections.feature]")
|
||||
{
|
||||
Sphere s;
|
||||
Intersection i1(1, s);
|
||||
@@ -186,7 +214,7 @@ TEST_CASE("[05][Rays] The hit, when all intersections have positive t", "[Inters
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] The hit, when some intersections have negative t", "[Intersections]")
|
||||
SCENARIO("The hit, when some intersections have negative t", "[features/intersections.feature]")
|
||||
{
|
||||
Sphere s;
|
||||
Intersection i1(-1, s);
|
||||
@@ -200,7 +228,7 @@ TEST_CASE("[05][Rays] The hit, when some intersections have negative t", "[Inter
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] The hit, when all intersections have negative t", "[Intersections]")
|
||||
SCENARIO("The hit, when all intersections have negative t", "[features/intersections.feature]")
|
||||
{
|
||||
Sphere s;
|
||||
Intersection i1(-2, s);
|
||||
@@ -214,7 +242,7 @@ TEST_CASE("[05][Rays] The hit, when all intersections have negative t", "[Inters
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] The hit is always the lowest nonnegative intersection", "[Intersections]")
|
||||
SCENARIO("The hit is always the lowest nonnegative intersection", "[features/intersections.feature]")
|
||||
{
|
||||
Sphere s;
|
||||
Intersection i1(5, s);
|
||||
@@ -230,7 +258,7 @@ TEST_CASE("[05][Rays] The hit is always the lowest nonnegative intersection", "[
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Translating a ray", "[Rays]")
|
||||
SCENARIO("Translating a ray", "[features/rays.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(1, 2, 3), Tuple::Vector(0, 1, 0));
|
||||
Matrix m = Matrix::translation(3, 4, 5);
|
||||
@@ -242,7 +270,7 @@ TEST_CASE("[05][Rays] Translating a ray", "[Rays]")
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Scaling a ray", "[Rays]")
|
||||
SCENARIO("Scaling a ray", "[features/rays.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(1, 2, 3), Tuple::Vector(0, 1, 0));
|
||||
Matrix m = Matrix::scaling(2, 3, 4);
|
||||
@@ -254,15 +282,21 @@ TEST_CASE("[05][Rays] Scaling a ray", "[Rays]")
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] A sphere's default transformation", "[Sphere]")
|
||||
SCENARIO("A sphere's default transformation", "[features/spheres.feature]")
|
||||
{
|
||||
Sphere s;
|
||||
REQUIRE(s.transform() == Matrix::identity());
|
||||
GIVEN("s <- Sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
THEN("s.transform = identity_matrix")
|
||||
{
|
||||
REQUIRE(s.transform() == Matrix::identity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Changing a sphere's transformation", "[Sphere]")
|
||||
SCENARIO("Changing a sphere's transformation", "[features/spheres.feature]")
|
||||
{
|
||||
Sphere s;
|
||||
Matrix t = Matrix::translation(2, 3, 4);
|
||||
@@ -271,8 +305,8 @@ TEST_CASE("[05][Rays] Changing a sphere's transformation", "[Sphere]")
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
#if 0
|
||||
TEST_CASE("[05][Rays] Intersecting a scaled sphere with a ray", "[Sphere]")
|
||||
|
||||
SCENARIO("Intersecting a scaled sphere with a ray", "[features/spheres.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
@@ -283,10 +317,10 @@ TEST_CASE("[05][Rays] Intersecting a scaled sphere with a ray", "[Sphere]")
|
||||
REQUIRE(xs[0].distance_t() == 3);
|
||||
REQUIRE(xs[1].distance_t() == 7);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Intersecting a translated sphere with a ray", "[Sphere]")
|
||||
SCENARIO("Intersecting a translated sphere with a ray", "[features/spheres.feature]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
|
||||
Reference in New Issue
Block a user