@@ -7,31 +7,35 @@ import (
7
7
)
8
8
9
9
type testCaseDiceThrow struct {
10
- m , n , sum int
10
+ numDice int
11
+ numFaces int
12
+ targetSum int
11
13
expected int
12
14
}
13
15
16
+ // getDiceThrowTestCases provides the test cases for DiceThrow
14
17
func getDiceThrowTestCases () []testCaseDiceThrow {
15
18
return []testCaseDiceThrow {
16
- {2 , 6 , 7 , 6 }, // Two dice, six faces each, sum = 7
17
- {1 , 6 , 3 , 1 }, // One die, six faces, sum = 3
18
- {3 , 4 , 5 , 6 }, // Three dice, four faces each, sum = 5
19
- {1 , 6 , 1 , 1 }, // One die, six faces, sum = 1
20
- {2 , 6 , 12 , 1 }, // Two dice, six faces each, sum = 12
21
- {3 , 6 , 18 , 1 }, // Three dice, six faces each, sum = 18
22
- {2 , 6 , 20 , 0 }, // Two dice, six faces each, sum = 20 (impossible)
23
- {1 , 1 , 1 , 1 }, // One die, one face, sum = 1
24
- {1 , 1 , 2 , 0 }, // One die, one face, sum = 2 (impossible)
25
- {2 , 1 , 2 , 1 }, // Two dice, one face each, sum = 2
19
+ {2 , 6 , 7 , 6 }, // Two dice, six faces each, sum = 7
20
+ {1 , 6 , 3 , 1 }, // One die, six faces, sum = 3
21
+ {3 , 4 , 5 , 6 }, // Three dice, four faces each, sum = 5
22
+ {1 , 6 , 1 , 1 }, // One die, six faces, sum = 1
23
+ {2 , 6 , 12 , 1 }, // Two dice, six faces each, sum = 12
24
+ {3 , 6 , 18 , 1 }, // Three dice, six faces each, sum = 18
25
+ {2 , 6 , 20 , 0 }, // Two dice, six faces each, sum = 20 (impossible)
26
+ {1 , 1 , 1 , 1 }, // One die, one face, sum = 1
27
+ {1 , 1 , 2 , 0 }, // One die, one face, sum = 2 (impossible)
28
+ {2 , 1 , 2 , 1 }, // Two dice, one face each, sum = 2
26
29
}
27
30
}
28
31
29
- func TestDiceThrow (t * testing.T ) {
32
+ // TestDiceThrow tests the DiceThrow function with basic test cases
33
+ func TestDiceThrow_BasicCases (t * testing.T ) {
30
34
t .Run ("Basic test cases" , func (t * testing.T ) {
31
35
for _ , tc := range getDiceThrowTestCases () {
32
- actual := dynamic .DiceThrow (tc .m , tc .n , tc .sum )
36
+ actual := dynamic .DiceThrow (tc .numDice , tc .numFaces , tc .targetSum )
33
37
if actual != tc .expected {
34
- t .Errorf ("DiceThrow(%d, %d, %d) = %d; expected %d" , tc .m , tc .n , tc .sum , actual , tc .expected )
38
+ t .Errorf ("DiceThrow(%d, %d, %d) = %d; expected %d" , tc .numDice , tc .numFaces , tc .targetSum , actual , tc .expected )
35
39
}
36
40
}
37
41
})
0 commit comments