Skip to content

Commit

Permalink
Fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvenkatasai committed Jan 14, 2025
1 parent 8147f00 commit 2fe179a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
32 changes: 18 additions & 14 deletions dynamic/dicethrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,35 @@ import (
)

type testCaseDiceThrow struct {
m, n, sum int
numDice int
numFaces int
targetSum int
expected int
}

// getDiceThrowTestCases provides the test cases for DiceThrow
func getDiceThrowTestCases() []testCaseDiceThrow {
return []testCaseDiceThrow{
{2, 6, 7, 6}, // Two dice, six faces each, sum = 7
{1, 6, 3, 1}, // One die, six faces, sum = 3
{3, 4, 5, 6}, // Three dice, four faces each, sum = 5
{1, 6, 1, 1}, // One die, six faces, sum = 1
{2, 6, 12, 1}, // Two dice, six faces each, sum = 12
{3, 6, 18, 1}, // Three dice, six faces each, sum = 18
{2, 6, 20, 0}, // Two dice, six faces each, sum = 20 (impossible)
{1, 1, 1, 1}, // One die, one face, sum = 1
{1, 1, 2, 0}, // One die, one face, sum = 2 (impossible)
{2, 1, 2, 1}, // Two dice, one face each, sum = 2
{2, 6, 7, 6}, // Two dice, six faces each, sum = 7
{1, 6, 3, 1}, // One die, six faces, sum = 3
{3, 4, 5, 6}, // Three dice, four faces each, sum = 5
{1, 6, 1, 1}, // One die, six faces, sum = 1
{2, 6, 12, 1}, // Two dice, six faces each, sum = 12
{3, 6, 18, 1}, // Three dice, six faces each, sum = 18
{2, 6, 20, 0}, // Two dice, six faces each, sum = 20 (impossible)
{1, 1, 1, 1}, // One die, one face, sum = 1
{1, 1, 2, 0}, // One die, one face, sum = 2 (impossible)
{2, 1, 2, 1}, // Two dice, one face each, sum = 2
}
}

func TestDiceThrow(t *testing.T) {
// TestDiceThrow tests the DiceThrow function with basic test cases
func TestDiceThrow_BasicCases(t *testing.T) {

Check failure on line 33 in dynamic/dicethrow_test.go

View workflow job for this annotation

GitHub Actions / Code style and tests

The declaration of the function TestDiceThrow_BasicCases is not following our style guide. Please read our contribution guidelines and style guides to help you resolve this issue.
t.Run("Basic test cases", func(t *testing.T) {
for _, tc := range getDiceThrowTestCases() {
actual := dynamic.DiceThrow(tc.m, tc.n, tc.sum)
actual := dynamic.DiceThrow(tc.numDice, tc.numFaces, tc.targetSum)
if actual != tc.expected {
t.Errorf("DiceThrow(%d, %d, %d) = %d; expected %d", tc.m, tc.n, tc.sum, actual, tc.expected)
t.Errorf("DiceThrow(%d, %d, %d) = %d; expected %d", tc.numDice, tc.numFaces, tc.targetSum, actual, tc.expected)
}
}
})
Expand Down
19 changes: 11 additions & 8 deletions dynamic/partitionproblem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ import (
"github.com/TheAlgorithms/Go/dynamic"
)

// testCasePartitionProblem holds the test cases for the Partition Problem
type testCasePartitionProblem struct {
nums []int
expected bool
}

// getPartitionProblemTestCases returns a list of test cases for the Partition Problem
func getPartitionProblemTestCases() []testCasePartitionProblem {
return []testCasePartitionProblem{
{[]int{1, 5, 11, 5}, true}, // Example with a partitionable set
{[]int{1, 2, 3, 5}, false}, // Example where partition is not possible
{[]int{1, 2, 5}, false}, // Set cannot be partitioned into two subsets
{[]int{2, 2, 2, 2}, true}, // Even split possible with equal elements
{[]int{7, 3, 2, 1}, false}, // Set cannot be partitioned
{[]int{}, true}, // Empty set, can be partitioned trivially
{[]int{1}, false}, // Single element, cannot be partitioned
{[]int{10, 10, 10, 10}, true}, // Equal elements, partitionable
{[]int{1, 5, 11, 5}, true}, // Example with a partitionable set
{[]int{1, 2, 3, 5}, false}, // Example where partition is not possible
{[]int{1, 2, 5}, false}, // Set cannot be partitioned into two subsets
{[]int{2, 2, 2, 2}, true}, // Even split possible with equal elements
{[]int{7, 3, 2, 1}, false}, // Set cannot be partitioned
{[]int{}, true}, // Empty set, can be partitioned trivially
{[]int{1}, false}, // Single element, cannot be partitioned
{[]int{10, 10, 10, 10}, true}, // Equal elements, partitionable
}
}

// TestPartitionProblem tests the PartitionProblem function with different test cases
func TestPartitionProblem(t *testing.T) {
t.Run("Partition Problem test cases", func(t *testing.T) {
for _, tc := range getPartitionProblemTestCases() {
Expand Down
27 changes: 15 additions & 12 deletions dynamic/wildcardmatching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,32 @@ import (
"github.com/TheAlgorithms/Go/dynamic"
)

// testCaseWildcardMatching holds the test cases for the Wildcard Matching problem
type testCaseWildcardMatching struct {
s string
p string
expected bool
}

// getWildcardMatchingTestCases returns a list of test cases for the Wildcard Matching problem
func getWildcardMatchingTestCases() []testCaseWildcardMatching {
return []testCaseWildcardMatching{
{"aa", "a*", true}, // * can match zero or more characters
{"aa", "a", false}, // No match due to no wildcard
{"ab", "?*", true}, // ? matches any single character, * matches remaining
{"abcd", "a*d", true}, // * matches the characters between 'a' and 'd'
{"abcd", "a*c", false}, // No match as 'c' doesn't match the last character 'd'
{"abc", "*", true}, // * matches the entire string
{"abc", "a*c", true}, // * matches 'b'
{"abc", "a?c", true}, // ? matches 'b'
{"abc", "a?d", false}, // ? cannot match 'd'
{"", "", true}, // Both strings empty, so they match
{"a", "?", true}, // ? matches any single character
{"a", "*", true}, // * matches any number of characters, including one
{"aa", "a*", true}, // '*' can match zero or more characters
{"aa", "a", false}, // No match due to no wildcard
{"ab", "?*", true}, // '?' matches any single character, '*' matches remaining
{"abcd", "a*d", true}, // '*' matches the characters between 'a' and 'd'
{"abcd", "a*c", false}, // No match as 'c' doesn't match the last character 'd'
{"abc", "*", true}, // '*' matches the entire string
{"abc", "a*c", true}, // '*' matches 'b'
{"abc", "a?c", true}, // '?' matches 'b'
{"abc", "a?d", false}, // '?' cannot match 'd'
{"", "", true}, // Both strings empty, so they match
{"a", "?", true}, // '?' matches any single character
{"a", "*", true}, // '*' matches any number of characters, including one
}
}

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

0 comments on commit 2fe179a

Please sign in to comment.