Debian Codegraph @

tests/src/test_mathutils.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include <catch2/catch_all.hpp>
5
6 #include "common/mathutils.h"
7 #include <units.h>
8
9 namespace Tests::Utils::Math {
10
11 TEST_CASE("MathUtils tests", "[Utils][Math]")
12 {
13 SECTION("linearNorm")
14 {
15 std::vector<int> values{1, 50, 100};
16 std::pair<int, int> oldRange(1, 100);
17 std::pair<int, int> newRange(1, 50);
18
19 std::vector<int> normValues{1, 25, 50};
20 ::Utils::Math::linearNorm(values, oldRange, newRange);
21 REQUIRE(values == normValues);
22 }
23
24 SECTION("lerpX")
25 {
26 auto p1 = std::make_pair(0, 0);
27 auto p2 = std::make_pair(10, 10);
28
29 REQUIRE(::Utils::Math::lerpX(5, p1, p2) == 5);
30 }
31
32 SECTION("lerpY")
33 {
34 auto p1 = std::make_pair(0, 0);
35 auto p2 = std::make_pair(10, 10);
36
37 REQUIRE(::Utils::Math::lerpY(5, p1, p2) == 5);
38 }
39 }
40
41 } // namespace Tests::Utils::Math