Esempio n. 1
0
func (intSetSuite) TestDifference(c *gc.C) {
	s1 := set.NewInts(1, 2)
	s2 := set.NewInts(1, 3, 4)
	diff1 := s1.Difference(s2)
	diff2 := s2.Difference(s1)

	AssertIntValues(c, diff1, 2)
	AssertIntValues(c, diff2, 3, 4)
}
Esempio n. 2
0
func (intSetSuite) TestSize(c *gc.C) {
	// Empty sets are empty.
	s := set.NewInts()
	c.Assert(s.Size(), gc.Equals, 0)

	// Size returns number of unique values.
	s = set.NewInts(1, 1, 2)
	c.Assert(s.Size(), gc.Equals, 2)
}
Esempio n. 3
0
func (intSetSuite) TestIntersection(c *gc.C) {
	s1 := set.NewInts(1, 2)
	s2 := set.NewInts(1, 3, 4)
	int1 := s1.Intersection(s2)
	int2 := s2.Intersection(s1)

	AssertIntValues(c, int1, 1)
	AssertIntValues(c, int2, 1)
}
Esempio n. 4
0
func (intSetSuite) TestUnion(c *gc.C) {
	s1 := set.NewInts(1, 2)
	s2 := set.NewInts(1, 3, 4)
	union1 := s1.Union(s2)
	union2 := s2.Union(s1)

	AssertIntValues(c, union1, 1, 2, 3, 4)
	AssertIntValues(c, union2, 1, 2, 3, 4)
}
Esempio n. 5
0
func (intSetSuite) TestIsEmpty(c *gc.C) {
	// Empty sets are empty.
	s := set.NewInts()
	c.Assert(s.IsEmpty(), jc.IsTrue)

	// Non-empty sets are not empty.
	s = set.NewInts(1)
	c.Assert(s.IsEmpty(), jc.IsFalse)
	// Newly empty sets work too.
	s.Remove(1)
	c.Assert(s.IsEmpty(), jc.IsTrue)
}
Esempio n. 6
0
func (intSetSuite) TestAdd(c *gc.C) {
	s := set.NewInts()
	s.Add(1)
	s.Add(1)
	s.Add(2)
	AssertIntValues(c, s, 1, 2)
}
Esempio n. 7
0
// relationsChanged responds to service relation changes.
func (f *filter) relationsChanged(changed []int) {
	ids := set.NewInts(f.relations...)
	for _, id := range changed {
		ids.Add(id)
	}
	if len(f.relations) != len(ids) {
		f.relations = ids.SortedValues()
		f.outRelations = f.outRelationsOn
	}
}
Esempio n. 8
0
// Add adds a port to the PortSet.
func (ps *PortSet) Add(protocol string, port int) {
	if ps.values == nil {
		panic("uninitalised set")
	}
	ports, ok := ps.values[protocol]
	if !ok {
		ps.values[protocol] = set.NewInts(port)
	} else {
		ports.Add(port)
	}
}
Esempio n. 9
0
// Ports returns the unique ports for the api addresses.
func (info *Info) Ports() []int {
	ports := set.NewInts()
	hostPorts, err := network.ParseHostPorts(info.Addrs...)
	if err != nil {
		// Addresses have already been validated.
		panic(err)
	}
	for _, hp := range hostPorts {
		ports.Add(hp.Port)
	}
	return ports.Values()
}
Esempio n. 10
0
func (intSetSuite) TestRemoveNonExistent(c *gc.C) {
	s := set.NewInts()
	s.Remove(1)
	AssertIntValues(c, s)
}
Esempio n. 11
0
func (intSetSuite) TestContains(c *gc.C) {
	s := set.NewInts(1, 2)
	c.Assert(s.Contains(1), jc.IsTrue)
	c.Assert(s.Contains(2), jc.IsTrue)
	c.Assert(s.Contains(3), jc.IsFalse)
}
Esempio n. 12
0
func (intSetSuite) TestRemove(c *gc.C) {
	s := set.NewInts(1, 2)
	s.Remove(1)
	AssertIntValues(c, s, 2)
}
Esempio n. 13
0
func (intSetSuite) TestInitialValues(c *gc.C) {
	values := []int{1, 2, 3}
	s := set.NewInts(values...)
	AssertIntValues(c, s, values...)
}
Esempio n. 14
0
func (intSetSuite) TestEmpty(c *gc.C) {
	s := set.NewInts()
	AssertIntValues(c, s)
}