1 #include "objects/geometry/Indices.h" 2 #include "catch.hpp" 3 #include "utils/Utils.h" 4 5 using namespace Sph; 6 7 8 TEST_CASE("Indices construction", "[indices]") { 9 Indices i1(1, 2, 3, 4); 10 REQUIRE(i1[0] == 1); 11 REQUIRE(i1[1] == 2); 12 REQUIRE(i1[2] == 3); 13 REQUIRE(i1[3] == 4); 14 15 Indices i2(5); 16 REQUIRE(i2[0] == 5); 17 REQUIRE(i2[1] == 5); 18 REQUIRE(i2[2] == 5); 19 REQUIRE(i2[3] == 5); 20 21 Indices i3(i1); 22 REQUIRE(i3[0] == 1); 23 REQUIRE(i3[1] == 2); 24 REQUIRE(i3[2] == 3); 25 REQUIRE(i3[3] == 4); 26 } 27 28 TEST_CASE("Indices comparison", "[indices]") { 29 Indices i1(1, 2, 3, 5); 30 Indices i2(1, 2, 3, 7); 31 Indices i3(1, -1, 3, 5); 32 Indices i12 = i1 == i2; 33 Indices i13 = i1 == i3; 34 35 REQUIRE(i12[0]); 36 REQUIRE(i12[1]); 37 REQUIRE(i12[2]); 38 REQUIRE_FALSE(i12[3]); 39 40 REQUIRE(i13[0]); 41 REQUIRE_FALSE(i13[1]); 42 REQUIRE(i13[2]); 43 REQUIRE(i13[3]); 44 45 Indices ni12 = i1 != i2; 46 Indices ni13 = i1 != i3; 47 48 REQUIRE_FALSE(ni12[0]); 49 REQUIRE_FALSE(ni12[1]); 50 REQUIRE_FALSE(ni12[2]); 51 REQUIRE(ni12[3]); 52 53 REQUIRE_FALSE(ni13[0]); 54 REQUIRE(ni13[1]); 55 REQUIRE_FALSE(ni13[2]); 56 REQUIRE_FALSE(ni13[3]); 57 } 58 59 TEST_CASE("Indices conversion", "[indices]") { 60 Vector v(1.5_f, 2.4_f, 5._f); 61 Indices i(v); 62 63 REQUIRE(i[0] == 1); 64 REQUIRE(i[1] == 2); 65 REQUIRE(i[2] == 5); 66 67 Vector v2 = i; 68 REQUIRE(v2 == Vector(1._f, 2._f, 5._f)); 69 } 70 71 TEST_CASE("Indices random access", "[indices]") { 72 Indices i(4, 5, 6); 73 i[2]++; 74 REQUIRE(all(i == Indices(4, 5, 7))); 75 REQUIRE(i[0] == 4); 76 REQUIRE(i[1] == 5); 77 REQUIRE(i[2] == 7); 78 REQUIRE(i[3] == 0); 79 80 i[1]--; 81 REQUIRE(all(i == Indices(4, 4, 7))); 82 REQUIRE(i[0] == 4); 83 REQUIRE(i[1] == 4); 84 REQUIRE(i[2] == 7); 85 REQUIRE(i[3] == 0); 86 87 REQUIRE_SPH_ASSERT(i[4]); 88 } 89 90 TEST_CASE("Indices arithmetics", "[indices]") { 91 Indices i1(2, 4, 3); 92 Indices i2(5, -1, 2); 93 REQUIRE(all(i1 + i2 == Indices(7, 3, 5))); 94 REQUIRE(all(i1 - i2 == Indices(-3, 5, 1))); 95 REQUIRE(all(i1.max(i2) == Indices(5, 4, 3))); 96 REQUIRE(all(i1.min(i2) == Indices(2, -1, 2))); 97 } 98