@@ -7,31 +7,35 @@ import (
77)
88
99type testCaseDiceThrow struct {
10- m , n , sum int
10+ numDice int
11+ numFaces int
12+ targetSum int
1113 expected int
1214}
1315
16+ // getDiceThrowTestCases provides the test cases for DiceThrow
1417func getDiceThrowTestCases () []testCaseDiceThrow {
1518 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
2629 }
2730}
2831
29- func TestDiceThrow (t * testing.T ) {
32+ // TestDiceThrow tests the DiceThrow function with basic test cases
33+ func TestDiceThrow_BasicCases (t * testing.T ) {
3034 t .Run ("Basic test cases" , func (t * testing.T ) {
3135 for _ , tc := range getDiceThrowTestCases () {
32- actual := dynamic .DiceThrow (tc .m , tc .n , tc .sum )
36+ actual := dynamic .DiceThrow (tc .numDice , tc .numFaces , tc .targetSum )
3337 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 )
3539 }
3640 }
3741 })
0 commit comments