Skip to content

Commit

Permalink
fix: resolved code smells (#258)
Browse files Browse the repository at this point in the history
Made the project to smell good

Co-authored-by: aelumalai <aelumalai@paypal.com>
  • Loading branch information
anandrajelu and aelumalai committed Oct 31, 2022
1 parent 4689f3a commit 27d8810
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
10 changes: 5 additions & 5 deletions channel_test.go
Expand Up @@ -114,19 +114,19 @@ func TestDispatchingStrategyRoundRobin(t *testing.T) {
func TestDispatchingStrategyRandom(t *testing.T) {
testWithTimeout(t, 10*time.Millisecond)
is := assert.New(t)

// with this seed, the order of random channels are: 1 - 0
rand.Seed(14)

children := createChannels[int](2, 2)
rochildren := channelsToReadOnly(children)
defer closeChannels(children)

for i := 0; i < 2; i++ {
children[1] <- i
}
is.Equal(0, DispatchingStrategyRandom[int](42, 0, rochildren))

is.Equal(0, DispatchingStrategyRandom(42, 0, rochildren))
}

func TestDispatchingStrategyWeightedRandom(t *testing.T) {
Expand Down
32 changes: 16 additions & 16 deletions find_test.go
Expand Up @@ -118,11 +118,11 @@ func TestFindKey(t *testing.T) {
foobar string
}

result3, ok3 := FindKey(map[string]test{"foo": test{"foo"}, "bar": test{"bar"}, "baz": test{"baz"}}, test{"foo"})
result3, ok3 := FindKey(map[string]test{"foo": {"foo"}, "bar": {"bar"}, "baz": {"baz"}}, test{"foo"})
is.Equal("foo", result3)
is.True(ok3)

result4, ok4 := FindKey(map[string]test{"foo": test{"foo"}, "bar": test{"bar"}, "baz": test{"baz"}}, test{"hello world"})
result4, ok4 := FindKey(map[string]test{"foo": {"foo"}, "bar": {"bar"}, "baz": {"baz"}}, test{"hello world"})
is.Equal("", result4)
is.False(ok4)
}
Expand All @@ -148,22 +148,22 @@ func TestFindUniques(t *testing.T) {
t.Parallel()
is := assert.New(t)

result1 := FindUniques[int]([]int{1, 2, 3})
result1 := FindUniques([]int{1, 2, 3})

is.Equal(3, len(result1))
is.Equal([]int{1, 2, 3}, result1)

result2 := FindUniques[int]([]int{1, 2, 2, 3, 1, 2})
result2 := FindUniques([]int{1, 2, 2, 3, 1, 2})

is.Equal(1, len(result2))
is.Equal([]int{3}, result2)

result3 := FindUniques[int]([]int{1, 2, 2, 1})
result3 := FindUniques([]int{1, 2, 2, 1})

is.Equal(0, len(result3))
is.Equal([]int{}, result3)

result4 := FindUniques[int]([]int{})
result4 := FindUniques([]int{})

is.Equal(0, len(result4))
is.Equal([]int{}, result4)
Expand All @@ -173,28 +173,28 @@ func TestFindUniquesBy(t *testing.T) {
t.Parallel()
is := assert.New(t)

result1 := FindUniquesBy[int, int]([]int{0, 1, 2}, func(i int) int {
result1 := FindUniquesBy([]int{0, 1, 2}, func(i int) int {
return i % 3
})

is.Equal(3, len(result1))
is.Equal([]int{0, 1, 2}, result1)

result2 := FindUniquesBy[int, int]([]int{0, 1, 2, 3, 4}, func(i int) int {
result2 := FindUniquesBy([]int{0, 1, 2, 3, 4}, func(i int) int {
return i % 3
})

is.Equal(1, len(result2))
is.Equal([]int{2}, result2)

result3 := FindUniquesBy[int, int]([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
result3 := FindUniquesBy([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
return i % 3
})

is.Equal(0, len(result3))
is.Equal([]int{}, result3)

result4 := FindUniquesBy[int, int]([]int{}, func(i int) int {
result4 := FindUniquesBy([]int{}, func(i int) int {
return i % 3
})

Expand All @@ -206,17 +206,17 @@ func TestFindDuplicates(t *testing.T) {
t.Parallel()
is := assert.New(t)

result1 := FindDuplicates[int]([]int{1, 2, 2, 1, 2, 3})
result1 := FindDuplicates([]int{1, 2, 2, 1, 2, 3})

is.Equal(2, len(result1))
is.Equal([]int{1, 2}, result1)

result2 := FindDuplicates[int]([]int{1, 2, 3})
result2 := FindDuplicates([]int{1, 2, 3})

is.Equal(0, len(result2))
is.Equal([]int{}, result2)

result3 := FindDuplicates[int]([]int{})
result3 := FindDuplicates([]int{})

is.Equal(0, len(result3))
is.Equal([]int{}, result3)
Expand All @@ -226,21 +226,21 @@ func TestFindDuplicatesBy(t *testing.T) {
t.Parallel()
is := assert.New(t)

result1 := FindDuplicatesBy[int, int]([]int{3, 4, 5, 6, 7}, func(i int) int {
result1 := FindDuplicatesBy([]int{3, 4, 5, 6, 7}, func(i int) int {
return i % 3
})

is.Equal(2, len(result1))
is.Equal([]int{3, 4}, result1)

result2 := FindDuplicatesBy[int, int]([]int{0, 1, 2, 3, 4}, func(i int) int {
result2 := FindDuplicatesBy([]int{0, 1, 2, 3, 4}, func(i int) int {
return i % 5
})

is.Equal(0, len(result2))
is.Equal([]int{}, result2)

result3 := FindDuplicatesBy[int, int]([]int{}, func(i int) int {
result3 := FindDuplicatesBy([]int{}, func(i int) int {
return i % 3
})

Expand Down
10 changes: 5 additions & 5 deletions slice_example_test.go
Expand Up @@ -210,23 +210,23 @@ func ExampleReverse() {
}

func ExampleFill() {
list := []foo{foo{"a"}, foo{"a"}}
list := []foo{{"a"}, {"a"}}

result := Fill[foo](list, foo{"b"})
result := Fill(list, foo{"b"})

fmt.Printf("%v", result)
// Output: [{b} {b}]
}

func ExampleRepeat() {
result := Repeat[foo](2, foo{"a"})
result := Repeat(2, foo{"a"})

fmt.Printf("%v", result)
// Output: [{a} {a}]
}

func ExampleRepeatBy() {
result := RepeatBy[string](5, func(i int) string {
result := RepeatBy(5, func(i int) string {
return strconv.FormatInt(int64(math.Pow(float64(i), 2)), 10)
})

Expand All @@ -237,7 +237,7 @@ func ExampleRepeatBy() {
func ExampleKeyBy() {
list := []string{"a", "aa", "aaa"}

result := KeyBy[int, string](list, func(str string) int {
result := KeyBy(list, func(str string) int {
return len(str)
})

Expand Down
20 changes: 9 additions & 11 deletions type_manipulation_test.go
Expand Up @@ -91,9 +91,7 @@ func TestEmpty(t *testing.T) {
is := assert.New(t)

//nolint:unused
type test struct {
foobar string
}
type test struct{}

is.Empty(Empty[string]())
is.Empty(Empty[int64]())
Expand All @@ -110,12 +108,12 @@ func TestIsEmpty(t *testing.T) {
foobar string
}

is.True(IsEmpty[string](""))
is.False(IsEmpty[string]("foo"))
is.True(IsEmpty(""))
is.False(IsEmpty("foo"))
is.True(IsEmpty[int64](0))
is.False(IsEmpty[int64](42))
is.True(IsEmpty[test](test{foobar: ""}))
is.False(IsEmpty[test](test{foobar: "foo"}))
is.True(IsEmpty(test{foobar: ""}))
is.False(IsEmpty(test{foobar: "foo"}))
}

func TestIsNotEmpty(t *testing.T) {
Expand All @@ -127,12 +125,12 @@ func TestIsNotEmpty(t *testing.T) {
foobar string
}

is.False(IsNotEmpty[string](""))
is.True(IsNotEmpty[string]("foo"))
is.False(IsNotEmpty(""))
is.True(IsNotEmpty("foo"))
is.False(IsNotEmpty[int64](0))
is.True(IsNotEmpty[int64](42))
is.False(IsNotEmpty[test](test{foobar: ""}))
is.True(IsNotEmpty[test](test{foobar: "foo"}))
is.False(IsNotEmpty(test{foobar: ""}))
is.True(IsNotEmpty(test{foobar: "foo"}))
}

func TestCoalesce(t *testing.T) {
Expand Down

0 comments on commit 27d8810

Please sign in to comment.