-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For degenerate bounds, they would end up going on forever (or at least a very long time, visiting all sorts of points that weren't inside the bounds). Added unit tests to test both their regular operation as well as degenerate cases.
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
#include "tests/gtest/gtest.h" | ||
#include "pbrt.h" | ||
#include "geometry.h" | ||
|
||
TEST(Bounds2, IteratorBasic) { | ||
Bounds2i b{{0, 1}, {2, 3}}; | ||
Point2i e[] = { { 0, 1 }, { 1, 1 }, { 0, 2 }, { 1, 2 } }; | ||
int offset = 0; | ||
for (auto p : b) { | ||
EXPECT_LT(offset, sizeof(e) / sizeof(e[0])); | ||
EXPECT_EQ(e[offset], p) << "offset = " << offset; | ||
++offset; | ||
} | ||
} | ||
|
||
TEST(Bounds2, IteratorDegenerate) { | ||
Bounds2i b{{0, 0}, {0, 10}}; | ||
for (auto p : b) { | ||
// This loop should never run. | ||
bool reached = true; | ||
EXPECT_FALSE(reached) << "p = " << p; | ||
break; | ||
} | ||
|
||
Bounds2i b2{{0, 0}, {4, 0}}; | ||
for (auto p : b2) { | ||
// This loop should never run. | ||
bool reached = true; | ||
EXPECT_FALSE(reached) << "p = " << p; | ||
break; | ||
} | ||
|
||
Bounds2i b3; | ||
for (auto p : b3) { | ||
// This loop should never run. | ||
bool reached = true; | ||
EXPECT_FALSE(reached) << "p = " << p; | ||
break; | ||
} | ||
} | ||
|