1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
// Copyright 2015 Kevin Gillette. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mapset_test
import (
"testing"
"github.com/xtgo/set/internal/mapset"
"github.com/xtgo/set/internal/testdata"
)
func TestUnion(t *testing.T) { testMut(t, "Union") }
func TestInter(t *testing.T) { testMut(t, "Inter") }
func TestDiff(t *testing.T) { testMut(t, "Diff") }
func TestSymDiff(t *testing.T) { testMut(t, "SymDiff") }
func TestIsSub(t *testing.T) { testBool(t, "IsSub") }
func TestIsSuper(t *testing.T) { testBool(t, "IsSuper") }
func TestIsInter(t *testing.T) { testBool(t, "IsInter") }
func TestIsEqual(t *testing.T) { testBool(t, "IsEqual") }
const format = "%s(%v, %v) = %v, want %v"
type (
mutOp func(a, b mapset.Set) mapset.Set
boolOp func(a, b mapset.Set) bool
)
func testMut(t *testing.T, name string) {
var op mutOp
testdata.ConvMethod(&op, mapset.Set(nil), name)
for _, tt := range testdata.BinTests {
a, b := mapset.New(tt.A), mapset.New(tt.B)
c := op(a, b).Elems()
want := tt.SelSlice(name)
if !testdata.IsEqual(c, want) {
t.Errorf(format, name, tt.A, tt.B, c, want)
}
}
}
func testBool(t *testing.T, name string) {
var op boolOp
testdata.ConvMethod(&op, mapset.Set(nil), name)
for _, tt := range testdata.BinTests {
a, b := mapset.New(tt.A), mapset.New(tt.B)
ok := op(a, b)
want := tt.SelBool(name)
if ok != want {
t.Errorf(format, name, tt.A, tt.B, ok, want)
}
}
}
|