Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
1261385937 committed Nov 1, 2023
1 parent 79f311f commit d343428
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
50 changes: 13 additions & 37 deletions ut/Column_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,25 +376,18 @@ TYPED_TEST(GenericColumnTest, Swap) {
#endif

TYPED_TEST(GenericColumnTest, ReserveAndCapacity) {
if constexpr (
// TODO(venemkov): test that ColumnType has Reserve() and Capacity() methods
is_one_of_v<typename TestFixture::ColumnType,
// Only types that support Reserve() and Capacity() methods
ColumnUInt8,
ColumnUInt16,
ColumnUInt32,
ColumnUInt64,
ColumnInt8,
ColumnInt16,
ColumnInt32,
ColumnInt64,
ColumnInt128,
ColumnFloat32,
ColumnFloat64,
ColumnDate,
ColumnDate32,
ColumnDateTime>) {

using column_type = typename TestFixture::ColumnType;
auto [column0, values] = this->MakeColumnWithValues(2);
auto values_copy = values;
EXPECT_NO_THROW(column0->Reserve(0u));
EXPECT_EQ(2u, column0->Size());
EXPECT_TRUE(CompareRecursive(values, values_copy));

auto column1 = this->MakeColumn();
column1->Reserve(10u);
EXPECT_EQ(0u, column1->Size());

if constexpr (has_method_Reserve_v<column_type> && has_method_Capacity_v<column_type>) {
auto column = this->MakeColumn();
EXPECT_EQ(0u, column->Capacity());
EXPECT_NO_THROW(column->Reserve(100u));
Expand All @@ -408,24 +401,7 @@ TYPED_TEST(GenericColumnTest, ReserveAndCapacity) {


TYPED_TEST(GenericColumnTest, GetWritableData) {
if constexpr (
// TODO(venemkov): test that ColumnType has GetWritableData() method
is_one_of_v<typename TestFixture::ColumnType,
// Only types that support GetWritableData() method
ColumnUInt8,
ColumnUInt16,
ColumnUInt32,
ColumnUInt64,
ColumnInt8,
ColumnInt16,
ColumnInt32,
ColumnInt64,
ColumnInt128,
ColumnFloat32,
ColumnFloat64,
ColumnDate,
ColumnDate32,
ColumnDateTime>) {
if constexpr (has_method_GetWritableData_v<typename TestFixture::ColumnType>) {
auto [column, values] = this->MakeColumnWithValues(111);
// Do conversion from time_t to internal representation, similar to what ColumnDate and ColumnDate32 do
if constexpr (is_one_of_v<typename TestFixture::ColumnType,
Expand Down
14 changes: 14 additions & 0 deletions ut/utils_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ struct is_one_of<F, S, T...> {

template <typename F, typename S, typename... T>
inline constexpr bool is_one_of_v = is_one_of<F, S, T...>::value;


#define HAS_METHOD(FUN) \
template <typename T, class U = void> \
struct has_method_##FUN : std::false_type {}; \
template <typename T> \
struct has_method_##FUN<T, std::enable_if_t<std::is_member_function_pointer_v<decltype(&T::FUN)>>> \
: std::true_type {}; \
template <class T> \
constexpr bool has_method_##FUN##_v = has_method_##FUN<T>::value;

HAS_METHOD(Reserve);
HAS_METHOD(Capacity);
HAS_METHOD(GetWritableData);

0 comments on commit d343428

Please sign in to comment.