-
-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathDndCharacterTests.cs
176 lines (154 loc) · 5.43 KB
/
DndCharacterTests.cs
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
public class DndCharacterTests
{
[Fact]
public void Ability_modifier_for_score_3_is_4()
{
Assert.Equal(-4, DndCharacter.Modifier(3));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_4_is_3()
{
Assert.Equal(-3, DndCharacter.Modifier(4));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_5_is_3()
{
Assert.Equal(-3, DndCharacter.Modifier(5));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_6_is_2()
{
Assert.Equal(-2, DndCharacter.Modifier(6));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_7_is_2()
{
Assert.Equal(-2, DndCharacter.Modifier(7));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_8_is_1()
{
Assert.Equal(-1, DndCharacter.Modifier(8));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_9_is_1()
{
Assert.Equal(-1, DndCharacter.Modifier(9));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_10_is_0()
{
Assert.Equal(0, DndCharacter.Modifier(10));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_11_is_0()
{
Assert.Equal(0, DndCharacter.Modifier(11));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_12_is_1()
{
Assert.Equal(1, DndCharacter.Modifier(12));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_13_is_1()
{
Assert.Equal(1, DndCharacter.Modifier(13));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_14_is_2()
{
Assert.Equal(2, DndCharacter.Modifier(14));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_15_is_2()
{
Assert.Equal(2, DndCharacter.Modifier(15));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_16_is_3()
{
Assert.Equal(3, DndCharacter.Modifier(16));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_17_is_3()
{
Assert.Equal(3, DndCharacter.Modifier(17));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Ability_modifier_for_score_18_is_4()
{
Assert.Equal(4, DndCharacter.Modifier(18));
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Random_ability_is_within_range()
{
for (var i = 0; i < 10; i++)
{
Assert.InRange(DndCharacter.Ability(), 3, 18);
}
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Random_character_is_valid()
{
for (var i = 0; i < 10; i++)
{
var sut = DndCharacter.Generate();
Assert.InRange(sut.Strength, 3, 18);
Assert.InRange(sut.Dexterity, 3, 18);
Assert.InRange(sut.Constitution, 3, 18);
Assert.InRange(sut.Intelligence, 3, 18);
Assert.InRange(sut.Wisdom, 3, 18);
Assert.InRange(sut.Charisma, 3, 18);
Assert.Equal(sut.Hitpoints, 10 + DndCharacter.Modifier(sut.Constitution));
}
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Each_ability_is_only_calculated_once()
{
for (var i = 0; i < 10; i++)
{
var sut = DndCharacter.Generate();
Assert.Equal(sut.Strength, sut.Strength);
Assert.Equal(sut.Dexterity, sut.Dexterity);
Assert.Equal(sut.Constitution, sut.Constitution);
Assert.Equal(sut.Intelligence, sut.Intelligence);
Assert.Equal(sut.Wisdom, sut.Wisdom);
Assert.Equal(sut.Charisma, sut.Charisma);
}
}
[Fact(Skip = "Remove this Skip property to run this test")]
public void Random_ability_is_distributed_correctly()
{
var expectedDistribution = new Dictionary<int, int>
{
[3] = 1,
[4] = 4,
[5] = 10,
[6] = 21,
[7] = 38,
[8] = 62,
[9] = 91,
[10] = 122,
[11] = 148,
[12] = 167,
[13] = 172,
[14] = 160,
[15] = 131,
[16] = 94,
[17] = 54,
[18] = 21
};
var actualDistribution = new Dictionary<int, int>(expectedDistribution);
foreach (var key in actualDistribution.Keys)
actualDistribution[key] = 0;
const int times = 250;
const int possibleCombinationsCount = 6 * 6 * 6 * 6; // 4d6
for (var i = 0; i < times * possibleCombinationsCount; i++)
actualDistribution[DndCharacter.Ability()]++;
const double minTimes = times * 0.8;
const double maxTimes = times * 1.2;
foreach (var k in expectedDistribution.Keys)
Assert.InRange(actualDistribution[k], expectedDistribution[k] * minTimes, expectedDistribution[k] * maxTimes);
}
}