Test example

SCENARIO("Computing the dot product of a vector", "[raytracer][vector]") { GIVEN("Two vectors") { raytracer::vector v1{ -235.4, 4.0, 332.0 }; raytracer::vector v2{ -51.0, 4.0, 3.0 }; WHEN("Their dot product is computed") { auto result{ v1 * v2 }; THEN("The result is the sum of the products of their respective components") { REQUIRE(result == Approx(v1.x * v2.x + v1.y * v2.y + v1.z * v2.z)); } } } GIVEN("Two identical unit vectors") { raytracer::vector v1{ raytracer::vector::unitX() }; raytracer::vector v2{ v1 }; WHEN("Their dot product is computed") { auto result{ v1 * v2 }; THEN("The result is 1") { REQUIRE(result == Approx(1.0)); } } } GIVEN("Two opposite unit vectors") { raytracer::vector v1{ raytracer::vector::unitZ() }; raytracer::vector v2{ -v1 }; WHEN("Their dot product is computed") { auto result{ v1 * v2 }; THEN("The result is -1") { REQUIRE(result == Approx(-1.0)); } } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.