You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
2.6 KiB
129 lines
2.6 KiB
package slice
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestIntersection(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
b := []int{1, 2, 0, 56, 89}
|
|
c := []int{1, 2, 4}
|
|
fmt.Println(Intersection(a, b))
|
|
fmt.Println(Intersection(a, c))
|
|
|
|
}
|
|
func TestUnion(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
b := []int{1, 2, 0, 56, 89}
|
|
c := []int{1, 2, 4}
|
|
fmt.Println(Union(a, b))
|
|
fmt.Println(Union(a, c))
|
|
|
|
}
|
|
func TestUniqueBy(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
b := []int{1, 2, 3}
|
|
c := []int{1, 2, 4}
|
|
fmt.Println(UniqueBy(a, func(i int) int {
|
|
return i
|
|
}))
|
|
fmt.Println(UniqueBy(b, func(i int) int {
|
|
return i
|
|
}))
|
|
fmt.Println(UniqueBy(c, func(i int) int {
|
|
return i
|
|
}))
|
|
|
|
}
|
|
func TestUnique(t *testing.T) {
|
|
a := []int{1, 2, 3, 1, 2, 3}
|
|
b := []int{1, 2, 3}
|
|
c := []int{1, 2, 4}
|
|
d := []int{13, 32, 43, 56, 65, 76, 87, 98, 87, 76, 65, 43, 32, 13}
|
|
fmt.Println(Unique(a))
|
|
fmt.Println(Unique(b))
|
|
fmt.Println(Unique(c))
|
|
fmt.Println(Unique(d))
|
|
|
|
}
|
|
func TestUpdateAt(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
fmt.Println(UpdateAt(a, 1, 4))
|
|
fmt.Println(UpdateAt(a, 2, 4))
|
|
fmt.Println(UpdateAt(a, 3, 4))
|
|
fmt.Println(UpdateAt(a, 4, 4))
|
|
|
|
}
|
|
func TestInsertAt(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
fmt.Println(InsertAt(a, 1, 4))
|
|
fmt.Println(InsertAt(a, 2, 4))
|
|
fmt.Println(InsertAt(a, 3, 4))
|
|
fmt.Println(InsertAt(a, 4, 4))
|
|
|
|
}
|
|
func TestDrop(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
fmt.Println(Drop(a, 1))
|
|
fmt.Println(Drop(a, 2))
|
|
fmt.Println(Drop(a, 3))
|
|
fmt.Println(Drop(a, 4))
|
|
|
|
}
|
|
func TestDeleteAt(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
fmt.Println(DeleteAt(a, 1))
|
|
fmt.Println(DeleteAt(a, 2))
|
|
fmt.Println(DeleteAt(a, 3))
|
|
fmt.Println(DeleteAt(a, 4))
|
|
|
|
}
|
|
func TestIntSlice(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
b := []int{1, 2, 3}
|
|
c := []int{1, 2, 4}
|
|
fmt.Println(IntSlice(a))
|
|
fmt.Println(IntSlice(b))
|
|
fmt.Println(IntSlice(c))
|
|
|
|
}
|
|
func TestStringSlice(t *testing.T) {
|
|
a := []string{"hello", "world"}
|
|
c := []string{"hello", "world", "!"}
|
|
d := []int{1, 2, 3}
|
|
fmt.Println(StringSlice(a))
|
|
fmt.Println(StringSlice(d))
|
|
fmt.Println(StringSlice(c))
|
|
|
|
}
|
|
func TestEqualWith(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
b := []int{1, 2, 3}
|
|
c := []int{1, 2, 4}
|
|
fmt.Println(EqualWith(a, b, func(i, j int) bool {
|
|
return i == j
|
|
}))
|
|
fmt.Println(EqualWith(a, c, func(i, j int) bool {
|
|
return i == j
|
|
}))
|
|
|
|
}
|
|
func TestEqual(t *testing.T) {
|
|
a := []int{1, 2, 3}
|
|
b := []int{1, 2, 3}
|
|
c := []int{1, 2, 4}
|
|
fmt.Println(Equal(a, b))
|
|
fmt.Println(Equal(a, c))
|
|
|
|
}
|
|
|
|
func TestChunk(t *testing.T) {
|
|
a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
|
b := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
|
c := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
|
fmt.Println(Chunk(a, 2))
|
|
fmt.Println(Chunk(b, 10))
|
|
fmt.Println(Chunk(c, 3))
|
|
}
|