Skip to content

Commit

Permalink
add stack, vstack, hstack tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alifahrri committed May 25, 2024
1 parent f55ac64 commit 27f2d17
Show file tree
Hide file tree
Showing 25 changed files with 3,038 additions and 6 deletions.
93 changes: 93 additions & 0 deletions include/nmtools/testing/data/array/hstack.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#ifndef NMTOOLS_TESTING_DATA_ARRAY_HSTACK_HPP
#define NMTOOLS_TESTING_DATA_ARRAY_HSTACK_HPP

#include "nmtools/testing/testing.hpp"

NMTOOLS_TESTING_DECLARE_CASE(hstack)
{
NMTOOLS_TESTING_DECLARE_ARGS(case1)
{
inline int a[3] = {1,2,3};
inline int b[3] = {4,5,6};
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case1)
{
inline int result[6] = {1,2,3,4,5,6};
}

NMTOOLS_TESTING_DECLARE_ARGS(case2)
{
inline int a[2][3] = {
{1,2,3},
{4,5,6},
};
inline int b[2][3] = {
{ 7, 8, 9},
{10,11,12},
};
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case2)
{
inline int result[2][6] = {
{ 1, 2, 3, 7, 8, 9},
{ 4, 5, 6,10,11,12},
};
}

NMTOOLS_TESTING_DECLARE_ARGS(case3)
{
inline int a[2][3][2] = {
{
{1,2},
{3,4},
{5,6},
},
{
{ 7, 8},
{ 9,10},
{11,12},
}
};
inline int b[2][3][2] = {
{
{13,14},
{15,16},
{17,18},
},
{
{19,20},
{21,22},
{23,24},
}
};
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case3)
{
inline int result[2][6][2] = {
{
{ 1, 2},
{ 3, 4},
{ 5, 6},
{13,14},
{15,16},
{17,18},
},
{
{ 7, 8},
{ 9,10},
{11,12},
{19,20},
{21,22},
{23,24},
}
};
}
}

#endif // NMTOOLS_TESTING_DATA_ARRAY_HSTACK_HPP
126 changes: 126 additions & 0 deletions include/nmtools/testing/data/array/stack.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#ifndef NMTOOLS_TESTING_DATA_ARRAY_STACK_HPP
#define NMTOOLS_TESTING_DATA_ARRAY_STACK_HPP

#include "nmtools/testing/testing.hpp"

NMTOOLS_TESTING_DECLARE_CASE(stack)
{
NMTOOLS_TESTING_DECLARE_ARGS(case1)
{
inline int a[3] = {1,2,3};
inline int b[3] = {4,5,6};
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case1)
{
inline int result[2][3] = {
{1,2,3},
{4,5,6},
};
}

NMTOOLS_TESTING_DECLARE_ARGS(case2)
{
inline int a[3] = {1,2,3};
inline int b[3] = {4,5,6};
inline int axis = 1;
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case2)
{
inline int result[3][2] = {
{1,4},
{2,5},
{3,6},
};
}

NMTOOLS_TESTING_DECLARE_ARGS(case3)
{
inline int a[2][3] = {
{1,2,3},
{4,5,6},
};
inline int b[2][3] = {
{ 7, 8, 9},
{10,11,12},
};
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case3)
{
inline int result[2][2][3] = {
{
{1,2,3},
{4,5,6},
},
{
{ 7, 8, 9},
{10,11,12},
}
};
}

NMTOOLS_TESTING_DECLARE_ARGS(case4)
{
inline int a[2][3] = {
{1,2,3},
{4,5,6},
};
inline int b[2][3] = {
{ 7, 8, 9},
{10,11,12},
};
inline int axis = 1;
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case4)
{
inline int result[2][2][3] = {
{
{1,2,3},
{7,8,9},
},
{
{ 4, 5, 6},
{10,11,12},
}
};
}

NMTOOLS_TESTING_DECLARE_ARGS(case5)
{
inline int a[2][3] = {
{1,2,3},
{4,5,6},
};
inline int b[2][3] = {
{ 7, 8, 9},
{10,11,12},
};
inline int axis = 2;
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case5)
{
inline int result[2][3][2] = {
{
{1,7},
{2,8},
{3,9},
},
{
{4,10},
{5,11},
{6,12},
}
};
}
}

#endif // NMTOOLS_TESTING_DATA_ARRAY_STACK_HPP
102 changes: 102 additions & 0 deletions include/nmtools/testing/data/array/vstack.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#ifndef NMTOOLS_TESTING_DATA_ARRAY_VSTACK_HPP
#define NMTOOLS_TESTING_DATA_ARRAY_VSTACK_HPP

#include "nmtools/testing/testing.hpp"

