-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter_tests.cpp
More file actions
123 lines (107 loc) · 4.19 KB
/
Copy pathcharacter_tests.cpp
File metadata and controls
123 lines (107 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <gtest/gtest.h>
#include "character.h"
#include "diceroller.h"
TEST(Character, NoToughnessNoArmorKillingBlow)
{
constexpr const auto health = 5;
Character c(false, "dummy", 0, 0, 0, 0, 0, 0, health, 0 ,0 ,0, false);
EXPECT_TRUE(c.isAlive());
c.hit(health);
EXPECT_FALSE(c.isAlive());
}
TEST(Character, ArmorPreventsKillingBlow)
{
constexpr const auto health = 5;
constexpr const auto armor = 1;
Character c(false, "dummy", 0, 0, 0, 0, 0, 0, health, 0 ,0 , armor, false);
EXPECT_TRUE(c.isAlive());
c.hit(health);
EXPECT_TRUE(c.isAlive());
EXPECT_EQ(c.health(), armor);
c.hit(2*armor);
EXPECT_FALSE(c.isAlive());
}
TEST(Character, ToughnessPreventsKillingBlow)
{
constexpr const auto health = 5;
constexpr const auto toughness = 38;
Character c(false, "dummy", 0, 0, 0, toughness, 0, 0, health, 0 ,0 , 0, false);
EXPECT_TRUE(c.isAlive());
c.hit(health);
EXPECT_TRUE(c.isAlive());
EXPECT_EQ(c.health(), toughness / 10);
c.hit(2*(toughness / 10));
EXPECT_FALSE(c.isAlive());
EXPECT_EQ(c.health(), 0);
}
TEST(Character, HitRoll)
{
constexpr const auto health = 6;
Character dummy(false, "dummy", 0, 0, 0, 0, 0, 0, health, 0 ,0 , 0, false);
EXPECT_TRUE(dummy.isAlive());
constexpr const auto ws = 50;
constexpr const auto str = 20; // with dmg roll 2 hits to kill
constexpr const auto attacks = 1;
Character trainee(true, "trainee", ws, 0, str, 0, 0, attacks, health, 0, 0, 0, false);
EXPECT_EQ(trainee.currentAttackingWeapon(), Character::AttackingWeapon::Melee);
EXPECT_EQ(trainee.remainingActions(), 2);
trainee.target = &dummy;
PredeterminedDiceRoller roller({30 /* hit */, 100 /* parry */, 1 /* dmg */});
EXPECT_TRUE(trainee.attack(roller));
EXPECT_EQ(trainee.remainingActions(), 1);
EXPECT_TRUE(dummy.isAlive());
EXPECT_EQ(dummy.health(), health - (str / 10) - 1);
EXPECT_FALSE(trainee.attack(roller)); // 1 attack per turn
EXPECT_EQ(trainee.remainingActions(), 1);
dummy.newTurn();
trainee.newTurn();
EXPECT_TRUE(trainee.attack(roller));
EXPECT_EQ(trainee.remainingActions(), 1);
EXPECT_FALSE(dummy.isAlive());
EXPECT_EQ(dummy.health(), 0);
}
TEST(Character, MultipleAttacks)
{
constexpr const auto health = 6;
Character dummy(false, "dummy", 0, 0, 0, 0, 0, 0, health, 0 ,0 , 0, false);
EXPECT_TRUE(dummy.isAlive());
constexpr const auto ws = 50;
constexpr const auto str = 20; // with dmg roll 2 hits to kill
constexpr const auto attacks = 2;
Character trainee(true, "trainee", ws, 0, str, 0, 0, attacks, health, 0, 0, 0, false);
EXPECT_EQ(trainee.currentAttackingWeapon(), Character::AttackingWeapon::Melee);
EXPECT_EQ(trainee.remainingActions(), 2);
trainee.target = &dummy;
PredeterminedDiceRoller roller({30 /* hit */, 100 /* parry */, 1 /* dmg */, 30 /* another hit */, 1 /* dmg */});
EXPECT_TRUE(trainee.attack(roller));
EXPECT_FALSE(dummy.isAlive());
EXPECT_EQ(dummy.health(), 0);
EXPECT_EQ(trainee.remainingActions(), 0);
}
TEST(Character, CannotParryTwice)
{
constexpr const auto health = 6;
Character dummy(false, "dummy", 0, 0, 0, 0, 0, 0, health, 0 ,0 , 0, false);
EXPECT_TRUE(dummy.isAlive());
EXPECT_TRUE(dummy.canParry());
constexpr const auto ws = 50;
constexpr const auto str = 20; // with dmg roll 2 hits to kill
constexpr const auto attacks = 1;
Character trainee(true, "trainee", ws, 0, str, 0, 0, attacks, health, 0, 0, 0, false);
EXPECT_EQ(trainee.currentAttackingWeapon(), Character::AttackingWeapon::Melee);
EXPECT_EQ(trainee.remainingActions(), 2);
trainee.target = &dummy;
PredeterminedDiceRoller roller({30 /* hit */, 100 /* parry */, 1 /* dmg */, 30 /* hit */, 1 /* dmg */});
EXPECT_TRUE(trainee.attack(roller));
EXPECT_EQ(trainee.remainingActions(), 1);
EXPECT_TRUE(dummy.isAlive());
EXPECT_FALSE(dummy.canParry());
EXPECT_EQ(dummy.health(), health - (str / 10) - 1);
// no new turn for dummy
trainee.newTurn();
EXPECT_TRUE(trainee.attack(roller));
EXPECT_EQ(trainee.remainingActions(), 1);
EXPECT_FALSE(dummy.isAlive());
EXPECT_FALSE(dummy.canParry());
EXPECT_EQ(dummy.health(), 0);
}