aboutsummaryrefslogtreecommitdiff
path: root/test/vector.cpp
blob: 61648c6fee69c0db059dd824dde9f0a9f9478e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
}