Skip to content

Commit

Permalink
#67 Apply testEmptyChain
Browse files Browse the repository at this point in the history
  • Loading branch information
meian committed Jan 30, 2022
1 parent ea65aab commit a4127f7
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 0 deletions.
7 changes: 7 additions & 0 deletions concat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func TestConcat(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.Concat(itb, gcf.FromSlice([]int{4, 5, 6}))
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Concat(itb, gcf.FromSlice([]int{}))
})
testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Concat(itb, nil)
})
}

func ExampleConcat() {
Expand Down
4 changes: 4 additions & 0 deletions distinct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func TestDistinct(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3, 2, 4})
itb = gcf.Distinct(itb)
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Distinct(itb)
})
}

func ExampleDistinct() {
Expand Down
4 changes: 4 additions & 0 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func TestFilter(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3, 4})
itb = gcf.Filter(itb, func(v int) bool { return v%2 == 0 })
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Filter(itb, func(v int) bool { return true })
})
}

func ExampleFilter() {
Expand Down
8 changes: 8 additions & 0 deletions map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func TestMap(t *testing.T) {
assert.Equal(tt.want, s)
})
}

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Map(itb, func(v int) int { return v })
})
}

func ExampleMap() {
Expand Down Expand Up @@ -140,6 +144,10 @@ func TestFlatMap(t *testing.T) {
return strings.Repeat("a", v)
})
testBeforeAndAfter(t, itbs)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.FlatMap(itb, func(v int) []int { return []int{v, v, v} })
})
}

func ExampleFlatMap() {
Expand Down
9 changes: 9 additions & 0 deletions range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ func TestRange(t *testing.T) {
testBeforeAndAfter(t, itb)
itb, _ = gcf.Range(3, 1, -1)
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
itb, _ = gcf.Range(1, 0, 1)
return itb
})
testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
itb, _ = gcf.Range(1, 2, -1)
return itb
})
}

func ExampleRange() {
Expand Down
14 changes: 14 additions & 0 deletions repeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func TestRepeat(t *testing.T) {

itb := gcf.Repeat(1, 3)
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Repeat(1, 0)
})
testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Repeat(1, -1)
})
}

func ExampleRepeat() {
Expand Down Expand Up @@ -116,6 +123,13 @@ func TestRepeatIterable(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.RepeatIterable(itb, 2)
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.RepeatIterable(itb, 0)
})
testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.RepeatIterable(itb, -1)
})
}

func ExampleRepeatIterable() {
Expand Down
4 changes: 4 additions & 0 deletions reverse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func TestReverse(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.Reverse(itb)
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Reverse(itb)
})
}

func ExampleReverse() {
Expand Down
8 changes: 8 additions & 0 deletions skip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func TestSkip(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.Skip(itb, 2)
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Skip(itb, 0)
})
}

func ExampleSkip() {
Expand Down Expand Up @@ -166,6 +170,10 @@ func TestSkipWhile(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.SkipWhile(itb, func(v int) bool { return v < 2 })
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.SkipWhile(itb, func(v int) bool { return true })
})
}

func ExampleSkipWhile() {
Expand Down
8 changes: 8 additions & 0 deletions slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func TestFromSlice_pointer(t *testing.T) {

itb := gcf.FromSlice([]*int{&i1, &i2, &i3})
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.FromSlice([]int{})
})
}

func TestFromSliceImmutable(t *testing.T) {
Expand Down Expand Up @@ -142,6 +146,10 @@ func TestFromSliceImmutable(t *testing.T) {

itb := gcf.FromSliceImmutable([]int{1, 2, 3})
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.FromSliceImmutable([]int{})
})
}

func TestToSlice(t *testing.T) {
Expand Down
12 changes: 12 additions & 0 deletions sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func TestSortAsc(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.SortAsc(itb)
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.SortAsc(itb)
})
}

func TestSortDesc(t *testing.T) {
Expand Down Expand Up @@ -150,6 +154,10 @@ func TestSortDesc(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.SortDesc(itb)
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.SortDesc(itb)
})
}

func TestSortBy(t *testing.T) {
Expand Down Expand Up @@ -239,6 +247,10 @@ func TestSortBy(t *testing.T) {
itb := gcf.FromSlice([]data{{1}, {2}, {3}})
itb = gcf.SortBy(itb, func(x, y data) bool { return x.v < y.v })
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.SortBy(itb, func(x, y int) bool { return true })
})
}

func FuzzSortAsc(f *testing.F) {
Expand Down
8 changes: 8 additions & 0 deletions take_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func TestTake(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.Take(itb, 2)
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.Take(itb, 1)
})
}

func ExampleTake() {
Expand Down Expand Up @@ -166,6 +170,10 @@ func TestTakeWhile(t *testing.T) {
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.TakeWhile(itb, func(v int) bool { return v < 2 })
testBeforeAndAfter(t, itb)

testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] {
return gcf.TakeWhile(itb, func(v int) bool { return true })
})
}

func ExampleTakeWhile() {
Expand Down

0 comments on commit a4127f7

Please sign in to comment.