You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
5 years ago
|
package util
|
||
10 years ago
|
|
||
|
import (
|
||
|
"github.com/stretchr/testify/assert"
|
||
5 years ago
|
"testing"
|
||
10 years ago
|
)
|
||
|
|
||
9 years ago
|
func TestSliceEqual_True(t *testing.T) {
|
||
|
s1 := []string{"a", "b", "c"}
|
||
|
s2 := []string{"a", "b", "c"}
|
||
|
|
||
5 years ago
|
result := SliceEqual(s1, s2)
|
||
9 years ago
|
|
||
|
assert.True(t, result)
|
||
|
}
|
||
|
|
||
|
func TestSliceEqual_DifferentLengths(t *testing.T) {
|
||
|
s1 := []string{"a", "b", "c"}
|
||
|
s2 := []string{"a", "b", "c", "d"}
|
||
|
|
||
5 years ago
|
result := SliceEqual(s1, s2)
|
||
9 years ago
|
|
||
|
assert.False(t, result)
|
||
|
}
|
||
|
|
||
|
func TestSliceEqual_DifferentContents(t *testing.T) {
|
||
|
s1 := []string{"a", "b", "c"}
|
||
|
s2 := []string{"a", "b", "d"}
|
||
|
|
||
5 years ago
|
result := SliceEqual(s1, s2)
|
||
9 years ago
|
|
||
|
assert.False(t, result)
|
||
|
}
|
||
|
|
||
|
func TestSliceSubtract(t *testing.T) {
|
||
|
a1 := []string{"a", "b", "c"}
|
||
|
a2 := []string{"a", "c"}
|
||
|
|
||
5 years ago
|
result := SliceSubtract(a1, a2)
|
||
9 years ago
|
assert.Equal(t, []string{"b"}, result)
|
||
|
assert.Equal(t, []string{"a", "b", "c"}, a1)
|
||
|
assert.Equal(t, []string{"a", "c"}, a2)
|
||
|
}
|
||
|
|
||
10 years ago
|
func TestStringMapSubtract(t *testing.T) {
|
||
|
m1 := map[string]string{"a": "a", "b": "b", "c": "sea"}
|
||
|
m2 := map[string]string{"a": "a", "c": "c"}
|
||
|
|
||
5 years ago
|
result := StringMapSubtract(m1, m2)
|
||
10 years ago
|
assert.Equal(t, map[string]string{"b": "b", "c": "sea"}, result)
|
||
|
assert.Equal(t, map[string]string{"a": "a", "b": "b", "c": "sea"}, m1)
|
||
|
assert.Equal(t, map[string]string{"a": "a", "c": "c"}, m2)
|
||
|
}
|
||
|
|
||
|
func TestStructMapSubtract(t *testing.T) {
|
||
|
x := struct{}{}
|
||
|
m1 := map[string]struct{}{"a": x, "b": x, "c": x}
|
||
|
m2 := map[string]struct{}{"a": x, "c": x}
|
||
|
|
||
5 years ago
|
result := StructMapSubtract(m1, m2)
|
||
10 years ago
|
assert.Equal(t, map[string]struct{}{"b": x}, result)
|
||
|
assert.Equal(t, map[string]struct{}{"a": x, "b": x, "c": x}, m1)
|
||
|
assert.Equal(t, map[string]struct{}{"a": x, "c": x}, m2)
|
||
|
}
|