-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package handy | ||
|
||
import ( | ||
"slices" | ||
"testing" | ||
) | ||
|
||
func TestList_Take(t *testing.T) { | ||
list := NewListWithElems(1, 2, 3, 4, 5, 6, 7, 8) | ||
|
||
actual := []int{} | ||
for v := range list.Take(5).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect := []int{1, 2, 3, 4, 5} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.Take expect: %v, actual: %v", expect, actual) | ||
} | ||
|
||
actual = []int{} | ||
for v := range list.Take(10).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect = []int{1, 2, 3, 4, 5, 6, 7, 8} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.Take expect: %v, actual: %v", expect, actual) | ||
} | ||
|
||
actual = []int{} | ||
for v := range list.Take(-1).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect = []int{} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.Take expect: %v, actual: %v", expect, actual) | ||
} | ||
} | ||
|
||
func TestList_TakeLast(t *testing.T) { | ||
list := NewListWithElems(1, 2, 3, 4, 5, 6, 7, 8) | ||
|
||
actual := []int{} | ||
for v := range list.TakeLast(5).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect := []int{4, 5, 6, 7, 8} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.TakeLast expect: %v, actual: %v", expect, actual) | ||
} | ||
|
||
actual = []int{} | ||
for v := range list.TakeLast(10).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect = []int{1, 2, 3, 4, 5, 6, 7, 8} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.TakeLast expect: %v, actual: %v", expect, actual) | ||
} | ||
|
||
actual = []int{} | ||
for v := range list.TakeLast(-1).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect = []int{} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.TakeLast expect: %v, actual: %v", expect, actual) | ||
} | ||
} | ||
|
||
func TestList_Skip(t *testing.T) { | ||
list := NewListWithElems(1, 2, 3, 4, 5, 6, 7, 8) | ||
|
||
actual := []int{} | ||
for v := range list.Skip(5).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect := []int{6, 7, 8} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.Skip expect: %v, actual: %v", expect, actual) | ||
} | ||
|
||
actual = []int{} | ||
for v := range list.Skip(10).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect = []int{} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.Skip expect: %v, actual: %v", expect, actual) | ||
} | ||
|
||
actual = []int{} | ||
for v := range list.Skip(-1).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect = []int{1, 2, 3, 4, 5, 6, 7, 8} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.Skip expect: %v, actual: %v", expect, actual) | ||
} | ||
} | ||
|
||
func TestList_SkipLast(t *testing.T) { | ||
list := NewListWithElems(1, 2, 3, 4, 5, 6, 7, 8) | ||
|
||
actual := []int{} | ||
for v := range list.SkipLast(5).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect := []int{1, 2, 3} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.SkipLast expect: %v, actual: %v", expect, actual) | ||
} | ||
|
||
actual = []int{} | ||
for v := range list.SkipLast(8).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect = []int{} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.SkipLast expect: %v, actual: %v", expect, actual) | ||
} | ||
|
||
actual = []int{} | ||
for v := range list.SkipLast(-1).Iter() { | ||
actual = append(actual, v) | ||
} | ||
expect = []int{1, 2, 3, 4, 5, 6, 7, 8} | ||
if !slices.Equal(expect, actual) { | ||
t.Fatalf("test List.SkipLast expect: %v, actual: %v", expect, actual) | ||
} | ||
} |