Skip to content

Commit ec00fec

Browse files
authored
Relax distribution test for dnd-character (#533)
* Relax distribution test for `dnd-character` * Add parameter name
1 parent f09d55c commit ec00fec

1 file changed

Lines changed: 4 additions & 34 deletions

File tree

exercises/practice/dnd-character/DndCharacterTests.vb

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -115,40 +115,10 @@ Public Class DndCharacterTests
115115

116116
<Fact(Skip:="Remove this Skip property to run this test")>
117117
Public Sub Random_ability_is_distributed_correctly()
118-
Dim expectedDistribution = New Dictionary(Of Integer, Integer) From {
119-
{3, 1},
120-
{4, 4},
121-
{5, 10},
122-
{6, 21},
123-
{7, 38},
124-
{8, 62},
125-
{9, 91},
126-
{10, 122},
127-
{11, 148},
128-
{12, 167},
129-
{13, 172},
130-
{14, 160},
131-
{15, 131},
132-
{16, 94},
133-
{17, 54},
134-
{18, 21}
135-
}
136-
137-
Dim actualDistribution = New Dictionary(Of Integer, Integer)(expectedDistribution)
138-
For Each key In actualDistribution.Keys
139-
actualDistribution(key) = 0
140-
Next
141-
142-
Const times = 250
143-
Const possibleCombinationsCount = 6 * 6 * 6 * 6 ' 4d6
144-
For i = 0 To times * possibleCombinationsCount - 1
145-
actualDistribution(DndCharacter.Ability()) += 1
146-
Next
118+
Dim abilities = Enumerable.Range(1, 10000).Select(Function(roll) DndCharacter.Ability()).ToArray()
119+
Assert.All(abilities, Sub(ability) Assert.InRange(ability, 3, 18))
147120

148-
Const minTimes = times * 0.8
149-
Const maxTimes = times * 1.2
150-
For Each k In expectedDistribution.Keys
151-
Assert.InRange(actualDistribution(k), expectedDistribution(k) * minTimes, expectedDistribution(k) * maxTimes)
152-
Next
121+
Dim average = abilities.Average() ' 4d6, drop lowest expected average is approximately 12.24
122+
Assert.InRange(average, 11.84, 12.64)
153123
End Sub
154124
End Class

0 commit comments

Comments
 (0)