Skip to content

Commit 2fe179a

Browse files
Fix linters
1 parent 8147f00 commit 2fe179a

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

dynamic/dicethrow_test.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,35 @@ import (
77
)
88

99
type 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
1417
func 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
})

dynamic/partitionproblem_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,27 @@ import (
66
"github.com/TheAlgorithms/Go/dynamic"
77
)
88

9+
// testCasePartitionProblem holds the test cases for the Partition Problem
910
type testCasePartitionProblem struct {
1011
nums []int
1112
expected bool
1213
}
1314

15+
// getPartitionProblemTestCases returns a list of test cases for the Partition Problem
1416
func getPartitionProblemTestCases() []testCasePartitionProblem {
1517
return []testCasePartitionProblem{
16-
{[]int{1, 5, 11, 5}, true}, // Example with a partitionable set
17-
{[]int{1, 2, 3, 5}, false}, // Example where partition is not possible
18-
{[]int{1, 2, 5}, false}, // Set cannot be partitioned into two subsets
19-
{[]int{2, 2, 2, 2}, true}, // Even split possible with equal elements
20-
{[]int{7, 3, 2, 1}, false}, // Set cannot be partitioned
21-
{[]int{}, true}, // Empty set, can be partitioned trivially
22-
{[]int{1}, false}, // Single element, cannot be partitioned
23-
{[]int{10, 10, 10, 10}, true}, // Equal elements, partitionable
18+
{[]int{1, 5, 11, 5}, true}, // Example with a partitionable set
19+
{[]int{1, 2, 3, 5}, false}, // Example where partition is not possible
20+
{[]int{1, 2, 5}, false}, // Set cannot be partitioned into two subsets
21+
{[]int{2, 2, 2, 2}, true}, // Even split possible with equal elements
22+
{[]int{7, 3, 2, 1}, false}, // Set cannot be partitioned
23+
{[]int{}, true}, // Empty set, can be partitioned trivially
24+
{[]int{1}, false}, // Single element, cannot be partitioned
25+
{[]int{10, 10, 10, 10}, true}, // Equal elements, partitionable
2426
}
2527
}
2628

29+
// TestPartitionProblem tests the PartitionProblem function with different test cases
2730
func TestPartitionProblem(t *testing.T) {
2831
t.Run("Partition Problem test cases", func(t *testing.T) {
2932
for _, tc := range getPartitionProblemTestCases() {

dynamic/wildcardmatching_test.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,32 @@ import (
66
"github.com/TheAlgorithms/Go/dynamic"
77
)
88

9+
// testCaseWildcardMatching holds the test cases for the Wildcard Matching problem
910
type testCaseWildcardMatching struct {
1011
s string
1112
p string
1213
expected bool
1314
}
1415

16+
// getWildcardMatchingTestCases returns a list of test cases for the Wildcard Matching problem
1517
func getWildcardMatchingTestCases() []testCaseWildcardMatching {
1618
return []testCaseWildcardMatching{
17-
{"aa", "a*", true}, // * can match zero or more characters
18-
{"aa", "a", false}, // No match due to no wildcard
19-
{"ab", "?*", true}, // ? matches any single character, * matches remaining
20-
{"abcd", "a*d", true}, // * matches the characters between 'a' and 'd'
21-
{"abcd", "a*c", false}, // No match as 'c' doesn't match the last character 'd'
22-
{"abc", "*", true}, // * matches the entire string
23-
{"abc", "a*c", true}, // * matches 'b'
24-
{"abc", "a?c", true}, // ? matches 'b'
25-
{"abc", "a?d", false}, // ? cannot match 'd'
26-
{"", "", true}, // Both strings empty, so they match
27-
{"a", "?", true}, // ? matches any single character
28-
{"a", "*", true}, // * matches any number of characters, including one
19+
{"aa", "a*", true}, // '*' can match zero or more characters
20+
{"aa", "a", false}, // No match due to no wildcard
21+
{"ab", "?*", true}, // '?' matches any single character, '*' matches remaining
22+
{"abcd", "a*d", true}, // '*' matches the characters between 'a' and 'd'
23+
{"abcd", "a*c", false}, // No match as 'c' doesn't match the last character 'd'
24+
{"abc", "*", true}, // '*' matches the entire string
25+
{"abc", "a*c", true}, // '*' matches 'b'
26+
{"abc", "a?c", true}, // '?' matches 'b'
27+
{"abc", "a?d", false}, // '?' cannot match 'd'
28+
{"", "", true}, // Both strings empty, so they match
29+
{"a", "?", true}, // '?' matches any single character
30+
{"a", "*", true}, // '*' matches any number of characters, including one
2931
}
3032
}
3133

34+
// TestIsMatch tests the IsMatch function with various test cases
3235
func TestIsMatch(t *testing.T) {
3336
t.Run("Wildcard Matching test cases", func(t *testing.T) {
3437
for _, tc := range getWildcardMatchingTestCases() {

0 commit comments

Comments
 (0)