123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "tests/BoxTests.h"
- #include "math/Box.h"
- #include "tests/Test.h"
- #include "utils/StringBuffer.h"
- typedef StringBuffer<250> String;
- static void testInit(Test& test) {
- Box box(Vector3(1.0f, 2.0f, 3.0f));
- test.checkEqual(String("Box([0.00, 0.00, 0.00], [1.00, 2.00, 3.00])"),
- String(box), "init 1");
- test.checkEqual(String("[0.00, 0.00, 0.00]"), String(box.getMin()),
- "get min 1");
- test.checkEqual(String("[1.00, 2.00, 3.00]"), String(box.getMax()),
- "get max 1");
- box = Box(Vector3(-1.0f, -2.0f, -3.0f));
- test.checkEqual(String("Box([-1.00, -2.00, -3.00], [0.00, 0.00, 0.00])"),
- String(box), "init 2");
- test.checkEqual(String("[-1.00, -2.00, -3.00]"), String(box.getMin()),
- "get min 2");
- test.checkEqual(String("[0.00, 0.00, 0.00]"), String(box.getMax()),
- "get max 2");
- }
- static void testOffset(Test& test) {
- Box box(Vector3(1.0f, 2.0f, 3.0f));
- test.checkEqual(String("Box([7.00, -4.00, 6.00], [8.00, -2.00, 9.00])"),
- String(box.offset(Vector3(7.0f, -4.0f, 6.0f))), "expand");
- }
- static void testCollidesWith(Test& test) {
- Box boxA(Vector3(1.0f, 2.0f, 3.0f));
- Box boxB(Vector3(-1.0f, -2.0f, -3.0f));
- Box boxC(Vector3(2.0f, 2.0f, 2.0f));
- boxC = boxC.offset(Vector3(-1.0f, -1.0f, -1.0f));
- test.checkTrue(boxC.collidesWith(boxA), "collides with 1");
- test.checkTrue(boxC.collidesWith(boxB), "collides with 2");
- test.checkTrue(boxA.collidesWith(boxC), "collides with 3");
- test.checkTrue(boxB.collidesWith(boxC), "collides with 4");
- test.checkFalse(boxA.collidesWith(boxB), "collides with 5");
- test.checkFalse(boxB.collidesWith(boxA), "collides with 6");
- }
- static void testExpand(Test& test) {
- Box box(Vector3(1.0f, 2.0f, 3.0f));
- test.checkEqual(String("Box([0.00, -4.00, 0.00], [8.00, 2.00, 9.00])"),
- String(box.expand(Vector3(7.0f, -4.0f, 6.0f))), "expand");
- test.checkEqual(String("Box([-7.00, 0.00, -6.00], [1.00, 6.00, 3.00])"),
- String(box.expand(Vector3(-7.0f, 4.0f, -6.0f))), "expand");
- }
- static void testGrow(Test& test) {
- Box box(Vector3(1.0f, 2.0f, 3.0f));
- test.checkEqual(String("Box([-2.00, -1.00, -3.00], [3.00, 3.00, 6.00])"),
- String(box.grow(Vector3(4.0f, 2.0f, 6.0f))), "expand");
- test.checkEqual(String("Box([0.50, 1.00, 1.50], [0.50, 1.00, 1.50])"),
- String(box.grow(Vector3(-4.0f, -2.0f, -6.0f))), "expand");
- test.checkEqual(String("Box([0.05, 1.00, 0.50], [0.95, 1.00, 2.50])"),
- String(box.grow(Vector3(-0.1f, -4.0f, -1.0f))), "expand");
- }
- void BoxTests::test() {
- Test test("Box");
- testInit(test);
- testOffset(test);
- testCollidesWith(test);
- testExpand(test);
- testGrow(test);
- test.finalize();
- }
|