|
| 1 | +package dynamic_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/TheAlgorithms/Go/dynamic" |
| 7 | +) |
| 8 | + |
| 9 | +type testCaseDiceThrow struct { |
| 10 | + numDice int |
| 11 | + numFaces int |
| 12 | + targetSum int |
| 13 | + expected int |
| 14 | +} |
| 15 | + |
| 16 | +// getDiceThrowTestCases provides the test cases for DiceThrow |
| 17 | +func getDiceThrowTestCases() []testCaseDiceThrow { |
| 18 | + return []testCaseDiceThrow{ |
| 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 |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +// TestDiceThrow tests the DiceThrow function with basic test cases |
| 33 | +func TestDiceThrow(t *testing.T) { |
| 34 | + t.Run("Basic test cases", func(t *testing.T) { |
| 35 | + for _, tc := range getDiceThrowTestCases() { |
| 36 | + actual := dynamic.DiceThrow(tc.numDice, tc.numFaces, tc.targetSum) |
| 37 | + if actual != tc.expected { |
| 38 | + t.Errorf("DiceThrow(%d, %d, %d) = %d; expected %d", tc.numDice, tc.numFaces, tc.targetSum, actual, tc.expected) |
| 39 | + } |
| 40 | + } |
| 41 | + }) |
| 42 | +} |
0 commit comments