Skip to content

Commit

Permalink
update List.TakeLast and List.SkipLast tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hsldymq committed Mar 31, 2024
1 parent b413f48 commit 6fe8e6f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func TestList_Take(t *testing.T) {
func TestList_TakeLast(t *testing.T) {
list := NewList(1, 2, 3, 4, 5, 6, 7, 8)

// case 1
actual := []int{}
for v := range list.TakeLast(5).Iter() {
actual = append(actual, v)
Expand All @@ -236,6 +237,20 @@ func TestList_TakeLast(t *testing.T) {
t.Fatalf("test List.TakeLast expect: %v, actual: %v", expect, actual)
}

// case 2
actual = []int{}
for v := range list.TakeLast(5).Iter() {
actual = append(actual, v)
if v == 6 {
break
}
}
expect = []int{4, 5, 6}
if !slices.Equal(expect, actual) {
t.Fatalf("test List.TakeLast expect: %v, actual: %v", expect, actual)
}

// case 3
actual = []int{}
for v := range list.TakeLast(10).Iter() {
actual = append(actual, v)
Expand All @@ -245,6 +260,7 @@ func TestList_TakeLast(t *testing.T) {
t.Fatalf("test List.TakeLast expect: %v, actual: %v", expect, actual)
}

// case 4
actual = []int{}
for v := range list.TakeLast(-1).Iter() {
actual = append(actual, v)
Expand Down Expand Up @@ -289,6 +305,7 @@ func TestList_Skip(t *testing.T) {
func TestList_SkipLast(t *testing.T) {
list := NewList(1, 2, 3, 4, 5, 6, 7, 8)

// case 1
actual := []int{}
for v := range list.SkipLast(5).Iter() {
actual = append(actual, v)
Expand All @@ -298,6 +315,20 @@ func TestList_SkipLast(t *testing.T) {
t.Fatalf("test List.SkipLast expect: %v, actual: %v", expect, actual)
}

// case 2
actual = []int{}
for v := range list.SkipLast(4).Iter() {
actual = append(actual, v)
if v == 3 {
break
}
}
expect = []int{1, 2, 3}
if !slices.Equal(expect, actual) {
t.Fatalf("test List.TakeLast expect: %v, actual: %v", expect, actual)
}

// case 3
actual = []int{}
for v := range list.SkipLast(8).Iter() {
actual = append(actual, v)
Expand All @@ -307,6 +338,7 @@ func TestList_SkipLast(t *testing.T) {
t.Fatalf("test List.SkipLast expect: %v, actual: %v", expect, actual)
}

// case 4
actual = []int{}
for v := range list.SkipLast(-1).Iter() {
actual = append(actual, v)
Expand Down

0 comments on commit 6fe8e6f

Please sign in to comment.