File: subset_test.go

package info (click to toggle)
golang-github-facebookgo-subset 0.0~git20150612.0.8dac2c3-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 84 kB
  • sloc: makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,460 bytes parent folder | download | duplicates (3)
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
59
60
61
62
package subset

import (
	"testing"
)

type test struct {
	Name string
	A    interface{}
	B    interface{}
}

type sample struct {
	Answer  int
	Name    string
	Child   *sample
	private string
}

var (
	subsetTests = []test{
		test{"Integers", 1, 1},
		test{"Strings", "a", "a"},
		test{"Maps",
			map[string]string{"foo": "bar"},
			map[string]string{"foo": "bar"}},
		test{"Maps subset",
			map[string]string{"foo": "bar"},
			map[string]string{"foo": "bar", "answer": "42"}},
		test{"Nil map", nil, map[string]string{"foo": "bar"}},
		test{"Structs", sample{Answer: 1}, sample{Answer: 1}},
		test{"Struct subset", sample{Answer: 1}, sample{Answer: 1, Name: "a"}},
		test{"Nil pointer", sample{}, sample{Child: &sample{}}},
	}
	notSubsetTests = []test{
		test{"Integer", 1, 2},
		test{"Integers of different types", uint(1), int(1)},
		test{"Maps not subset",
			map[string]string{"foo": "bar", "answer": "42"},
			map[string]string{"foo": "bar"}},
		test{"Structs", sample{Answer: 1}, sample{Answer: 2}},
		test{"Struct subset",
			sample{Answer: 1, Name: "b"},
			sample{Answer: 1, Name: "a"}},
	}
)

func TestSubsets(t *testing.T) {
	for _, d := range subsetTests {
		if !Check(d.A, d.B) {
			t.Errorf("Was expecting \"%s\" Check(%v, %v) == true.", d.Name, d.A, d.B)
		}
	}
}

func TestNotSubsets(t *testing.T) {
	for _, d := range notSubsetTests {
		if Check(d.A, d.B) {
			t.Errorf("Was expecting %s Check(%v, %v) == false.", d.Name, d.A, d.B)
		}
	}
}