Skip to content

Commit 54c82c3

Browse files
committed
Make public Assert helper methods
1 parent c5ad676 commit 54c82c3

File tree

10 files changed

+276
-276
lines changed

10 files changed

+276
-276
lines changed

circle_test.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,38 @@ var (
1414
)
1515

1616
func TestCircle_New(t *testing.T) {
17-
assertCircle(t, Circ(Pt(10, 16), 12), 10, 16, 12)
18-
assertCircle(t, Circ(Pt(0.16, 204), 5.1), 0.16, 204.0, 5.1)
17+
AssertCircle(t, Circ(Pt(10, 16), 12), 10, 16, 12)
18+
AssertCircle(t, Circ(Pt(0.16, 204), 5.1), 0.16, 204.0, 5.1)
1919
}
2020

2121
func TestCircle_Translate(t *testing.T) {
22-
assertCircle(t, circleInt.Translate(Vec(3, -2)), 4, 0, 10)
23-
assertCircle(t, circleFloat.Translate(Vec(100.1, -0.1)), 100.7, -0.35, 1.2)
22+
AssertCircle(t, circleInt.Translate(Vec(3, -2)), 4, 0, 10)
23+
AssertCircle(t, circleFloat.Translate(Vec(100.1, -0.1)), 100.7, -0.35, 1.2)
2424
}
2525

2626
func TestCircle_MoveTo(t *testing.T) {
27-
assertCircle(t, circleInt.MoveTo(Pt(3, -2)), 3, -2, 10)
28-
assertCircle(t, circleFloat.MoveTo(Pt(100.1, -0.1)), 100.1, -0.1, 1.2)
27+
AssertCircle(t, circleInt.MoveTo(Pt(3, -2)), 3, -2, 10)
28+
AssertCircle(t, circleFloat.MoveTo(Pt(100.1, -0.1)), 100.1, -0.1, 1.2)
2929
}
3030

3131
func TestCircle_Scale(t *testing.T) {
32-
assertCircle(t, circleInt.Scale(2.5), 1, 2, 25)
33-
assertCircle(t, circleFloat.Scale(2.5), 0.6, -0.25, 3.0)
32+
AssertCircle(t, circleInt.Scale(2.5), 1, 2, 25)
33+
AssertCircle(t, circleFloat.Scale(2.5), 0.6, -0.25, 3.0)
3434
}
3535

3636
func TestCircle_Resize(t *testing.T) {
37-
assertCircle(t, circleInt.Resize(8), 1, 2, 8)
38-
assertCircle(t, circleFloat.Resize(3.1), 0.6, -0.25, 3.1)
37+
AssertCircle(t, circleInt.Resize(8), 1, 2, 8)
38+
AssertCircle(t, circleFloat.Resize(3.1), 0.6, -0.25, 3.1)
3939
}
4040

4141
func TestCircle_Grow(t *testing.T) {
42-
assertCircle(t, circleInt.Grow(8), 1, 2, 18)
43-
assertCircle(t, circleFloat.Grow(3.1), 0.6, -0.25, 4.3)
42+
AssertCircle(t, circleInt.Grow(8), 1, 2, 18)
43+
AssertCircle(t, circleFloat.Grow(3.1), 0.6, -0.25, 4.3)
4444
}
4545

4646
func TestCircle_Shrink(t *testing.T) {
47-
assertCircle(t, circleInt.Shrink(8), 1, 2, 2)
48-
assertCircle(t, circleFloat.Shrink(0.3), 0.6, -0.25, 0.9)
47+
AssertCircle(t, circleInt.Shrink(8), 1, 2, 2)
48+
AssertCircle(t, circleFloat.Shrink(0.3), 0.6, -0.25, 0.9)
4949
}
5050

