Skip to content

Commit

Permalink
Unit test Set NumMatches
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrks committed May 16, 2024
1 parent 11e5a76 commit e493241
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions base/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package base

import (
"fmt"
"sort"
"testing"

Expand Down Expand Up @@ -146,3 +147,56 @@ func TestSetUnmarshal(t *testing.T) {
assert.Equal(t, []string{"foo"}, str.Channels.ToArray())

}

func TestSetNumMatches(t *testing.T) {
tests := []struct {
a, b Set
expected int
}{
{
a: nil,
b: nil,
expected: 0,
},
{
a: SetOf("a", "b", "c"),
b: nil,
expected: 0,
},
{
a: nil,
b: SetOf("a", "b", "c"),
expected: 0,
},
{
a: SetOf("a", "b", "c"),
b: SetOf("a", "b", "c"),
expected: 3,
},
{
a: SetOf("a", "b", "c"),
b: SetOf("a", "c"),
expected: 2,
},
{
a: SetOf("a", "c"),
b: SetOf("a", "b", "c"),
expected: 2,
},
{
a: SetOf("a", "b", "c"),
b: SetOf("a", "y", "c"),
expected: 2,
},
{
a: SetOf("a", "b", "c"),
b: SetOf("x", "y", "z"),
expected: 0,
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%v %v=%v", test.a, test.b, test.expected), func(t *testing.T) {
assert.Equal(t, test.expected, test.a.NumMatches(test.b))
})
}
}

0 comments on commit e493241

Please sign in to comment.