Example #1
0
func TestSliceSetAdd(t *testing.T) {
	specs := specs.New(t)

	set := NewSliceSet(100).Add(1, 2, 5, 2)

	specs.Expect(set.Contains(1, 2, 5), true)
	specs.Expect(set.Size(), 3)
}
Example #2
0
func TestSliceSetSize(t *testing.T) {
	specs := specs.New(t)

	set := NewSliceSet(100).Add(1, 2, 3)
	specs.Expect(set.Size(), 3)
	set.Remove(2)
	specs.Expect(set.Size(), 2)
}
Example #3
0
func TestSliceSetRemove(t *testing.T) {
	specs := specs.New(t)

	set := NewSliceSet(100).Add(3, 1)
	specs.Expect(set.Contains(3, 1), true)
	set.Remove(1, 3)
	specs.Expect(set.Contains(1, 3), false)
}
Example #4
0
func TestSliceSetClear(t *testing.T) {
	specs := specs.New(t)

	set := NewSliceSet(100).Add(1, 2, 3, 4, 5).Clear()

	specs.Expect(set.Contains(1, 2, 3, 4, 5), false)
	specs.Expect(set.Size(), 0)
}
Example #5
0
func TestSliceSetContains(t *testing.T) {
	specs := specs.New(t)

	set := NewSliceSet(100).Add(1, 2, 3).Remove(2)

	specs.Expect(set.Contains(2), false)
	specs.Expect(set.Contains(1, 3), true)
	specs.Expect(set.Contains(1, 2, 3), false)
}
Example #6
0
func TestSliceSetSupersetOf(t *testing.T) {
	specs := specs.New(t)

	setA := NewSliceSet(100).Add(1, 2)
	setB := NewSliceSet(100).Add(1, 2, 3)
	setC := NewSliceSet(100).Add(3, 4, 5)

	specs.Expect(setB.SupersetOf(setA), true)
	specs.Expect(setC.SupersetOf(setA), false)
}
Example #7
0
func TestSliceSetEqual(t *testing.T) {
	specs := specs.New(t)

	setA := NewSliceSet(100).Add(1, 2)
	setB := NewSliceSet(100).Add(2, 1, 1)
	setC := NewSliceSet(100).Add(1, 3)

	specs.Expect(setA.Equal(setB), true)
	specs.Expect(setA.Equal(setC), false)
}
Example #8
0
func TestSliceSetSymetricDifference(t *testing.T) {
	specs := specs.New(t)

	setA := NewSliceSet(100).Add(1, 2, 4)
	setB := NewSliceSet(100).Add(1, 2, 3)
	setC := NewSliceSet(100).Add(3, 4, 5)

	specs.Expect(setA.SymetricDifference(setB).Equal(NewSliceSet(100).Add(3, 4)), true)
	specs.Expect(setB.SymetricDifference(setC).Equal(NewSliceSet(100).Add(1, 2, 4, 5)), true)
}
Example #9
0
func TestSliceSetIntersection(t *testing.T) {
	specs := specs.New(t)

	setA := NewSliceSet(100).Add(1, 2)
	setB := NewSliceSet(100).Add(1, 2, 3)
	setC := NewSliceSet(100).Add(3, 4, 5)

	specs.Expect(setA.Intersection(setB).Equal(setA), true)
	specs.Expect(setB.Intersection(setC).Equal(NewSliceSet(100).Add(3)), true)
}
Example #10
0
func TestSliceSetUnion(t *testing.T) {
	specs := specs.New(t)

	setA := NewSliceSet(100).Add(1, 2)
	setB := NewSliceSet(100).Add(3, 4)
	setC := NewSliceSet(100).Add(1, 99)

	specs.Expect(setA.Union(setB).Equal(NewSliceSet(100).Add(1, 2, 3, 4)), true)
	specs.Expect(setA.Union(setC).Equal(NewSliceSet(100).Add(1, 2, 99)), true)
}
Example #11
0
func TestBriggsSetSubsetOf(t *testing.T) {
	specs := specs.New(t)

	setA := NewBriggsSet(100).Add(1, 2)
	setB := NewBriggsSet(100).Add(1, 2, 3)
	setC := NewBriggsSet(100).Add(3, 4, 5)

	specs.Expect(setA.SubsetOf(setB), true)
	specs.Expect(setA.SubsetOf(setC), false)
}
Example #12
0
func TestSliceSetAll(t *testing.T) {
	specs := specs.New(t)

	set := NewSliceSet(100).Add(99, 1, 5)
	all := set.All()

	specs.Expect(len(all), 3)
	specs.Expect(all[0], 1)
	specs.Expect(all[1], 5)
	specs.Expect(all[2], 99)
}
Example #13
0
func TestBriggsSetAll(t *testing.T) {
	specs := specs.New(t)

	set := NewBriggsSet(100).Add(99, 1, 5)
	all := set.All()

	specs.Expect(len(all), 3)
	sort.Ints(all) // Hashet.All() doesn't guarantee order of ints
	specs.Expect(all[0], 1)
	specs.Expect(all[1], 5)
	specs.Expect(all[2], 99)
}
Example #14
0
func TestSliceSetClone(t *testing.T) {
	specs := specs.New(t)

	setA := NewSliceSet(100).Add(9, 3, 1)
	setB := setA.Clone()

	specs.Expect(setB.Equal(setA), true)
}