|
5 | 5 | #include "test/catch.hpp"
|
6 | 6 | #endif
|
7 | 7 |
|
| 8 | +#include <sstream> |
| 9 | + |
| 10 | +template <typename T> |
| 11 | +class IsBetweenMatcher : public Catch::MatcherBase<T> { |
| 12 | + T m_begin, m_end; |
| 13 | +public: |
| 14 | + IsBetweenMatcher(T begin, T end) : |
| 15 | + m_begin(begin), m_end(end) { |
| 16 | + } |
| 17 | + bool match(T const& in) const override { |
| 18 | + return in >= m_begin && in <= m_end; |
| 19 | + } |
| 20 | + std::string describe() const override { |
| 21 | + std::ostringstream ss; |
| 22 | + ss << "should be between " << m_begin << " and " << m_end; |
| 23 | + return ss.str(); |
| 24 | + } |
| 25 | +}; |
| 26 | + |
8 | 27 | TEST_CASE("ability modifier for score 3 is -4", "[1e9ae1dc-35bd-43ba-aa08-e4b94c20fa37]") {
|
9 | 28 | REQUIRE(-4 == dnd_character::modifier(3));
|
10 | 29 | }
|
@@ -73,29 +92,18 @@ TEST_CASE("ability modifier for score 18 is +4", "[bafd997a-e852-4e56-9f65-14b60
|
73 | 92 |
|
74 | 93 | TEST_CASE("random ability is within range", "[4f28f19c-2e47-4453-a46a-c0d365259c14]") {
|
75 | 94 | int result{dnd_character::ability()};
|
76 |
| - //REQUIRE("score >= 3 && score <= 18" == dnd_character::ability()); |
77 |
| - REQUIRE((result >= 3 && result <= 18)); |
| 95 | + CHECK_THAT(result, IsBetweenMatcher(3, 18)); |
78 | 96 | }
|
79 | 97 |
|
80 | 98 | TEST_CASE("random character is valid", "[385d7e72-864f-4e88-8279-81a7d75b04ad]") {
|
81 | 99 | dnd_character::Character character;
|
82 |
| - REQUIRE((character.strength >= 3 && character.strength <= 18)); |
83 |
| - REQUIRE((character.dexterity >= 3 && character.dexterity <= 18)); |
84 |
| - REQUIRE((character.constitution >= 3 && character.constitution <= 18)); |
85 |
| - REQUIRE((character.intelligence >= 3 && character.intelligence <= 18)); |
86 |
| - REQUIRE((character.wisdom >= 3 && character.wisdom <= 18)); |
87 |
| - REQUIRE((character.charisma >= 3 && character.charisma <= 18)); |
| 100 | + CHECK_THAT(character.strength, IsBetweenMatcher(3, 18)); |
| 101 | + CHECK_THAT(character.dexterity, IsBetweenMatcher(3, 18)); |
| 102 | + CHECK_THAT(character.constitution, IsBetweenMatcher(3, 18)); |
| 103 | + CHECK_THAT(character.intelligence, IsBetweenMatcher(3, 18)); |
| 104 | + CHECK_THAT(character.wisdom, IsBetweenMatcher(3, 18)); |
| 105 | + CHECK_THAT(character.charisma, IsBetweenMatcher(3, 18)); |
88 | 106 | REQUIRE(character.hitpoints == 10 + dnd_character::modifier(character.constitution));
|
89 | 107 | }
|
90 | 108 |
|
91 |
| -TEST_CASE("each ability is only calculated once", "[dca2b2ec-f729-4551-84b9-078876bb4808]") { |
92 |
| - dnd_character::Character character; |
93 |
| - REQUIRE(character.strength == character.strength); |
94 |
| - REQUIRE(character.dexterity == character.dexterity); |
95 |
| - REQUIRE(character.constitution == character.constitution); |
96 |
| - REQUIRE(character.intelligence == character.intelligence); |
97 |
| - REQUIRE(character.wisdom == character.wisdom); |
98 |
| - REQUIRE(character.charisma == character.charisma); |
99 |
| -} |
100 |
| - |
101 | 109 | #endif
|
0 commit comments