Add unit test for offset-based getters.

This commit is contained in:
King_DuckZ 2018-07-28 00:04:24 +01:00
parent a81c4c1077
commit 1e713696d7
2 changed files with 142 additions and 0 deletions

View file

@ -8,6 +8,7 @@ add_executable(${PROJECT_NAME}
test_get_at.cpp test_get_at.cpp
test_operators.cpp test_operators.cpp
test_sequence_range.cpp test_sequence_range.cpp
test_offset_getters.cpp
) )
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}

View file

@ -0,0 +1,141 @@
/*
* Copyright 2015-2017 Michele "King_DuckZ" Santullo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "vectorwrapper/vectorwrapper.hpp"
#include <gtest/gtest.h>
#include <cstddef>
struct Point {
int x, y;
};
struct Line {
int x, y, z;
};
struct Hyperline {
int x, y, z, w;
};
namespace vwr {
template <>
struct VectorWrapperInfo<Point> {
enum { dimensions = 2 };
typedef int scalar_type;
typedef Point vector_type;
typedef Line higher_vector_type;
enum {
offset_x = offsetof(vector_type, x),
offset_y = offsetof(vector_type, y)
};
};
template <>
struct VectorWrapperInfo<Line> {
enum { dimensions = 3 };
typedef int scalar_type;
typedef Line vector_type;
typedef Point lower_vector_type;
typedef Hyperline higher_vector_type;
enum {
offset_x = offsetof(vector_type, x),
offset_y = offsetof(vector_type, y),
offset_z = offsetof(vector_type, z)
};
};
template <>
struct VectorWrapperInfo<Hyperline> {
enum { dimensions = 4 };
typedef int scalar_type;
typedef Hyperline vector_type;
typedef Line lower_vector_type;
enum {
offset_x = offsetof(vector_type, x),
offset_y = offsetof(vector_type, y),
offset_z = offsetof(vector_type, z),
offset_w = offsetof(vector_type, w)
};
};
} //namespace vwr
using vec2 = vwr::Vec<Point>;
using vec3 = vwr::Vec<Line>;
using vec4 = vwr::Vec<Hyperline>;
TEST(vwr, offset_get_at) {
{
vec2 v(300000, 400000);
EXPECT_EQ(v.data().x, 300000);
EXPECT_EQ(v.data().y, 400000);
EXPECT_EQ(v.x(), 300000);
EXPECT_EQ(v.y(), 400000);
v.x()++;
v.y()++;
EXPECT_EQ(v.data().x, 300001);
EXPECT_EQ(v.data().y, 400001);
EXPECT_EQ(v.x(), 300001);
EXPECT_EQ(v.y(), 400001);
}
{
vec3 v(330000, 440000, 550000);
EXPECT_EQ(v.data().x, 330000);
EXPECT_EQ(v.data().y, 440000);
EXPECT_EQ(v.data().z, 550000);
EXPECT_EQ(v.x(), 330000);
EXPECT_EQ(v.y(), 440000);
EXPECT_EQ(v.z(), 550000);
v.x()++;
v.y()++;
v.z()++;
EXPECT_EQ(v.data().x, 330001);
EXPECT_EQ(v.data().y, 440001);
EXPECT_EQ(v.data().z, 550001);
EXPECT_EQ(v.x(), 330001);
EXPECT_EQ(v.y(), 440001);
EXPECT_EQ(v.z(), 550001);
}
{
vec4 v(333000, 444000, 555000, 666000);
EXPECT_EQ(v.data().x, 333000);
EXPECT_EQ(v.data().y, 444000);
EXPECT_EQ(v.data().z, 555000);
EXPECT_EQ(v.data().w, 666000);
EXPECT_EQ(v.x(), 333000);
EXPECT_EQ(v.y(), 444000);
EXPECT_EQ(v.z(), 555000);
EXPECT_EQ(v.w(), 666000);
v.x()++;
v.y()++;
v.z()++;
v.w()++;
EXPECT_EQ(v.data().x, 333001);
EXPECT_EQ(v.data().y, 444001);
EXPECT_EQ(v.data().z, 555001);
EXPECT_EQ(v.data().w, 666001);
EXPECT_EQ(v.x(), 333001);
EXPECT_EQ(v.y(), 444001);
EXPECT_EQ(v.z(), 555001);
EXPECT_EQ(v.w(), 666001);
}
}