diff options
author | Julian T <julian@jtle.dk> | 2021-01-24 18:13:44 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-01-24 18:22:11 +0100 |
commit | 41ea2d8f94043d49fc26aaaa8030a73dcfdc2da9 (patch) | |
tree | fcc07052425c65b38c1724f4fc30299a1cb48716 /test | |
parent | a38e6014ea5441e9d29fcb3b5607cd94e4061cff (diff) |
Create rust project
Diffstat (limited to 'test')
-rw-r--r-- | test/main.cpp | 2 | ||||
-rw-r--r-- | test/object.cpp | 36 | ||||
-rw-r--r-- | test/vector.cpp | 31 |
3 files changed, 0 insertions, 69 deletions
diff --git a/test/main.cpp b/test/main.cpp deleted file mode 100644 index 4ed06df..0000000 --- a/test/main.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include <catch2/catch.hpp> diff --git a/test/object.cpp b/test/object.cpp deleted file mode 100644 index bbce055..0000000 --- a/test/object.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include <object.hpp> -#include <ray.hpp> -#include <common.hpp> -#include <vector.hpp> - -#include <catch2/catch.hpp> -#include <math.h> - -TEST_CASE("Sphere normal at", "[sphere]") { - auto sph = Sphere(Vec3d(2, 3, 4), 2); - - auto norm = sph.norm_at(Vec3d(2, 3, 2), Vec3d()); - REQUIRE(norm.m_x == 0); - REQUIRE(norm.m_y == 0); - REQUIRE(norm.m_z == -1); -} - -TEST_CASE("Sphere intersect", "[sphere]") { - auto sph = Sphere(Vec3d(2, 3, 4), 2); - auto ray = Ray(Vec3d(1, 0, 0), Vec3d(0, 1, 1.5), true); - - auto dist = sph.intersect(ray, false); - REQUIRE(abs(dist - 3.28) < 0.01); -} - -TEST_CASE("Plane intersect", "[plane]") { - auto pln = Plane(Vec3d(3, 4, 2), Vec3d(-6, -3, -2)); - auto ray = Ray(Vec3d(0, 0, 0), Vec3d(-2, -1, 5)); - - auto dist = pln.intersect(ray, false); - REQUIRE(dist == -1); - - ray = Ray(Vec3d(-2, -2, 0), Vec3d(-2, -1, 5)); - dist = pln.intersect(ray, false); - REQUIRE(abs(dist - 20.4) < 0.1); -} diff --git a/test/vector.cpp b/test/vector.cpp deleted file mode 100644 index 61648c6..0000000 --- a/test/vector.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#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); -} |