5151
func TestCircle_Area(t *testing.T) {
@@ -64,8 +64,8 @@ func TestCircle_Diameter(t *testing.T) {
6464
}
6565

6666
func TestCircle_Bounds(t *testing.T) {
67-
assertRect(t, circleInt.Bounds(), 1, 2, 10, 10)
68-
assertRect(t, circleFloat.Bounds(), 0.6, -0.25, 1.2, 1.2)
67+
AssertRect(t, circleInt.Bounds(), 1, 2, 10, 10)
68+
AssertRect(t, circleFloat.Bounds(), 0.6, -0.25, 1.2, 1.2)
6969
}
7070

7171
func TestCircle_Equal(t *testing.T) {
@@ -100,13 +100,13 @@ func TestCircle_Contains(t *testing.T) {
100100
}
101101

102102
func TestCircle_Int(t *testing.T) {
103-
assertCircle(t, circleInt.Int(), 1, 2, 10)
104-
assertCircle(t, circleFloat.Int(), 1, 0, 1)
103+
AssertCircle(t, circleInt.Int(), 1, 2, 10)
104+
AssertCircle(t, circleFloat.Int(), 1, 0, 1)
105105
}
106106

107107
func TestCircle_Float(t *testing.T) {
108-
assertCircle(t, circleInt.Float(), 1.0, 2.0, 10.0)
109-
assertCircle(t, circleFloat.Float(), 0.6, -0.25, 1.2)
108+
AssertCircle(t, circleInt.Float(), 1.0, 2.0, 10.0)
109+
AssertCircle(t, circleFloat.Float(), 0.6, -0.25, 1.2)
110110
}
111111

112112
func TestCircle_String(t *testing.T) {
@@ -122,11 +122,11 @@ func TestCircle_Marshall(t *testing.T) {
122122
func TestCircle_Unmarshall(t *testing.T) {
123123
var p1 Circle[int]
124124
assert.NoError(t, json.Unmarshal([]byte(`{"x":10,"y":16,"r":12}`), &p1))
125-
assertCircle(t, p1, 10, 16, 12)
125+
AssertCircle(t, p1, 10, 16, 12)
126126

127127
var p2 Circle[float64]
128128
assert.NoError(t, json.Unmarshal([]byte(`{"x":10.1,"y":-34.0000115,"r":0.2}`), &p2))
129-
assertCircle(t, p2, 10.1, -34.0000115, 0.2)
129+
AssertCircle(t, p2, 10.1, -34.0000115, 0.2)
130130
}
131131

132132
func TestCircle_Immutable(t *testing.T) {
@@ -139,18 +139,18 @@ func TestCircle_Immutable(t *testing.T) {
139139
c1.Grow(1)
140140
c1.Shrink(2)
141141

142-
assertCircle(t, c1, 1, 2, 10)
142+
AssertCircle(t, c1, 1, 2, 10)
143143
}
144144

145-
func assertCircle[T Number](t *testing.T, c Circle[T], x, y, radius T) bool {
145+
func AssertCircle[T Number](t *testing.T, c Circle[T], x, y, radius T, messages ...string) bool {
146146
t.Helper()
147147

148148
ok := true
149149

150-
if !assertPoint(t, c.Center, x, y, "Center.") {
150+
if !AssertPoint(t, c.Center, x, y, append(messages, "Center.")...) {
151151
ok = false
152152
}
153-
if !assert.EqualDelta(t, float64(c.Radius), float64(radius), Delta, "Radius: ") {
153+
if !assert.EqualDelta(t, float64(c.Radius), float64(radius), Delta, append(messages, "Radius: ")...) {
154154
ok = false
155155
}
156156

image_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
)
99

1010
func TestPoint_NewFromImage(t *testing.T) {
11-
assertPoint(t, PointFromImage[int](image.Pt(1, 2)), 1, 2)
12-
assertPoint(t, PointFromImage[float64](image.Pt(1, 2)), 1.0, 2.0)
11+
AssertPoint(t, PointFromImage[int](image.Pt(1, 2)), 1, 2)
12+
AssertPoint(t, PointFromImage[float64](image.Pt(1, 2)), 1.0, 2.0)
1313
}
1414

1515
func TestPoint_Point(t *testing.T) {
@@ -23,11 +23,11 @@ func TestRectangle_Rectangle(t *testing.T) {
2323
}
2424

2525
func TestSize_NewFromImage(t *testing.T) {
26-
assertSize(t, SizeFromImage[int](image.Rect(0, 10, 55, 70)), 55, 60)
27-
assertSize(t, SizeFromImage[float64](image.Rect(0, 10, 55, 70)), 55.0, 60.0)
26+
AssertSize(t, SizeFromImage[int](image.Rect(0, 10, 55, 70)), 55, 60)
27+
AssertSize(t, SizeFromImage[float64](image.Rect(0, 10, 55, 70)), 55.0, 60.0)
2828
}
2929

3030
func TestRectangle_NewFromImage(t *testing.T) {
31-
assertRect(t, RectFromImage[int](image.Rect(0, 10, 55, 70)), 27, 40, 55, 60)
32-
assertRect(t, RectFromImage[float64](image.Rect(0, 10, 55, 70)), 27.5, 40, 55, 60)
31+
AssertRect(t, RectFromImage[int](image.Rect(0, 10, 55, 70)), 27, 40, 55, 60)
32+
AssertRect(t, RectFromImage[float64](image.Rect(0, 10, 55, 70)), 27.5, 40, 55, 60)
3333
}

line_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@ var (
1414
)
1515

1616
func TestLine_New(t *testing.T) {
17-
assertLine(t, Ln(Pt(1, -1), Pt(2, 0)), 1, -1, 2, 0)
18-
assertLine(t, Ln(Pt(0.5, -1.25), Pt(2.5, 3.75)), 0.5, -1.25, 2.5, 3.75)
17+
AssertLine(t, Ln(Pt(1, -1), Pt(2, 0)), 1, -1, 2, 0)
18+
AssertLine(t, Ln(Pt(0.5, -1.25), Pt(2.5, 3.75)), 0.5, -1.25, 2.5, 3.75)
1919
}
2020

2121
func TestLine_Translate(t *testing.T) {
22-
assertLine(t, lineInt.Translate(Vec(3, -2)), 4, 0, 6, 3)
23-
assertLine(t, lineFloat.Translate(Vec(100.1, -0.1)), 100.7, -0.35, 101.3, 3.3)
22+
AssertLine(t, lineInt.Translate(Vec(3, -2)), 4, 0, 6, 3)
23+
AssertLine(t, lineFloat.Translate(Vec(100.1, -0.1)), 100.7, -0.35, 101.3, 3.3)
2424
}
2525

2626
func TestLine_MoveTo(t *testing.T) {
27-
assertLine(t, lineInt.MoveTo(Pt(3, -2)), 3, -2, 5, 1)
28-
assertLine(t, lineFloat.MoveTo(Pt(100.1, -0.1)), 100.1, -0.1, 100.7, 3.55)
27+
AssertLine(t, lineInt.MoveTo(Pt(3, -2)), 3, -2, 5, 1)
28+
AssertLine(t, lineFloat.MoveTo(Pt(100.1, -0.1)), 100.1, -0.1, 100.7, 3.55)
2929
}
3030

3131
func TestLine_Reversed(t *testing.T) {
32-
assertLine(t, lineInt.Reversed(), 3, 5, 1, 2)
33-
assertLine(t, lineFloat.Reversed(), 1.2, 3.4, 0.6, -0.25)
32+
AssertLine(t, lineInt.Reversed(), 3, 5, 1, 2)
33+
AssertLine(t, lineFloat.Reversed(), 1.2, 3.4, 0.6, -0.25)
3434
}
3535

3636
func TestLine_Midpoint(t *testing.T) {
37-
assertPoint(t, lineInt.Midpoint(), 2, 4)
38-
assertPoint(t, lineFloat.Midpoint(), 0.9, 1.575)
37+
AssertPoint(t, lineInt.Midpoint(), 2, 4)
38+
AssertPoint(t, lineFloat.Midpoint(), 0.9, 1.575)
3939
}
4040

4141
func TestLine_Direction(t *testing.T) {
42-
assertVector(t, lineInt.Direction(), 2, 3)
43-
assertVector(t, lineFloat.Direction(), 0.6, 3.65)
42+
AssertVector(t, lineInt.Direction(), 2, 3)
43+
AssertVector(t, lineFloat.Direction(), 0.6, 3.65)
4444
}
4545

4646
func TestLine_Length(t *testing.T) {
@@ -49,11 +49,11 @@ func TestLine_Length(t *testing.T) {
4949
}
5050

5151
func TestLine_Bounds(t *testing.T) {
52-
assertRect(t, lineInt.Bounds(), 2, 3, 2, 3)
52+
AssertRect(t, lineInt.Bounds(), 2, 3, 2, 3)
5353
assert.Equal(t, lineInt.Start, lineInt.Bounds().Min())
5454
assert.Equal(t, lineInt.End, lineInt.Bounds().Max())
5555

56-
assertRect(t, lineFloat.Bounds(), 0.9, 1.575, 0.6, 3.65)
56+
AssertRect(t, lineFloat.Bounds(), 0.9, 1.575, 0.6, 3.65)
5757
}
5858

5959
func TestLine_Equal(t *testing.T) {
@@ -76,13 +76,13 @@ func TestLine_IsZero(t *testing.T) {
7676
}
7777

7878
func TestLine_Int(t *testing.T) {
79-
assertLine(t, lineInt.Int(), 1, 2, 3, 5)
80-
assertLine(t, lineFloat.Int(), 1, 0, 1, 3)
79+
AssertLine(t, lineInt.Int(), 1, 2, 3, 5)
80+
AssertLine(t, lineFloat.Int(), 1, 0, 1, 3)
8181
}
8282

8383
func TestLine_Float(t *testing.T) {
84-
assertLine(t, lineInt.Float(), 1.0, 2.0, 3.0, 5.0)
85-
assertLine(t, lineFloat.Float(), 0.6, -0.25, 1.2, 3.4)
84+
AssertLine(t, lineInt.Float(), 1.0, 2.0, 3.0, 5.0)
85+
AssertLine(t, lineFloat.Float(), 0.6, -0.25, 1.2, 3.4)
8686
}
8787

8888
func TestLine_String(t *testing.T) {
@@ -115,15 +115,15 @@ func TestLine_Immutable(t *testing.T) {
115115
assert.True(t, l.Equal(lineInt))
116116
}
117117

118-
func assertLine[T Number](t *testing.T, l Line[T], sx, sy, ex, ey T) bool {
118+
func AssertLine[T Number](t *testing.T, l Line[T], sx, sy, ex, ey T, messages ...string) bool {
119119
t.Helper()
120120

121121
ok := true
122122

123-
if !assertPoint(t, l.Start, sx, sy, "Start.") {
123+
if !AssertPoint(t, l.Start, sx, sy, append(messages, "Start.")...) {
124124
ok = false
125125
}
126-
if !assertPoint(t, l.End, ex, ey, "End.") {
126+
if !AssertPoint(t, l.End, ex, ey, append(messages, "End.")...) {
127127
ok = false
128128
}
129129

padding_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ var (
1313
)
1414

1515
func TestPadding_New(t *testing.T) {
16-
assertPadding(t, paddingInt, 2, 4, 3, 5)
17-
assertPadding(t, paddingFloat, 0.1, 3.0, 0.6, 2.4)
16+
AssertPadding(t, paddingInt, 2, 4, 3, 5)
17+
AssertPadding(t, paddingFloat, 0.1, 3.0, 0.6, 2.4)
1818

19-
assertPadding(t, PadU(20.0), 20.0, 20.0, 20.0, 20.0)
20-
assertPadding(t, PadXY(10.0, 20.0), 10.0, 20.0, 10.0, 20.0)
19+
AssertPadding(t, PadU(20.0), 20.0, 20.0, 20.0, 20.0)
20+
AssertPadding(t, PadXY(10.0, 20.0), 10.0, 20.0, 10.0, 20.0)
2121
}
2222

2323
func TestPadding_Width(t *testing.T) {
@@ -41,18 +41,18 @@ func TestPadding_XY(t *testing.T) {
4141
}
4242

4343
func TestPadding_Size(t *testing.T) {
44-
assertSize(t, paddingInt.Size(), 9, 5)
45-
assertSize(t, paddingFloat.Size(), 5.4, 0.7)
44+
AssertSize(t, paddingInt.Size(), 9, 5)
45+
AssertSize(t, paddingFloat.Size(), 5.4, 0.7)
4646
}
4747

4848
func TestPadding_Int(t *testing.T) {
49-
assertPadding(t, paddingInt.Int(), 2, 4, 3, 5)
50-
assertPadding(t, paddingFloat.Int(), 0, 3, 1, 2)
49+
AssertPadding(t, paddingInt.Int(), 2, 4, 3, 5)
50+
AssertPadding(t, paddingFloat.Int(), 0, 3, 1, 2)
5151
}
5252

5353
func TestPadding_Float(t *testing.T) {
54-
assertPadding(t, paddingInt.Float(), 2.0, 4.0, 3.0, 5.0)
55-
assertPadding(t, paddingFloat.Float(), 0.1, 3.0, 0.6, 2.4)
54+
AssertPadding(t, paddingInt.Float(), 2.0, 4.0, 3.0, 5.0)
55+
AssertPadding(t, paddingFloat.Float(), 0.1, 3.0, 0.6, 2.4)
5656
}
5757

5858
func TestPadding_String(t *testing.T) {
@@ -68,28 +68,28 @@ func TestPadding_Marshall(t *testing.T) {
6868
func TestPadding_Unmarshall(t *testing.T) {
6969
var p1 Padding[int]
7070
assert.NoError(t, json.Unmarshal([]byte(`{"t":2,"r":4,"b":3,"l":5}`), &p1))
71-
assertPadding(t, p1, 2, 4, 3, 5)
71+
AssertPadding(t, p1, 2, 4, 3, 5)
7272

7373
var p2 Padding[float64]
7474
assert.NoError(t, json.Unmarshal([]byte(`{"t":0.10,"r":3,"b":0.60,"l":2.40}`), &p2))
75-
assertPadding(t, p2, 0.1, 3.0, 0.6, 2.4)
75+
AssertPadding(t, p2, 0.1, 3.0, 0.6, 2.4)
7676
}
7777

78-
func assertPadding[T Number](t *testing.T, p Padding[T], top, right, bottom, left T) bool {
78+
func AssertPadding[T Number](t *testing.T, p Padding[T], top, right, bottom, left T, messages ...string) bool {
7979
t.Helper()
8080

8181
ok := true
8282

83-
if !assert.EqualDelta(t, float64(p.Top), float64(top), Delta, "Top: ") {
83+
if !assert.EqualDelta(t, float64(p.Top), float64(top), Delta, append(messages, "Top: ")...) {
8484
ok = false
8585
}
86-
if !assert.EqualDelta(t, float64(p.Right), float64(right), Delta, "Right: ") {
86+
if !assert.EqualDelta(t, float64(p.Right), float64(right), Delta, append(messages, "Right: ")...) {
8787
ok = false
8888
}
89-
if !assert.EqualDelta(t, float64(p.Bottom), float64(bottom), Delta, "Bottom: ") {
89+
if !assert.EqualDelta(t, float64(p.Bottom), float64(bottom), Delta, append(messages, "Bottom: ")...) {
9090
ok = false
9191
}
92-
if !assert.EqualDelta(t, float64(p.Left), float64(left), Delta, "Left: ") {
92+
if !assert.EqualDelta(t, float64(p.Left), float64(left), Delta, append(messages, "Left: ")...) {
9393
ok = false
9494
}
9595

0 commit comments

Comments
 (0)