-
Notifications
You must be signed in to change notification settings - Fork 36
/
equal_method_test.go
155 lines (132 loc) · 5.43 KB
/
equal_method_test.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package assertions
import (
"testing"
"github.com/smarty/assertions/internal/unit"
)
func TestEqualityFixture(t *testing.T) {
unit.Run(new(EqualityFixture), t)
}
type EqualityFixture struct {
*unit.Fixture
}
func (this *EqualityFixture) TestNilNil() {
spec := equalityMethodSpecification{}
this.So(spec.assertable(nil, nil), ShouldBeFalse)
}
func (this *EqualityFixture) TestEligible1() {
a := Eligible1{"hi"}
b := Eligible1{"hi"}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeTrue)
this.So(specification.passes(a, b), ShouldBeTrue)
}
func (this *EqualityFixture) TestAreEqual() {
a := Eligible1{"hi"}
b := Eligible1{"hi"}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeTrue)
this.So(specification.passes(a, b), ShouldBeTrue)
}
func (this *EqualityFixture) TestAreNotEqual() {
a := Eligible1{"hi"}
b := Eligible1{"bye"}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeTrue)
this.So(specification.passes(a, b), ShouldBeFalse)
}
func (this *EqualityFixture) TestEligible2() {
a := Eligible2{"hi"}
b := Eligible2{"hi"}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeTrue)
}
func (this *EqualityFixture) TestEligible1_PointerReceiver() {
a := &Eligible1{"hi"}
b := Eligible1{"hi"}
this.So(a.Equal(b), ShouldBeTrue)
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeTrue)
}
func (this *EqualityFixture) TestIneligible_PrimitiveTypes() {
specification := equalityMethodSpecification{}
this.So(specification.assertable(1, 1), ShouldBeFalse)
}
func (this *EqualityFixture) TestIneligible_DisparateTypes() {
a := Eligible1{"hi"}
b := Eligible2{"hi"}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeFalse)
}
func (this *EqualityFixture) TestIneligible_NoEqualMethod() {
a := Ineligible_NoEqualMethod{}
b := Ineligible_NoEqualMethod{}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeFalse)
}
func (this *EqualityFixture) TestIneligible_EqualMethodReceivesNoInput() {
a := Ineligible_EqualMethodNoInputs{}
b := Ineligible_EqualMethodNoInputs{}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeFalse)
}
func (this *EqualityFixture) TestIneligible_EqualMethodReceivesTooManyInputs() {
a := Ineligible_EqualMethodTooManyInputs{}
b := Ineligible_EqualMethodTooManyInputs{}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeFalse)
}
func (this *EqualityFixture) TestIneligible_EqualMethodReceivesWrongInput() {
a := Ineligible_EqualMethodWrongInput{}
b := Ineligible_EqualMethodWrongInput{}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeFalse)
}
func (this *EqualityFixture) TestIneligible_EqualMethodReturnsNoOutputs() {
a := Ineligible_EqualMethodNoOutputs{}
b := Ineligible_EqualMethodNoOutputs{}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeFalse)
}
func (this *EqualityFixture) TestIneligible_EqualMethodReturnsTooManyOutputs() {
a := Ineligible_EqualMethodTooManyOutputs{}
b := Ineligible_EqualMethodTooManyOutputs{}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeFalse)
}
func (this *EqualityFixture) TestIneligible_EqualMethodReturnsWrongOutputs() {
a := Ineligible_EqualMethodWrongOutput{}
b := Ineligible_EqualMethodWrongOutput{}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeFalse)
}
func (this *EqualityFixture) TestEligibleAsymmetric_EqualMethodResultDiffersWhenArgumentsInverted() {
a := EligibleAsymmetric{a: 0}
b := EligibleAsymmetric{a: 1}
specification := equalityMethodSpecification{}
this.So(specification.assertable(a, b), ShouldBeTrue)
this.So(specification.passes(a, b), ShouldBeFalse)
}
/**************************************************************************/
type (
Eligible1 struct{ a string }
Eligible2 struct{ a string }
EligibleAsymmetric struct{ a int }
Ineligible_NoEqualMethod struct{}
Ineligible_EqualMethodNoInputs struct{}
Ineligible_EqualMethodNoOutputs struct{}
Ineligible_EqualMethodTooManyInputs struct{}
Ineligible_EqualMethodTooManyOutputs struct{}
Ineligible_EqualMethodWrongInput struct{}
Ineligible_EqualMethodWrongOutput struct{}
)
func (this Eligible1) Equal(that Eligible1) bool { return this.a == that.a }
func (this Eligible2) Equal(that Eligible2) bool { return this.a == that.a }
func (this EligibleAsymmetric) Equal(that EligibleAsymmetric) bool {
return this.a == 0
}
func (this Ineligible_EqualMethodNoInputs) Equal() bool { return true }
func (this Ineligible_EqualMethodNoOutputs) Equal(that Ineligible_EqualMethodNoOutputs) {}
func (this Ineligible_EqualMethodTooManyInputs) Equal(a, b bool) bool { return true }
func (this Ineligible_EqualMethodTooManyOutputs) Equal(bool) (bool, bool) { return true, true }
func (this Ineligible_EqualMethodWrongInput) Equal(a string) bool { return true }
func (this Ineligible_EqualMethodWrongOutput) Equal(Ineligible_EqualMethodWrongOutput) int { return 0 }