Skip to content

Commit

Permalink
add List tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hsldymq committed Apr 1, 2024
1 parent 0866dfb commit 80e8b6f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,26 @@ func TestList_SkipLast(t *testing.T) {
t.Fatalf("test List.SkipLast expect: %v, actual: %v", expect, actual)
}
}

func TestList_Distinct(t *testing.T) {
list := NewList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5)
actual := []int{}
for v := range list.Distinct().Iter() {
actual = append(actual, v)
}
expect := []int{1, 2, 3, 4, 5}
if !slices.Equal(expect, actual) {
t.Fatalf("test List.Distinct expect: %v, actual: %v", expect, actual)
}

f := func() {}
list2 := NewList(f, f, f)
actual2 := []func(){}
for v := range list2.Distinct().Iter() {
actual2 = append(actual2, v)
}
expect2 := 3
if expect2 != len(actual2) {
t.Fatalf("test List.Distinct, should return 3 elements")
}
}

0 comments on commit 80e8b6f

Please sign in to comment.