Skip to content

Commit

Permalink
HasAny tests generated
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Johansson authored and mmatczuk committed Nov 14, 2018
1 parent 9606584 commit e560bb8
Show file tree
Hide file tree
Showing 34 changed files with 850 additions and 0 deletions.
13 changes: 13 additions & 0 deletions b16set/b16set.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ func (s *Set) Has(items ...[16]byte) bool {
return has
}

// HasAny looks for the existence of any of the items passed.
// It returns false if nothing is passed.
// For multiple items it returns true if any of the items exist.
func (s *Set) HasAny(items ...[16]byte) bool {
has := false
for _, item := range items {
if _, has = s.m[item]; has {
break
}
}
return has
}

// Size returns the number of items in a Set.
func (s *Set) Size() int {
return len(s.m)
Expand Down
37 changes: 37 additions & 0 deletions b16set/b16set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,43 @@ func TestHas(t *testing.T) {
}
}

func TestHasAny(t *testing.T) {
var e1, e2, e3 [16]byte
e := createRandomObject(e1)
if v, ok := e.([16]byte); ok {
e1 = v
}
e = createRandomObject(e2)
if v, ok := e.([16]byte); ok {
e2 = v
}
e = createRandomObject(e2)
if v, ok := e.([16]byte); ok {
e3 = v
}

s := New()
if s.Has(e1) {
t.Errorf("expected a new set to not contain %v", e1)
}

s.Add(e1)
s.Add(e2)

if !s.HasAny(e1) {
t.Errorf("expected the set to contain %v", e1)
}
if !s.HasAny(e2) {
t.Errorf("expected the set to contain %v", e2)
}
if s.HasAny(e3) {
t.Errorf("did not expect the set to contain %v", e3)
}
if !s.HasAny(e1, e3) {
t.Errorf("expected the set to contain %v", e1)
}
}