NMTOOLS_TESTING_DECLARE_CASE(vstack)
{
NMTOOLS_TESTING_DECLARE_ARGS(case1)
{
inline int a[3] = {1,2,3};
inline int b[3] = {4,5,6};
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case1)
{
inline int result[2][3] = {
{1,2,3},
{4,5,6}
};
}

NMTOOLS_TESTING_DECLARE_ARGS(case2)
{
inline int a[2][3] = {
{1,2,3},
{4,5,6},
};
inline int b[2][3] = {
{ 7, 8, 9},
{10,11,12},
};
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case2)
{
inline int result[4][3] = {
{ 1, 2, 3},
{ 4, 5, 6},
{ 7, 8, 9},
{10,11,12},
};
}

NMTOOLS_TESTING_DECLARE_ARGS(case3)
{
inline int a[2][3][2] = {
{
{1,2},
{3,4},
{5,6},
},
{
{ 7, 8},
{ 9,10},
{11,12},
}
};
inline int b[2][3][2] = {
{
{13,14},
{15,16},
{17,18},
},
{
{19,20},
{21,22},
{23,24},
}
};
NMTOOLS_CAST_ARRAYS(a)
NMTOOLS_CAST_ARRAYS(b)
}
NMTOOLS_TESTING_DECLARE_EXPECT(case3)
{
inline int result[4][3][2] = {
{
{ 1, 2},
{ 3, 4},
{ 5, 6},
},
{
{ 7, 8},
{ 9,10},
{11,12},
},
{
{13,14},
{15,16},
{17,18},
},
{
{19,20},
{21,22},
{23,24},
}
};
}
}

#endif // NMTOOLS_TESTING_DATA_ARRAY_VSTACK_HPP
35 changes: 33 additions & 2 deletions include/nmtools/testing/doctest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace utils = nmtools::utils;
CHECK_MESSAGE(isequal(result,expect), \
( \
std::string{} \
+ "\n\tActual : " + STRINGIFY(result) \
+ "\n\tExpected: " + STRINGIFY(expect) \
+ "\n\tActual :\n" + STRINGIFY(result) \
+ "\n\tExpected :\n" + STRINGIFY(expect) \
+ "\n\tArguments:\n" + arguments_string \
) \
); \
Expand Down Expand Up @@ -56,6 +56,32 @@ namespace utils = nmtools::utils;
); \
}

#define NMTOOLS_ASSERT_CLOSE_MSG_OPERANDS_DOCTEST(result,expect,...) \
{ \
auto args_pack = nmtools_tuple{__VA_ARGS__}; \
auto arguments_string = std::string{}; \
constexpr auto n_args = meta::len_v<decltype(args_pack)>; \
meta::template_for<n_args>([&](auto I){ \
auto arg_typename = nmtools_string(NMTOOLS_TESTING_GET_TYPENAME(decltype(nmtools::at(args_pack,I)))); \
arguments_string += "\t(#"; arguments_string += utils::to_string(I); arguments_string += "): "; \
arguments_string += nmtools_string("\033[0;90m(") + arg_typename + nmtools_string(")\033[0m:\n\t\t"); \
arguments_string += utils::to_string(nmtools::at(args_pack,I)); \
arguments_string += "\n"; \
}); \
auto result_typename = NMTOOLS_TESTING_GET_TYPENAME(decltype(result)); \
auto expect_typename = NMTOOLS_TESTING_GET_TYPENAME(decltype(expect)); \
CHECK_MESSAGE(isclose(result,expect), \
( \
std::string{} \
+ "\n\tActual " + "\033[0;90m<" + result_typename + ">\033[0m:\n" \
+ STRINGIFY(result) \
+ "\n\tExpected " + "\033[0;90m<" + expect_typename + ">\033[0m:\n" \
+ STRINGIFY(expect) \
+ "\n\tArguments:\n" + arguments_string \
) \
); \
}

#define NMTOOLS_ASSERT_APPLY_EQUAL_DOCTEST(result,expect) \
{ \
auto result_typename = nmtools_string(NMTOOLS_TESTING_GET_TYPENAME(decltype(result))); \
Expand All @@ -73,6 +99,7 @@ namespace utils = nmtools::utils;

namespace nmtools::testing
{
// TODO: remove
template <typename T>
constexpr auto maybe_shape(const T& t)
{
Expand All @@ -99,6 +126,7 @@ namespace nmtools::testing
#undef NMTOOLS_ASSERT_APPLY_EQUAL
#define NMTOOLS_ASSERT_APPLY_EQUAL NMTOOLS_ASSERT_APPLY_EQUAL_DOCTEST

// TODO: remove
#define NMTOOLS_ASSERT_SHAPE(result,expect) \
{ \
NMTOOLS_ASSERT_EQUAL( nmtools::testing::maybe_shape(result), nmtools::testing::maybe_shape(expect) ); \
Expand All @@ -110,6 +138,9 @@ namespace nmtools::testing
#undef NMTOOLS_ASSERT_EQUAL_MSG_ATTRIBUTES
#define NMTOOLS_ASSERT_EQUAL_MSG_ATTRIBUTES NMTOOLS_ASSERT_EQUAL_MSG_ATTRIBUTES_DOCTEST

#undef NMTOOLS_ASSERT_CLOSE_MSG_OPERANDS
#define NMTOOLS_ASSERT_CLOSE_MSG_OPERANDS NMTOOLS_ASSERT_CLOSE_MSG_OPERANDS_DOCTEST

#undef NMTOOLS_ASSERT_NOT_EQUAL
#define NMTOOLS_ASSERT_NOT_EQUAL NMTOOLS_ASSERT_NOT_EQUAL_DOCTEST

Expand Down
Loading

0 comments on commit 27f2d17

Please sign in to comment.