Add test for wrapped vector using get_at() which was not working previously.
This commit is contained in:
parent
84203ee817
commit
736e83893a
2 changed files with 56 additions and 0 deletions
|
@ -5,6 +5,7 @@ add_executable(${PROJECT_NAME}
|
|||
test_conversions.cpp
|
||||
test_ops.cpp
|
||||
example.cpp
|
||||
test_get_at.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
|
|
55
test/unit/test_get_at.cpp
Normal file
55
test/unit/test_get_at.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include "vectorwrapper/vectorwrapper.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace vwr {
|
||||
template <>
|
||||
struct VectorWrapperInfo<std::array<uint16_t, 2>> {
|
||||
enum {
|
||||
dimensions = 2
|
||||
};
|
||||
|
||||
typedef uint16_t scalar_type;
|
||||
|
||||
typedef std::array<scalar_type, dimensions> vector_type;
|
||||
|
||||
typedef std::array<scalar_type, dimensions + 1> higher_vector_type;
|
||||
|
||||
static scalar_type& get_at (size_t parIndex, vector_type& parVector) {
|
||||
return parVector[parIndex];
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct VectorWrapperInfo<std::array<uint16_t, 3>> {
|
||||
enum {
|
||||
dimensions = 3
|
||||
};
|
||||
|
||||
typedef uint16_t scalar_type;
|
||||
|
||||
typedef std::array<scalar_type, dimensions> vector_type;
|
||||
|
||||
typedef std::array<scalar_type, dimensions - 1> lower_vector_type;
|
||||
|
||||
static scalar_type& get_at (size_t parIndex, vector_type& parVector) {
|
||||
return parVector[parIndex];
|
||||
}
|
||||
};
|
||||
} //namespace vwr
|
||||
|
||||
using vec2 = vwr::Vec<std::array<uint16_t, 2>>;
|
||||
using vec3 = vwr::Vec<std::array<uint16_t, 3>>;
|
||||
|
||||
TEST(vwr, get_at) {
|
||||
const uint16_t v2 = 0x0c0cU;
|
||||
vec2 myvec2(v2);
|
||||
EXPECT_EQ(v2, myvec2.x());
|
||||
EXPECT_EQ(v2, myvec2.y());
|
||||
|
||||
const uint16_t v3 = 0xababU;
|
||||
vec3 myvec3(myvec2.x(), myvec2.y(), v3);
|
||||
EXPECT_EQ(v2, myvec3.x());
|
||||
EXPECT_EQ(v2, myvec3.y());
|
||||
EXPECT_EQ(v3, myvec3.z());
|
||||
}
|
Loading…
Reference in a new issue