Update dependencies (#34)

This commit is contained in:
Elizabeth
2018-09-24 15:39:23 -05:00
committed by GitHub
parent cee824f7ad
commit 5fc7170c1e
115 changed files with 1694 additions and 6055 deletions
+3
View File
@@ -162,6 +162,9 @@ type Set interface {
// Otherwise, IsSuperset will panic.
Union(other Set) Set
// Pop removes and returns an arbitrary item from the set.
Pop() interface{}
// Returns all subsets of a given set (Power Set).
PowerSet() Set
+78
View File
@@ -967,6 +967,70 @@ func Test_IteratorStop(t *testing.T) {
}
}
func Test_PopSafe(t *testing.T) {
a := NewSet()
a.Add("a")
a.Add("b")
a.Add("c")
a.Add("d")
captureSet := NewSet()
captureSet.Add(a.Pop())
captureSet.Add(a.Pop())
captureSet.Add(a.Pop())
captureSet.Add(a.Pop())
finalNil := a.Pop()
if captureSet.Cardinality() != 4 {
t.Error("unexpected captureSet cardinality; should be 4")
}
if a.Cardinality() != 0 {
t.Error("unepxected a cardinality; should be zero")
}
if !captureSet.Contains("c", "a", "d", "b") {
t.Error("unexpected result set; should be a,b,c,d (any order is fine")
}
if finalNil != nil {
t.Error("when original set is empty, further pops should result in nil")
}
}
func Test_PopUnsafe(t *testing.T) {
a := NewThreadUnsafeSet()
a.Add("a")
a.Add("b")
a.Add("c")
a.Add("d")
captureSet := NewThreadUnsafeSet()
captureSet.Add(a.Pop())
captureSet.Add(a.Pop())
captureSet.Add(a.Pop())
captureSet.Add(a.Pop())
finalNil := a.Pop()
if captureSet.Cardinality() != 4 {
t.Error("unexpected captureSet cardinality; should be 4")
}
if a.Cardinality() != 0 {
t.Error("unepxected a cardinality; should be zero")
}
if !captureSet.Contains("c", "a", "d", "b") {
t.Error("unexpected result set; should be a,b,c,d (any order is fine")
}
if finalNil != nil {
t.Error("when original set is empty, further pops should result in nil")
}
}
func Test_PowerSet(t *testing.T) {
a := NewThreadUnsafeSet()
@@ -981,6 +1045,20 @@ func Test_PowerSet(t *testing.T) {
}
}
func Test_PowerSetThreadSafe(t *testing.T) {
set := NewSet().PowerSet()
_, setIsThreadSafe := set.(*threadSafeSet)
if !setIsThreadSafe {
t.Error("result of PowerSet should be thread safe")
}
subset := set.Pop()
_, subsetIsThreadSafe := subset.(*threadSafeSet)
if !subsetIsThreadSafe {
t.Error("subsets in PowerSet result should be thread safe")
}
}
func Test_EmptySetProperties(t *testing.T) {
empty := NewSet()
+13 -1
View File
@@ -226,11 +226,23 @@ func (set *threadSafeSet) String() string {
func (set *threadSafeSet) PowerSet() Set {
set.RLock()
ret := set.s.PowerSet()
unsafePowerSet := set.s.PowerSet().(*threadUnsafeSet)
set.RUnlock()
ret := &threadSafeSet{s: newThreadUnsafeSet()}
for subset := range unsafePowerSet.Iter() {
unsafeSubset := subset.(*threadUnsafeSet)
ret.Add(&threadSafeSet{s: *unsafeSubset})
}
return ret
}
func (set *threadSafeSet) Pop() interface{} {
set.Lock()
defer set.Unlock()
return set.s.Pop()
}
func (set *threadSafeSet) CartesianProduct(other Set) Set {
o := other.(*threadSafeSet)
+13 -1
View File
@@ -57,8 +57,12 @@ func (pair *OrderedPair) Equal(other OrderedPair) bool {
func (set *threadUnsafeSet) Add(i interface{}) bool {
_, found := (*set)[i]
if found {
return false //False if it existed already
}
(*set)[i] = struct{}{}
return !found //False if it existed already
return true
}
func (set *threadUnsafeSet) Contains(i ...interface{}) bool {
@@ -233,6 +237,14 @@ func (pair OrderedPair) String() string {
return fmt.Sprintf("(%v, %v)", pair.First, pair.Second)
}
func (set *threadUnsafeSet) Pop() interface{} {
for item := range *set {
delete(*set, item)
return item
}
return nil
}
func (set *threadUnsafeSet) PowerSet() Set {
powSet := NewThreadUnsafeSet()
nullset := newThreadUnsafeSet()