Skip to content

Commit

Permalink
Add tests to improve code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Apr 22, 2015
1 parent 508e74f commit 67a99fc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
23 changes: 22 additions & 1 deletion test/test_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST(PrimitiveTest, InstanceTest) {
}

// ------------------------------
// Sphere class test
// Plane class test
// ------------------------------
TEST(PlaneTest, InstanceTest) {
Plane pl(3.0, Vector3(-1.0, 0.0, 0.0), Color(0.1, 0.2, 0.3), Color(0.25, 0.50, 0.75), REFLECTION_DIFFUSE);
Expand Down Expand Up @@ -94,6 +94,12 @@ TEST(PlaneTest, InstanceTest) {
// Sphere class test
// ------------------------------
TEST(SphereTest, InstanceTest) {
Sphere sp0;
EXPECT_EQ(0.0, sp0.center().x());
EXPECT_EQ(0.0, sp0.center().y());
EXPECT_EQ(0.0, sp0.center().z());
EXPECT_EQ(0.0, sp0.radius());

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());
Expand All @@ -110,6 +116,21 @@ TEST(SphereTest, InstanceTest) {

EXPECT_EQ(REFLECTION_DIFFUSE, sp.reftype());

// copy constructor
sp0 = sp;
EXPECT_EQ(0.0, sp0.center().x());
EXPECT_EQ(0.0, sp0.center().y());
EXPECT_EQ(0.0, sp0.center().z());

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

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

// intersection
HitPoint 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());
Expand Down
25 changes: 24 additions & 1 deletion test/test_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
#include "../include/spica.h"
using namespace spica;

Random rng = Random::getRNG();

TEST(ImageTest, InstanceTest) {
const int width = 320;
const int height = 240;

Image image;
EXPECT_EQ(0, image.width());
EXPECT_EQ(0, image.height());
ASSERT_DEATH(image(0, 0), "");
ASSERT_DEATH(Image(-1, -1), "");

image = Image(320, 240);
image = Image(width, height);
EXPECT_EQ(320, image.width());
EXPECT_EQ(240, image.height());
for (int y = 0; y < image.height(); y++) {
Expand All @@ -19,4 +24,22 @@ TEST(ImageTest, InstanceTest) {
EXPECT_EQ(0.0, image(x, y).blue());
}
}

Image rand(160, 120);
for (int y = 0; y < rand.height(); y++) {
for (int x = 0; x < rand.width(); x++) {
rand.pixel(x, y) = Color(rng.randReal(), rng.randReal(), rng.randReal());
}
}

image = rand;
EXPECT_EQ(rand.width(), image.width());
EXPECT_EQ(rand.height(), image.height());
for (int y = 0; y < image.height(); y++) {
for (int x = 0; x < image.width(); x++) {
EXPECT_EQ(rand(x, y).red(), image(x, y).red());
EXPECT_EQ(rand(x, y).green(), image(x, y).green());
EXPECT_EQ(rand(x, y).blue(), image(x, y).blue());
}
}
}

0 comments on commit 67a99fc

Please sign in to comment.