|
2 | 2 |
|
3 | 3 | #include <beman/{{cookiecutter.project_name}}/identity.hpp> |
4 | 4 |
|
| 5 | +{% if cookiecutter.unit_test_library == "gtest" %} |
5 | 6 | #include <gtest/gtest.h> |
| 7 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 8 | +#include <catch2/catch_all.hpp> |
| 9 | +{% endif %} |
6 | 10 |
|
7 | 11 | #include <algorithm> |
8 | 12 | #include <functional> |
9 | 13 |
|
10 | 14 | namespace exe = beman::{{cookiecutter.project_name}}; |
11 | 15 |
|
| 16 | +{% if cookiecutter.unit_test_library == "gtest" %} |
12 | 17 | TEST(IdentityTest, call_identity_with_int) { |
| 18 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 19 | +TEST_CASE("can call identity with int", "[{{cookiecutter.project_name}}::call_identity_with_int]") { |
| 20 | +{% endif %} |
13 | 21 | for (int i = -100; i < 100; ++i) { |
| 22 | +{% if cookiecutter.unit_test_library == "gtest" %} |
14 | 23 | EXPECT_EQ(i, exe::identity()(i)); |
| 24 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 25 | + CHECK(i == exe::identity()(i)); |
| 26 | +{% endif %} |
15 | 27 | } |
16 | 28 | } |
17 | 29 |
|
| 30 | +{% if cookiecutter.unit_test_library == "gtest" %} |
18 | 31 | TEST(IdentityTest, call_identity_with_custom_type) { |
| 32 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 33 | +TEST_CASE("can call identity with custom type", "[{{cookiecutter.project_name}}::call_identity_with_custom_type]") { |
| 34 | +{% endif %} |
19 | 35 | struct S { |
20 | 36 | int i; |
21 | 37 | }; |
22 | 38 |
|
23 | 39 | for (int i = -100; i < 100; ++i) { |
24 | 40 | const S s{i}; |
25 | 41 | const S s_id = exe::identity()(s); |
| 42 | +{% if cookiecutter.unit_test_library == "gtest" %} |
26 | 43 | EXPECT_EQ(s.i, s_id.i); |
| 44 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 45 | + CHECK(s.i == s_id.i); |
| 46 | +{% endif %} |
27 | 47 | } |
28 | 48 | } |
29 | 49 |
|
| 50 | +{% if cookiecutter.unit_test_library == "gtest" %} |
30 | 51 | TEST(IdentityTest, compare_std_vs_beman) { |
| 52 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 53 | +TEST_CASE("compare std vs beman", "[{{cookiecutter.project_name}}::compare_std_vs_beman]") { |
| 54 | +{% endif %} |
31 | 55 | // Requires: std::identity support. |
32 | 56 | #if defined(__cpp_lib_type_identity) |
33 | 57 | std::identity std_id; |
34 | 58 | exe::identity beman_id; |
35 | 59 | for (int i = -100; i < 100; ++i) { |
| 60 | +{% if cookiecutter.unit_test_library == "gtest" %} |
36 | 61 | EXPECT_EQ(std_id(i), beman_id(i)); |
| 62 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 63 | + CHECK(std_id(i) == beman_id(i)); |
| 64 | +{% endif %} |
37 | 65 | } |
38 | 66 | #endif |
39 | 67 | } |
40 | 68 |
|
| 69 | +{% if cookiecutter.unit_test_library == "gtest" %} |
41 | 70 | TEST(IdentityTest, check_is_transparent) { |
| 71 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 72 | +TEST_CASE("check is transparent", "[{{cookiecutter.project_name}}::check_is_transparent]") { |
| 73 | +{% endif %} |
42 | 74 | // Requires: transparent operators support. |
43 | 75 | #if defined(__cpp_lib_transparent_operators) |
44 | 76 |
|
45 | 77 | exe::identity id; |
46 | 78 |
|
47 | 79 | const auto container = {1, 2, 3, 4, 5}; |
48 | 80 | auto it = std::find(std::begin(container), std::end(container), 3); |
| 81 | +{% if cookiecutter.unit_test_library == "gtest" %} |
49 | 82 | EXPECT_EQ(3, *it); |
| 83 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 84 | + CHECK(3 == *it); |
| 85 | +{% endif %} |
50 | 86 | auto it_with_id = std::find(std::begin(container), std::end(container), id(3)); |
| 87 | +{% if cookiecutter.unit_test_library == "gtest" %} |
51 | 88 | EXPECT_EQ(3, *it_with_id); |
52 | 89 |
|
53 | 90 | EXPECT_EQ(it, it_with_id); |
| 91 | +{% elif cookiecutter.unit_test_library == "catch2" %} |
| 92 | + CHECK(3 == *it_with_id); |
| 93 | + |
| 94 | + CHECK(it == it_with_id); |
| 95 | +{% endif %} |
54 | 96 | #endif |
55 | 97 | } |
0 commit comments