12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package buildin
- import (
- "reflect"
- "testing"
- )
- func TestIntersection(t *testing.T) {
-
- a := []string{"apple", "banana", "orange"}
- b := []string{"banana", "grape", "orange"}
- expected1 := []string{"banana", "orange"}
- result1 := Intersection(a, b)
- if !reflect.DeepEqual(result1, expected1) {
- t.Errorf("Test case 1 failed. Expected %v, got %v", expected1, result1)
- }
-
- c := []int{1, 2, 3, 4}
- d := []int{2, 3, 4, 5}
- expected2 := []int{2, 3, 4}
- result2 := Intersection(c, d)
- if !reflect.DeepEqual(result2, expected2) {
- t.Errorf("Test case 2 failed. Expected %v, got %v", expected2, result2)
- }
- }
- func TestInSlice(t *testing.T) {
-
- slice1 := []int{1, 2, 3, 4, 5}
- item1 := 3
- expected1 := true
- result1 := InSlice(item1, slice1)
- if result1 != expected1 {
- t.Errorf("Test case 1 failed. Expected %v, got %v", expected1, result1)
- }
-
- slice2 := []string{"apple", "banana", "orange"}
- item2 := "grape"
- expected2 := false
- result2 := InSlice(item2, slice2)
- if result2 != expected2 {
- t.Errorf("Test case 2 failed. Expected %v, got %v", expected2, result2)
- }
-
- slice3 := []bool{true, false}
- item3 := true
- expected3 := true
- result3 := InSlice(item3, slice3)
- if result3 != expected3 {
- t.Errorf("Test case 3 failed. Expected %v, got %v", expected3, result3)
- }
- }
- func TestRemoveDuplicates(t *testing.T) {
-
- slice1 := []string{"apple", "banana", "apple", "orange", "banana"}
- result1 := RemoveDuplicates(slice1)
- expected1 := []string{"apple", "banana", "orange"}
- if !reflect.DeepEqual(result1, expected1) {
- panic("Test case 1 failed")
- }
-
- slice2 := []int{1, 2, 2, 3, 4, 4, 5}
- result2 := RemoveDuplicates(slice2)
- expected2 := []int{1, 2, 3, 4, 5}
- if !reflect.DeepEqual(result2, expected2) {
- panic("Test case 2 failed")
- }
- }
|