Skip to content

Commit

Permalink
Add test code for Sphere intersection.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Apr 14, 2015
1 parent b40d632 commit bc38999
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/test_Sphere.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@
using namespace rainy;

TEST(SphereTest, InstanceTest) {
Sphere sp(1.0, Vector3(0.0, 0.0, 0.0), Color(), Color(0.75, 0.75, 0.75), REFLECTION_DIFFUSE);
Sphere sp(2.0, Vector3(0.0, 0.0, 0.0), Color(), Color(0.75, 0.75, 0.75), REFLECTION_DIFFUSE);

EXPECT_EQ(0.0, sp.center().x());
EXPECT_EQ(0.0, sp.center().y());
EXPECT_EQ(0.0, sp.center().z());

EXPECT_EQ(0.0, sp.emission().x());
EXPECT_EQ(0.0, sp.emission().y());
EXPECT_EQ(0.0, sp.emission().z());

EXPECT_EQ(0.75, sp.color().x());
EXPECT_EQ(0.75, sp.color().y());
EXPECT_EQ(0.75, sp.color().z());

EXPECT_EQ(REFLECTION_DIFFUSE, sp.reftype());

HitPoint hitpoint;
sp.intersect(Ray(Vector3(10.0, 0.0, 0.0), Vector3(-1.0, 0.0, 0.0)), hitpoint);
EXPECT_TRUE(sp.intersect(Ray(Vector3(10.0, 0.0, 0.0), Vector3(-1.0, 0.0, 0.0)), hitpoint));
EXPECT_EQ(2.0, hitpoint.position().x());
EXPECT_EQ(0.0, hitpoint.position().y());
EXPECT_EQ(0.0, hitpoint.position().z());

EXPECT_EQ(1.0, hitpoint.normal().x());
EXPECT_EQ(0.0, hitpoint.normal().y());
EXPECT_EQ(0.0, hitpoint.normal().z());

EXPECT_FALSE(sp.intersect(Ray(Vector3(10.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0)), hitpoint));
}

int main(int argc, char **argv) {
Expand Down

0 comments on commit bc38999

Please sign in to comment.