func TestSize(t *testing.T) {
var e1, e2 [16]byte
e := createRandomObject(e1)
Expand Down
13 changes: 13 additions & 0 deletions b32set/b32set.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ func (s *Set) Has(items ...[32]byte) bool {
return has
}

// HasAny looks for the existence of any of the items passed.
// It returns false if nothing is passed.
// For multiple items it returns true if any of the items exist.
func (s *Set) HasAny(items ...[32]byte) bool {
has := false
for _, item := range items {
if _, has = s.m[item]; has {
break
}
}
return has
}

// Size returns the number of items in a Set.
func (s *Set) Size() int {
return len(s.m)
Expand Down
37 changes: 37 additions & 0 deletions b32set/b32set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,43 @@ func TestHas(t *testing.T) {
}
}

func TestHasAny(t *testing.T) {
var e1, e2, e3 [32]byte
e := createRandomObject(e1)
if v, ok := e.([32]byte); ok {
e1 = v
}
e = createRandomObject(e2)
if v, ok := e.([32]byte); ok {
e2 = v
}
e = createRandomObject(e2)
if v, ok := e.([32]byte); ok {
e3 = v
}

s := New()
if s.Has(e1) {
t.Errorf("expected a new set to not contain %v", e1)
}

s.Add(e1)
s.Add(e2)

if !s.HasAny(e1) {
t.Errorf("expected the set to contain %v", e1)
}
if !s.HasAny(e2) {
t.Errorf("expected the set to contain %v", e2)
}
if s.HasAny(e3) {
t.Errorf("did not expect the set to contain %v", e3)
}
if !s.HasAny(e1, e3) {
t.Errorf("expected the set to contain %v", e1)
}
}

func TestSize(t *testing.T) {
var e1, e2 [32]byte
e := createRandomObject(e1)
Expand Down
13 changes: 13 additions & 0 deletions b64set/b64set.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ func (s *Set) Has(items ...[64]byte) bool {
return has
}

// HasAny looks for the existence of any of the items passed.
// It returns false if nothing is passed.
// For multiple items it returns true if any of the items exist.
func (s *Set) HasAny(items ...[64]byte) bool {
has := false
for _, item := range items {
if _, has = s.m[item]; has {
break
}
}
return has
}

// Size returns the number of items in a Set.
func (s *Set) Size() int {
return len(s.m)
Expand Down
37 changes: 37 additions & 0 deletions b64set/b64set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,43 @@ func TestHas(t *testing.T) {
}
}

func TestHasAny(t *testing.T) {
var e1, e2, e3 [64]byte
e := createRandomObject(e1)
if v, ok := e.([64]byte); ok {
e1 = v
}
e = createRandomObject(e2)
if v, ok := e.([64]byte); ok {
e2 = v
}
e = createRandomObject(e2)
if v, ok := e.([64]byte); ok {
e3 = v
}

s := New()
if s.Has(e1) {
t.Errorf("expected a new set to not contain %v", e1)
}

s.Add(e1)
s.Add(e2)

if !s.HasAny(e1) {
t.Errorf("expected the set to contain %v", e1)
}
if !s.HasAny(e2) {
t.Errorf("expected the set to contain %v", e2)
}
if s.HasAny(e3) {
t.Errorf("did not expect the set to contain %v", e3)
}
if !s.HasAny(e1, e3) {
t.Errorf("expected the set to contain %v", e1)
}
}

func TestSize(t *testing.T) {
var e1, e2 [64]byte
e := createRandomObject(e1)
Expand Down
13 changes: 13 additions & 0 deletions b8set/b8set.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ func (s *Set) Has(items ...[8]byte) bool {
return has
}

// HasAny looks for the existence of any of the items passed.
// It returns false if nothing is passed.
// For multiple items it returns true if any of the items exist.
func (s *Set) HasAny(items ...[8]byte) bool {
has := false
for _, item := range items {
if _, has = s.m[item]; has {
break
}
}
return has
}

// Size returns the number of items in a Set.
func (s *Set) Size() int {
return len(s.m)
Expand Down
37 changes: 37 additions & 0 deletions b8set/b8set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,43 @@ func TestHas(t *testing.T) {
}
}

func TestHasAny(t *testing.T) {
var e1, e2, e3 [8]byte
e := createRandomObject(e1)
if v, ok := e.([8]byte); ok {
e1 = v
}
e = createRandomObject(e2)
if v, ok := e.([8]byte); ok {
e2 = v
}
e = createRandomObject(e2)
if v, ok := e.([8]byte); ok {
e3 = v
}

s := New()
if s.Has(e1) {
t.Errorf("expected a new set to not contain %v", e1)
}

s.Add(e1)
s.Add(e2)

if !s.HasAny(e1) {
t.Errorf("expected the set to contain %v", e1)
}
if !s.HasAny(e2) {
t.Errorf("expected the set to contain %v", e2)
}
if s.HasAny(e3) {
t.Errorf("did not expect the set to contain %v", e3)
}
if !s.HasAny(e1, e3) {
t.Errorf("expected the set to contain %v", e1)
}
}

func TestSize(t *testing.T) {
var e1, e2 [8]byte
e := createRandomObject(e1)
Expand Down
13 changes: 13 additions & 0 deletions f32set/f32set.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ func (s *Set) Has(items ...float32) bool {
return has
}

// HasAny looks for the existence of any of the items passed.
// It returns false if nothing is passed.
// For multiple items it returns true if any of the items exist.
func (s *Set) HasAny(items ...float32) bool {
has := false
for _, item := range items {
if _, has = s.m[item]; has {
break
}
}
return has
}

// Size returns the number of items in a Set.
func (s *Set) Size() int {
return len(s.m)
Expand Down
37 changes: 37 additions & 0 deletions f32set/f32set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,43 @@ func TestHas(t *testing.T) {
}
}

func TestHasAny(t *testing.T) {
var e1, e2, e3 float32
e := createRandomObject(e1)
if v, ok := e.(float32); ok {
e1 = v
}
e = createRandomObject(e2)
if v, ok := e.(float32); ok {
e2 = v
}
e = createRandomObject(e2)
if v, ok := e.(float32); ok {
e3 = v
}

s := New()
if s.Has(e1) {
t.Errorf("expected a new set to not contain %v", e1)
}

s.Add(e1)
s.Add(e2)

if !s.HasAny(e1) {
t.Errorf("expected the set to contain %v", e1)
}
if !s.HasAny(e2) {
t.Errorf("expected the set to contain %v", e2)
}
if s.HasAny(e3) {
t.Errorf("did not expect the set to contain %v", e3)
}
if !s.HasAny(e1, e3) {
t.Errorf("expected the set to contain %v", e1)
}
}

func TestSize(t *testing.T) {
var e1, e2 float32
e := createRandomObject(e1)
Expand Down
13 changes: 13 additions & 0 deletions f64set/f64set.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ func (s *Set) Has(items ...float64) bool {
return has
}

// HasAny looks for the existence of any of the items passed.
// It returns false if nothing is passed.
// For multiple items it returns true if any of the items exist.
func (s *Set) HasAny(items ...float64) bool {
has := false
for _, item := range items {
if _, has = s.m[item]; has {
break
}
}
return has
}

// Size returns the number of items in a Set.
func (s *Set) Size() int {
return len(s.m)
Expand Down
37 changes: 37 additions & 0 deletions f64set/f64set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,43 @@ func TestHas(t *testing.T) {
}
}

func TestHasAny(t *testing.T) {
var e1, e2, e3 float64
e := createRandomObject(e1)
if v, ok := e.(float64); ok {
e1 = v
}
e = createRandomObject(e2)
if v, ok := e.(float64); ok {
e2 = v
}
e = createRandomObject(e2)
if v, ok := e.(float64); ok {
e3 = v
}

s := New()
if s.Has(e1) {
t.Errorf("expected a new set to not contain %v", e1)
}

s.Add(e1)
s.Add(e2)

if !s.HasAny(e1) {
t.Errorf("expected the set to contain %v", e1)
}
if !s.HasAny(e2) {
t.Errorf("expected the set to contain %v", e2)
}
if s.HasAny(e3) {
t.Errorf("did not expect the set to contain %v", e3)
}
if !s.HasAny(e1, e3) {
t.Errorf("expected the set to contain %v", e1)
}
}

func TestSize(t *testing.T) {
var e1, e2 float64
e := createRandomObject(e1)
Expand Down
Loading

0 comments on commit e560bb8

Please sign in to comment.