aboutsummaryrefslogtreecommitdiff
path: root/test/vector.cpp
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-07-26 12:56:27 +0200
committerJulian T <julian@jtle.dk>2020-07-26 12:56:27 +0200
commit893176a0b18a2281abe09def716ccc3db5583c3f (patch)
treea34da79b7dc0fcdbdd39e2a3f4000cc6a1c0a896 /test/vector.cpp
parent18960c4b88ce912e08b12182b835a7de75388b78 (diff)
Implemented object intersection and startet work on render gui
Diffstat (limited to 'test/vector.cpp')
-rw-r--r--test/vector.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/vector.cpp b/test/vector.cpp
new file mode 100644
index 0000000..61648c6
--- /dev/null
+++ b/test/vector.cpp
@@ -0,0 +1,31 @@
+#include <vector.hpp>
+#include <common.hpp>
+#include <catch2/catch.hpp>
+
+TEST_CASE( "Vector length", "[vector]" ) {
+ auto vec = Vec3d(2, 4, 4);
+ REQUIRE(vec.length() == 6);
+ vec.set(0, 0, 0);
+ REQUIRE(vec.length() == 0);
+ vec.set(0, 3.5, 0);
+ REQUIRE(vec.length() == 3.5);
+}
+
+TEST_CASE("Vector_normal", "[vector]") {
+ auto vec = Vec3d(4, 5, 4545);
+ REQUIRE(vec.length() != 1.0);
+ vec.normalize();
+ REQUIRE(vec.length() - 1.0 < ZERO_APPROX);
+ vec.set(0, 0, 0);
+ REQUIRE_THROWS(vec.normalize());
+}
+
+TEST_CASE("Vector dot", "[vector]") {
+ auto a = Vec3d(4, 5, 6);
+ auto b = Vec3d(1, 2, 3);
+ REQUIRE(a.dot(b) == 32);
+ a.set(0, 0, 0);
+ REQUIRE(a.dot(b) == 0);
+ a.set(0, 5, 0);
+ REQUIRE(a.dot(b) == 10);
+}