2014-08-21 03:30:28 +02:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetAdd(t *testing.T) {
|
|
|
|
s := &Set{F: testSetInt}
|
|
|
|
s.Add(1)
|
|
|
|
s.Add(5)
|
|
|
|
s.Add(25)
|
|
|
|
|
|
|
|
expected := []interface{}{1, 5, 25}
|
|
|
|
actual := s.List()
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-23 16:57:26 +02:00
|
|
|
func TestSetAdd_negative(t *testing.T) {
|
|
|
|
// Since we don't allow negative hashes, this should just hash to the
|
|
|
|
// same thing...
|
|
|
|
s := &Set{F: testSetInt}
|
|
|
|
s.Add(-1)
|
|
|
|
s.Add(1)
|
|
|
|
|
|
|
|
expected := []interface{}{-1}
|
|
|
|
actual := s.List()
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-21 06:02:42 +02:00
|
|
|
func TestSetContains(t *testing.T) {
|
|
|
|
s := &Set{F: testSetInt}
|
|
|
|
s.Add(5)
|
|
|
|
|
|
|
|
if s.Contains(2) {
|
|
|
|
t.Fatal("should not contain")
|
|
|
|
}
|
|
|
|
if !s.Contains(5) {
|
|
|
|
t.Fatal("should contain")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-21 03:30:28 +02:00
|
|
|
func TestSetDifference(t *testing.T) {
|
|
|
|
s1 := &Set{F: testSetInt}
|
2014-08-21 07:24:35 +02:00
|
|
|
s2 := &Set{F: testSetInt}
|
2014-08-21 03:30:28 +02:00
|
|
|
|
|
|
|
s1.Add(1)
|
|
|
|
s1.Add(5)
|
|
|
|
|
|
|
|
s2.Add(5)
|
|
|
|
s2.Add(25)
|
|
|
|
|
2015-01-15 15:33:52 +01:00
|
|
|
difference := s1.Difference(s2)
|
|
|
|
difference.Add(2)
|
|
|
|
|
|
|
|
expected := []interface{}{1, 2}
|
|
|
|
actual := difference.List()
|
2014-08-21 03:30:28 +02:00
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetIntersection(t *testing.T) {
|
|
|
|
s1 := &Set{F: testSetInt}
|
2014-08-21 07:24:35 +02:00
|
|
|
s2 := &Set{F: testSetInt}
|
2014-08-21 03:30:28 +02:00
|
|
|
|
|
|
|
s1.Add(1)
|
|
|
|
s1.Add(5)
|
|
|
|
|
|
|
|
s2.Add(5)
|
|
|
|
s2.Add(25)
|
|
|
|
|
2015-01-15 15:33:52 +01:00
|
|
|
intersection := s1.Intersection(s2)
|
|
|
|
intersection.Add(2)
|
|
|
|
|
|
|
|
expected := []interface{}{2, 5}
|
|
|
|
actual := intersection.List()
|
2014-08-21 03:30:28 +02:00
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetUnion(t *testing.T) {
|
|
|
|
s1 := &Set{F: testSetInt}
|
2014-08-21 07:24:35 +02:00
|
|
|
s2 := &Set{F: testSetInt}
|
2014-08-21 03:30:28 +02:00
|
|
|
|
|
|
|
s1.Add(1)
|
|
|
|
s1.Add(5)
|
|
|
|
|
|
|
|
s2.Add(5)
|
|
|
|
s2.Add(25)
|
|
|
|
|
2015-01-15 15:33:52 +01:00
|
|
|
union := s1.Union(s2)
|
|
|
|
union.Add(2)
|
|
|
|
|
|
|
|
expected := []interface{}{1, 2, 5, 25}
|
|
|
|
actual := union.List()
|
2014-08-21 03:30:28 +02:00
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSetInt(v interface{}) int {
|
|
|
|
return v.(int)
|
|
|
|
}
|