Skip to content

Commit 6dc9c68

Browse files
committed
[brief] Adds unit tests for concepts.
[detailed] - All concepts are now fully unit tested. - Adds a test for the delimiter functor concept from string.
1 parent 3830a65 commit 6dc9c68

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(TEST_SOURCE
1212
${ZEUS_TEST_ROOT}/random_test.cpp
1313
${ZEUS_TEST_ROOT}/string_test.cpp
1414
${ZEUS_TEST_ROOT}/range_test.cpp
15+
${ZEUS_TEST_ROOT}/concepts_test.cpp
1516
)
1617

1718
source_group("source" FILES ${TEST_SOURCE})

test/concepts_test.cpp

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#include <zeus/concepts.hpp>
2+
3+
#include <catch2/catch_test_macros.hpp>
4+
5+
TEST_CASE("[concepts] - Enum", "[zeus]")
6+
{
7+
enum Foo
8+
{
9+
a = 0
10+
};
11+
12+
enum class Bar
13+
{
14+
b = 0
15+
};
16+
17+
STATIC_REQUIRE(zeus::Enum<Foo>);
18+
STATIC_REQUIRE(zeus::Enum<Bar>);
19+
STATIC_REQUIRE_FALSE(zeus::Enum<int>);
20+
}
21+
22+
TEST_CASE("[concepts] - ScopedEnum", "[zeus]")
23+
{
24+
enum Foo
25+
{
26+
a = 0
27+
};
28+
29+
enum class Bar
30+
{
31+
b = 0
32+
};
33+
34+
STATIC_REQUIRE(zeus::ScopedEnum<Bar>);
35+
STATIC_REQUIRE_FALSE(zeus::ScopedEnum<Foo>);
36+
STATIC_REQUIRE_FALSE(zeus::ScopedEnum<int>);
37+
}
38+
39+
TEST_CASE("[concepts] - UnsignedEnum", "[zeus]")
40+
{
41+
enum Foo : int
42+
{
43+
a
44+
};
45+
46+
enum Bar : unsigned char
47+
{
48+
b
49+
};
50+
51+
enum class Baz : int
52+
{
53+
c
54+
};
55+
56+
enum class Bumble : unsigned int
57+
{
58+
d
59+
};
60+
61+
STATIC_REQUIRE(zeus::UnsignedEnum<Bar>);
62+
STATIC_REQUIRE_FALSE(zeus::UnsignedEnum<Foo>);
63+
64+
STATIC_REQUIRE(zeus::UnsignedEnum<Bumble>);
65+
STATIC_REQUIRE_FALSE(zeus::UnsignedEnum<Baz>);
66+
}
67+
68+
TEST_CASE("[concepts] - UnsignedScopedEnum", "[zeus]")
69+
{
70+
enum Foo : int
71+
{
72+
a
73+
};
74+
75+
enum Bar : unsigned char
76+
{
77+
b
78+
};
79+
80+
enum class Baz : int
81+
{
82+
c
83+
};
84+
85+
enum class Bumble : unsigned int
86+
{
87+
d
88+
};
89+
90+
STATIC_REQUIRE(zeus::UnsignedScopedEnum<Bumble>);
91+
STATIC_REQUIRE_FALSE(zeus::UnsignedScopedEnum<Baz>);
92+
STATIC_REQUIRE_FALSE(zeus::UnsignedScopedEnum<Bar>);
93+
STATIC_REQUIRE_FALSE(zeus::UnsignedScopedEnum<Foo>);
94+
}
95+
96+
TEST_CASE("[concepts] - IntegralType", "[zeus]")
97+
{
98+
STATIC_REQUIRE(zeus::IntegralType<char>);
99+
STATIC_REQUIRE(zeus::IntegralType<char8_t>);
100+
STATIC_REQUIRE(zeus::IntegralType<char16_t>);
101+
STATIC_REQUIRE(zeus::IntegralType<char32_t>);
102+
STATIC_REQUIRE(zeus::IntegralType<wchar_t>);
103+
STATIC_REQUIRE(zeus::IntegralType<short>);
104+
STATIC_REQUIRE(zeus::IntegralType<int>);
105+
STATIC_REQUIRE(zeus::IntegralType<long>);
106+
STATIC_REQUIRE(zeus::IntegralType<long long>);
107+
108+
STATIC_REQUIRE_FALSE(zeus::IntegralType<float>);
109+
STATIC_REQUIRE_FALSE(zeus::IntegralType<double>);
110+
STATIC_REQUIRE_FALSE(zeus::IntegralType<long double>);
111+
STATIC_REQUIRE_FALSE(zeus::IntegralType<bool>);
112+
}
113+
114+
TEST_CASE("[concepts] - ArithmeticType", "[zeus]")
115+
{
116+
STATIC_REQUIRE(zeus::ArithmeticType<char>);
117+
STATIC_REQUIRE(zeus::ArithmeticType<char8_t>);
118+
STATIC_REQUIRE(zeus::ArithmeticType<char16_t>);
119+
STATIC_REQUIRE(zeus::ArithmeticType<char32_t>);
120+
STATIC_REQUIRE(zeus::ArithmeticType<wchar_t>);
121+
STATIC_REQUIRE(zeus::ArithmeticType<short>);
122+
STATIC_REQUIRE(zeus::ArithmeticType<int>);
123+
STATIC_REQUIRE(zeus::ArithmeticType<long>);
124+
STATIC_REQUIRE(zeus::ArithmeticType<long long>);
125+
STATIC_REQUIRE(zeus::ArithmeticType<float>);
126+
STATIC_REQUIRE(zeus::ArithmeticType<double>);
127+
STATIC_REQUIRE(zeus::ArithmeticType<long double>);
128+
129+
STATIC_REQUIRE_FALSE(zeus::ArithmeticType<bool>);
130+
}

test/string_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ TEST_CASE("[string] - is_whitespace", "[zeus]")
1515
REQUIRE_FALSE(zeus::is_whitespace('c'));
1616
}
1717

18+
TEST_CASE("[string] DelimiterFunctor concept", "[zeus]")
19+
{
20+
SECTION("Valid functor")
21+
{
22+
constexpr auto fun = [](char) {
23+
return false;
24+
};
25+
STATIC_REQUIRE(zeus::DelimiterFunctor<decltype(fun)>);
26+
}
27+
28+
SECTION("Invalid functors")
29+
{
30+
constexpr auto void_fun = [](char) {};
31+
STATIC_REQUIRE_FALSE(zeus::DelimiterFunctor<decltype(void_fun)>);
32+
33+
constexpr auto str_fun = [](std::string) {
34+
return false;
35+
};
36+
STATIC_REQUIRE_FALSE(zeus::DelimiterFunctor<decltype(str_fun)>);
37+
}
38+
}
39+
1840
TEST_CASE("[string] - split", "[zeus]")
1941
{
2042
static constexpr char delim{'_'};

0 commit comments

Comments
 (0)