Commit 03cec20e authored by Rostyslav Geyyer's avatar Rostyslav Geyyer
Browse files

Add AsType test cases

parent d71189ff
...@@ -3,14 +3,17 @@ ...@@ -3,14 +3,17 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "ck/utility/data_type.hpp" #include "ck/utility/data_type.hpp"
#include "ck/utility/type_convert.hpp"
using ck::bf8_t; using ck::bf8_t;
using ck::bhalf_t; using ck::bhalf_t;
using ck::f8_t; using ck::f8_t;
using ck::half_t; using ck::half_t;
using ck::Number;
using ck::type_convert;
using ck::vector_type; using ck::vector_type;
TEST(Custom_bool, Test) TEST(Custom_bool, TestSize)
{ {
struct custom_bool_t struct custom_bool_t
{ {
...@@ -32,7 +35,34 @@ TEST(Custom_bool, Test) ...@@ -32,7 +35,34 @@ TEST(Custom_bool, Test)
ASSERT_EQ(sizeof(vector_type<custom_bool_t, 64>), 64); ASSERT_EQ(sizeof(vector_type<custom_bool_t, 64>), 64);
} }
TEST(Custom_int8, Test) TEST(Custom_bool, TestAsType)
{
struct custom_bool_t
{
using type = bool;
type data;
custom_bool_t() : data{type{}} {}
custom_bool_t(type init) : data{init} {}
};
// test size
const int size = 4;
std::vector<bool> test_vec = {false, true, false, true};
// reference vector
vector_type<custom_bool_t, size> right_vec;
// assign test values to the vector
ck::static_for<0, size, 1>{}([&](auto i) {
right_vec.template AsType<custom_bool_t>()(Number<i>{}) = custom_bool_t{test_vec.at(i)};
});
// copy the vector
vector_type<custom_bool_t, size> left_vec{right_vec};
// check if values were copied correctly
ck::static_for<0, size, 1>{}([&](auto i) {
ASSERT_EQ(left_vec.template AsType<custom_bool_t>()(Number<i>{}).data, test_vec.at(i));
});
}
TEST(Custom_int8, TestSize)
{ {
struct custom_int8_t struct custom_int8_t
{ {
...@@ -54,7 +84,34 @@ TEST(Custom_int8, Test) ...@@ -54,7 +84,34 @@ TEST(Custom_int8, Test)
ASSERT_EQ(sizeof(vector_type<custom_int8_t, 64>), 64); ASSERT_EQ(sizeof(vector_type<custom_int8_t, 64>), 64);
} }
TEST(Custom_uint8, Test) TEST(Custom_int8, TestAsType)
{
struct custom_int8_t
{
using type = int8_t;
type data;
custom_int8_t() : data{type{}} {}
custom_int8_t(type init) : data{init} {}
};
// test size
const int size = 4;
std::vector<int8_t> test_vec = {3, -6, 8, -2};
// reference vector
vector_type<custom_int8_t, size> right_vec;
// assign test values to the vector
ck::static_for<0, size, 1>{}([&](auto i) {
right_vec.template AsType<custom_int8_t>()(Number<i>{}) = custom_int8_t{test_vec.at(i)};
});
// copy the vector
vector_type<custom_int8_t, size> left_vec{right_vec};
// check if values were copied correctly
ck::static_for<0, size, 1>{}([&](auto i) {
ASSERT_EQ(left_vec.template AsType<custom_int8_t>()(Number<i>{}).data, test_vec.at(i));
});
}
TEST(Custom_uint8, TestSize)
{ {
struct custom_uint8_t struct custom_uint8_t
{ {
...@@ -76,7 +133,34 @@ TEST(Custom_uint8, Test) ...@@ -76,7 +133,34 @@ TEST(Custom_uint8, Test)
ASSERT_EQ(sizeof(vector_type<custom_uint8_t, 64>), 64); ASSERT_EQ(sizeof(vector_type<custom_uint8_t, 64>), 64);
} }
TEST(Custom_f8, Test) TEST(Custom_uint8, TestAsType)
{
struct custom_uint8_t
{
using type = uint8_t;
type data;
custom_uint8_t() : data{type{}} {}
custom_uint8_t(type init) : data{init} {}
};
// test size
const int size = 4;
std::vector<uint8_t> test_vec = {3, 6, 8, 2};
// reference vector
vector_type<custom_uint8_t, size> right_vec;
// assign test values to the vector
ck::static_for<0, size, 1>{}([&](auto i) {
right_vec.template AsType<custom_uint8_t>()(Number<i>{}) = custom_uint8_t{test_vec.at(i)};
});
// copy the vector
vector_type<custom_uint8_t, size> left_vec{right_vec};
// check if values were copied correctly
ck::static_for<0, size, 1>{}([&](auto i) {
ASSERT_EQ(left_vec.template AsType<custom_uint8_t>()(Number<i>{}).data, test_vec.at(i));
});
}
TEST(Custom_f8, TestSize)
{ {
struct custom_f8_t struct custom_f8_t
{ {
...@@ -98,7 +182,37 @@ TEST(Custom_f8, Test) ...@@ -98,7 +182,37 @@ TEST(Custom_f8, Test)
ASSERT_EQ(sizeof(vector_type<custom_f8_t, 64>), 64); ASSERT_EQ(sizeof(vector_type<custom_f8_t, 64>), 64);
} }
TEST(Custom_bf8, Test) TEST(Custom_f8, TestAsType)
{
struct custom_f8_t
{
using type = _BitInt(8);
type data;
custom_f8_t() : data{type{}} {}
custom_f8_t(type init) : data{init} {}
};
// test size
const int size = 4;
std::vector<_BitInt(8)> test_vec = {type_convert<_BitInt(8)>(0.3f),
type_convert<_BitInt(8)>(-0.6f),
type_convert<_BitInt(8)>(0.8f),
type_convert<_BitInt(8)>(-0.2f)};
// reference vector
vector_type<custom_f8_t, size> right_vec;
// assign test values to the vector
ck::static_for<0, size, 1>{}([&](auto i) {
right_vec.template AsType<custom_f8_t>()(Number<i>{}) = custom_f8_t{test_vec.at(i)};
});
// copy the vector
vector_type<custom_f8_t, size> left_vec{right_vec};
// check if values were copied correctly
ck::static_for<0, size, 1>{}([&](auto i) {
ASSERT_EQ(left_vec.template AsType<custom_f8_t>()(Number<i>{}).data, test_vec.at(i));
});
}
TEST(Custom_bf8, TestSize)
{ {
struct custom_bf8_t struct custom_bf8_t
{ {
...@@ -120,7 +234,37 @@ TEST(Custom_bf8, Test) ...@@ -120,7 +234,37 @@ TEST(Custom_bf8, Test)
ASSERT_EQ(sizeof(vector_type<custom_bf8_t, 64>), 64); ASSERT_EQ(sizeof(vector_type<custom_bf8_t, 64>), 64);
} }
TEST(Custom_half, Test) TEST(Custom_bf8, TestAsType)
{
struct custom_bf8_t
{
using type = unsigned _BitInt(8);
type data;
custom_bf8_t() : data{type{}} {}
custom_bf8_t(type init) : data{init} {}
};
// test size
const int size = 4;
std::vector<unsigned _BitInt(8)> test_vec = {type_convert<unsigned _BitInt(8)>(0.3f),
type_convert<unsigned _BitInt(8)>(-0.6f),
type_convert<unsigned _BitInt(8)>(0.8f),
type_convert<unsigned _BitInt(8)>(-0.2f)};
// reference vector
vector_type<custom_bf8_t, size> right_vec;
// assign test values to the vector
ck::static_for<0, size, 1>{}([&](auto i) {
right_vec.template AsType<custom_bf8_t>()(Number<i>{}) = custom_bf8_t{test_vec.at(i)};
});
// copy the vector
vector_type<custom_bf8_t, size> left_vec{right_vec};
// check if values were copied correctly
ck::static_for<0, size, 1>{}([&](auto i) {
ASSERT_EQ(left_vec.template AsType<custom_bf8_t>()(Number<i>{}).data, test_vec.at(i));
});
}
TEST(Custom_half, TestSize)
{ {
struct custom_half_t struct custom_half_t
{ {
...@@ -142,7 +286,34 @@ TEST(Custom_half, Test) ...@@ -142,7 +286,34 @@ TEST(Custom_half, Test)
ASSERT_EQ(sizeof(vector_type<custom_half_t, 64>), 128); ASSERT_EQ(sizeof(vector_type<custom_half_t, 64>), 128);
} }
TEST(Custom_bhalf, Test) TEST(Custom_half, TestAsType)
{
struct custom_half_t
{
using type = half_t;
type data;
custom_half_t() : data{type{}} {}
custom_half_t(type init) : data{init} {}
};
// test size
const int size = 4;
std::vector<half_t> test_vec = {half_t{0.3f}, half_t{-0.6f}, half_t{0.8f}, half_t{-0.2f}};
// reference vector
vector_type<custom_half_t, size> right_vec;
// assign test values to the vector
ck::static_for<0, size, 1>{}([&](auto i) {
right_vec.template AsType<custom_half_t>()(Number<i>{}) = custom_half_t{test_vec.at(i)};
});
// copy the vector
vector_type<custom_half_t, size> left_vec{right_vec};
// check if values were copied correctly
ck::static_for<0, size, 1>{}([&](auto i) {
ASSERT_EQ(left_vec.template AsType<custom_half_t>()(Number<i>{}).data, test_vec.at(i));
});
}
TEST(Custom_bhalf, TestSize)
{ {
struct custom_bhalf_t struct custom_bhalf_t
{ {
...@@ -164,7 +335,37 @@ TEST(Custom_bhalf, Test) ...@@ -164,7 +335,37 @@ TEST(Custom_bhalf, Test)
ASSERT_EQ(sizeof(vector_type<custom_bhalf_t, 64>), 128); ASSERT_EQ(sizeof(vector_type<custom_bhalf_t, 64>), 128);
} }
TEST(Custom_float, Test) TEST(Custom_bhalf, TestAsType)
{
struct custom_bhalf_t
{
using type = bhalf_t;
type data;
custom_bhalf_t() : data{type{}} {}
custom_bhalf_t(type init) : data{init} {}
};
// test size
const int size = 4;
std::vector<bhalf_t> test_vec = {type_convert<bhalf_t>(0.3f),
type_convert<bhalf_t>(-0.6f),
type_convert<bhalf_t>(0.8f),
type_convert<bhalf_t>(-0.2f)};
// reference vector
vector_type<custom_bhalf_t, size> right_vec;
// assign test values to the vector
ck::static_for<0, size, 1>{}([&](auto i) {
right_vec.template AsType<custom_bhalf_t>()(Number<i>{}) = custom_bhalf_t{test_vec.at(i)};
});
// copy the vector
vector_type<custom_bhalf_t, size> left_vec{right_vec};
// check if values were copied correctly
ck::static_for<0, size, 1>{}([&](auto i) {
ASSERT_EQ(left_vec.template AsType<custom_bhalf_t>()(Number<i>{}).data, test_vec.at(i));
});
}
TEST(Custom_float, TestSize)
{ {
struct custom_float_t struct custom_float_t
{ {
...@@ -186,7 +387,34 @@ TEST(Custom_float, Test) ...@@ -186,7 +387,34 @@ TEST(Custom_float, Test)
ASSERT_EQ(sizeof(vector_type<custom_float_t, 64>), 256); ASSERT_EQ(sizeof(vector_type<custom_float_t, 64>), 256);
} }
TEST(Custom_double, Test) TEST(Custom_float, TestAsType)
{
struct custom_float_t
{
using type = float;
type data;
custom_float_t() : data{type{}} {}
custom_float_t(type init) : data{init} {}
};
// test size
const int size = 4;
std::vector<float> test_vec = {0.3f, -0.6f, 0.8f, -0.2f};
// reference vector
vector_type<custom_float_t, size> right_vec;
// assign test values to the vector
ck::static_for<0, size, 1>{}([&](auto i) {
right_vec.template AsType<custom_float_t>()(Number<i>{}) = custom_float_t{test_vec.at(i)};
});
// copy the vector
vector_type<custom_float_t, size> left_vec{right_vec};
// check if values were copied correctly
ck::static_for<0, size, 1>{}([&](auto i) {
ASSERT_EQ(left_vec.template AsType<custom_float_t>()(Number<i>{}).data, test_vec.at(i));
});
}
TEST(Custom_double, TestSize)
{ {
struct custom_double_t struct custom_double_t
{ {
...@@ -207,3 +435,30 @@ TEST(Custom_double, Test) ...@@ -207,3 +435,30 @@ TEST(Custom_double, Test)
ASSERT_EQ(sizeof(vector_type<double, 64>), 512); ASSERT_EQ(sizeof(vector_type<double, 64>), 512);
ASSERT_EQ(sizeof(vector_type<custom_double_t, 64>), 512); ASSERT_EQ(sizeof(vector_type<custom_double_t, 64>), 512);
} }
TEST(Custom_double, TestAsType)
{
struct custom_double_t
{
using type = double;
type data;
custom_double_t() : data{type{}} {}
custom_double_t(type init) : data{init} {}
};
// test size
const int size = 4;
std::vector<double> test_vec = {0.3, 0.6, 0.8, 0.2};
// reference vector
vector_type<custom_double_t, size> right_vec;
// assign test values to the vector
ck::static_for<0, size, 1>{}([&](auto i) {
right_vec.template AsType<custom_double_t>()(Number<i>{}) = custom_double_t{test_vec.at(i)};
});
// copy the vector
vector_type<custom_double_t, size> left_vec{right_vec};
// check if values were copied correctly
ck::static_for<0, size, 1>{}([&](auto i) {
ASSERT_EQ(left_vec.template AsType<custom_double_t>()(Number<i>{}).data, test_vec.at(i));
});
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment