Loading [MathJax]/jax/input/TeX/config.js
Radium Engine  1.5.28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vectorarray.cpp
1#include <Core/Containers/VectorArray.hpp>
2#include <Core/Types.hpp>
3
4#include <catch2/catch_test_macros.hpp>
5#include <string>
6#include <type_traits>
7
8using namespace Ra::Core;
9
10TEST_CASE( "Core/Container/VectorArray", "[unittests][Core][Container][VectorArray]" ) {
11 enum class MyEnum : int { A, B, C };
12 // type check
19 REQUIRE( VectorArrayTypeHelper<std::function<int( float, float )>>::NumberOfComponents == 0 );
20
21 REQUIRE( std::is_same<VectorArray<float>::component_type, float>::value );
22 REQUIRE( std::is_same<VectorArray<Scalar>::component_type, Scalar>::value );
23 REQUIRE( std::is_same<VectorArray<Vector3>::component_type, Scalar>::value );
24 REQUIRE( std::is_same<VectorArray<MyEnum>::component_type, MyEnum>::value );
26 REQUIRE( std::is_same<VectorArray<VectorN>::component_type, Scalar>::value );
27 REQUIRE( std::is_same<VectorArray<int*>::component_type, int*>::value );
28 REQUIRE( std::is_same<VectorArray<std::function<int( float, float )>>::component_type,
29 std::function<int( float, float )>>::value );
30
31 VectorArray<float> floatArray;
32 VectorArray<Scalar> scalarArray;
33 VectorArray<Vector3> vec3Array;
34 VectorArray<MyEnum> enumArray;
35 VectorArray<std::string> stringArray;
36 VectorArray<VectorN> vecDynArray;
37 VectorArray<int*> intPtrArray;
38 VectorArray<std::function<int( float, float )>> funArray;
39
40 REQUIRE( floatArray.getSize() == 0 );
41 REQUIRE( scalarArray.getSize() == 0 );
42 REQUIRE( vec3Array.getSize() == 0 );
43 REQUIRE( enumArray.getSize() == 0 );
44 REQUIRE( stringArray.getSize() == 0 );
45 REQUIRE( vecDynArray.getSize() == 0 );
46 REQUIRE( intPtrArray.getSize() == 0 );
47 REQUIRE( funArray.getSize() == 0 );
48
49 REQUIRE( floatArray.getBufferSize() == 0 );
50 REQUIRE( scalarArray.getBufferSize() == 0 );
51 REQUIRE( vec3Array.getBufferSize() == 0 );
52 REQUIRE( enumArray.getBufferSize() == 0 );
53 REQUIRE( stringArray.getBufferSize() == 0 );
54 REQUIRE( vecDynArray.getBufferSize() == 0 );
55 REQUIRE( intPtrArray.getBufferSize() == 0 );
56 REQUIRE( funArray.getBufferSize() == 0 );
57
58 floatArray.push_back( 1.f );
59 scalarArray.push_back( 1_ra );
60 vec3Array.emplace_back( 1_ra, 2_ra, 3_ra );
61 enumArray.push_back( MyEnum::B );
62 stringArray.push_back( "foo" );
63 vecDynArray.emplace_back( VectorN {} );
64 intPtrArray.push_back( nullptr );
65 funArray.push_back( []( float a, float b ) -> int { return a + b; } );
66
67 REQUIRE( floatArray.getSize() == 1 );
68 REQUIRE( scalarArray.getSize() == 1 );
69 REQUIRE( vec3Array.getSize() == 1 );
70 REQUIRE( enumArray.getSize() == 1 );
71 REQUIRE( stringArray.getSize() == 1 );
72 REQUIRE( vecDynArray.getSize() == 1 );
73 REQUIRE( intPtrArray.getSize() == 1 );
74 REQUIRE( funArray.getSize() == 1 );
75
76 auto floatMap = floatArray.getMap();
77 auto scalarMap = scalarArray.getMap();
78 auto vec3Map = vec3Array.getMap();
79 auto enumMap = enumArray.getMap();
80 REQUIRE( floatMap( 0 ) == 1.f );
81 REQUIRE( scalarMap( 0 ) == 1_ra );
82 REQUIRE( vec3Map.col( 0 ) == Vector3 { 1_ra, 2_ra, 3_ra } );
83 REQUIRE( enumMap( 0 ) == MyEnum::B );
84
85 const auto& floatConstArray = floatArray;
86 const auto& scalarConstArray = scalarArray;
87 const auto& vec3ConstArray = vec3Array;
88 const auto& enumConstArray = enumArray;
89
90 const auto floatConstMap = floatConstArray.getMap();
91 const auto scalarConstMap = scalarConstArray.getMap();
92 const auto vec3ConstMap = vec3ConstArray.getMap();
93 const auto enumConstMap = enumConstArray.getMap();
94 REQUIRE( floatConstMap( 0 ) == 1.f );
95 REQUIRE( scalarConstMap( 0 ) == 1_ra );
96 REQUIRE( vec3ConstMap.col( 0 ) == Vector3 { 1_ra, 2_ra, 3_ra } );
97 REQUIRE( enumConstMap( 0 ) == MyEnum::B );
98
99 // the following lines are not allowed (std::enable_if fails at compile time)
100 // auto vecDynMap = vecDynArray.getMap();
101 // auto intPtrMap = intPtrArray.getMap();
102 // auto funMap = funArray.getMap();
103 // vecDynMap( 0 );
104 // intPtrMap( 0 );
105 // funMap( 0 );
106}
This class implements ContainerIntrospectionInterface for AlignedStdVector.
std::enable_if_t<(N > 0), MatrixMap > getMap()
typename TypeHelper::component_type component_type
size_t getSize() const override
size_t getBufferSize() const override
T emplace_back(T... args)
This namespace contains everything "low level", related to data, datastuctures, and computation.
Definition Cage.cpp:5
T push_back(T... args)