Skip to content

Commit

Permalink
Test setFaceNormal class method #12
Browse files Browse the repository at this point in the history
  • Loading branch information
smercer10 committed Feb 25, 2024
1 parent 711c9e1 commit 88160df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FetchContent_Declare(

FetchContent_MakeAvailable(googletest)

add_executable(raydiance_test vec3_test.cpp colour_test.cpp ray_test.cpp globals_test.cpp)
add_executable(raydiance_test vec3_test.cpp colour_test.cpp ray_test.cpp globals_test.cpp object_test.cpp)

target_link_libraries(raydiance_test raydiance_lib GTest::gtest_main)

Expand Down
24 changes: 24 additions & 0 deletions tests/object_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "raydiance/object.h"
#include <gtest/gtest.h>

TEST(IntersectionTest, SetFaceNormal) {
ray r1(point3{0, 0, 0}, vec3{0, 0, 1});
vec3 on1{0, 0, -1};
intersection i1;
i1.setFaceNormal(r1, on1);

EXPECT_TRUE(i1.frontFace);
EXPECT_DOUBLE_EQ(i1.normal.x(), 0);
EXPECT_DOUBLE_EQ(i1.normal.y(), 0);
EXPECT_DOUBLE_EQ(i1.normal.z(), -1);

ray r2(point3{0, 0, 0}, vec3{0, 0, -1});
vec3 on2{0, 0, -1};
intersection i2;
i2.setFaceNormal(r2, on2);

EXPECT_FALSE(i2.frontFace);
EXPECT_DOUBLE_EQ(i2.normal.x(), 0);
EXPECT_DOUBLE_EQ(i2.normal.y(), 0);
EXPECT_DOUBLE_EQ(i2.normal.z(), 1);
}

0 comments on commit 88160df

Please sign in to comment.