Ejemplo n.º 1
0
func TestStringSet(t *testing.T) {
	s := set.Set()
	s.Add("a")
	s.Add("b")
	s.Add("c")
	assert.Equal(t, len(s), 3, "Set has size 3")
	assert.True(t, s.Contains("a"), "Set contains an element")
	assert.True(t, s.Contains("b"), "Set contains an element")
	assert.False(t, s.Contains("asfasdf"), "Set does not contain an element")

	s.Add("a")
	s.Add("b")
	assert.Equal(t, len(s), 3, "Set has size 3")

	s.Discard("a")
	assert.Equal(t, len(s), 2, "Set has size 2")

	s.Discard("b")
	assert.Equal(t, len(s), 1, "Set has size 1")
	assert.True(t, s.Contains("c"), "Set contains an element")

	s.Clean()
	assert.Equal(t, len(s), 0, "Set is empty")
	assert.False(t, s.Contains("a"), "Set contains an element")
	assert.False(t, s.Contains("b"), "Set contains an element")
}
Ejemplo n.º 2
0
// go test set_test.go
func TestSet(t *testing.T) {
	s := set.Set()
	s.Add(1)
	s.Add(2)
	s.Add(3)
	assert.Equal(t, len(s), 3, "Set has size 3")
	assert.True(t, s.Contains(1), "Set contains an element")
	assert.True(t, s.Contains(2), "Set contains an element")
	assert.False(t, s.Contains(-1), "Set does not contain an element")

	s.Add(1)
	s.Add(2)
	assert.Equal(t, len(s), 3, "Set has size 3")

	s.Discard(1)
	assert.Equal(t, len(s), 2, "Set has size 2")

	s.Discard(2)
	assert.Equal(t, len(s), 1, "Set has size 1")

	s.Clean()
	assert.Equal(t, len(s), 0, "Set is empty")
	assert.False(t, s.Contains(1), "Set contains an element")
	assert.False(t, s.Contains(2), "Set contains an element")
}
Ejemplo n.º 3
0
func genSet(e []int) set.SetWrapper {
	s := set.Set()
	for _, i := range e {
		s.Add(i)
	}
	return s
}
Ejemplo n.º 4
0
func TestSubSet(t *testing.T) {
	elements := []int{1, 2, 3}
	elements2 := []int{1, 2, 3, 4, 5, 6, 7}
	elements3 := []int{4, 5, 6, 7, 8, 9, 10}

	a := genSet(elements)
	b := genSet(elements2)
	c := genSet(elements3)

	assert.True(t, a.Subset(b), "Should be a subset")
	assert.True(t, a.Subset(a), "Should be a subset")
	assert.True(t, set.Set().Subset(a), "Empty set is automatic subset")

	assert.False(t, a.Subset(c), "Should not be a subset")
	assert.False(t, b.Subset(c), "Should not be a subset")
}
Ejemplo n.º 5
0
func Run() {
	s := set.Set()
	s.Add(1)
}