Skip to content

Commit bd4a2df

Browse files
committed
Move Assert helper methods to geom package
1 parent e6eb134 commit bd4a2df

File tree

11 files changed

+182
-169
lines changed

11 files changed

+182
-169
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

88

9-
## [Unreleased](https://github.com/gravitton/geometry/compare/v1.1.0...master)
9+
## [Unreleased](https://github.com/gravitton/geometry/compare/v1.1.1...master)
10+
11+
12+
## [v1.1.1 (2025-10-27)](https://github.com/gravitton/geometry/compare/v1.1.0...v1.1.1)
13+
### Fixed
14+
- Move Assert helper methods to `geom` package
1015

1116

1217
## [v1.1.0 (2025-10-27)](https://github.com/gravitton/geometry/compare/v1.0.0...v1.1.0)

circle_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,3 @@ func TestCircle_Immutable(t *testing.T) {
141141

142142
AssertCircle(t, c1, 1, 2, 10)
143143
}
144-
145-
func AssertCircle[T Number](t *testing.T, c Circle[T], x, y, radius T, messages ...string) bool {
146-
t.Helper()
147-
148-
ok := true
149-
150-
if !AssertPoint(t, c.Center, x, y, append(messages, "Center.")...) {
151-
ok = false
152-
}
153-
if !assert.EqualDelta(t, float64(c.Radius), float64(radius), Delta, append(messages, "Radius: ")...) {
154-
ok = false
155-
}
156-
157-
return ok
158-
}

line_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,3 @@ func TestLine_Immutable(t *testing.T) {
114114

115115
assert.True(t, l.Equal(lineInt))
116116
}
117-
118-
func AssertLine[T Number](t *testing.T, l Line[T], sx, sy, ex, ey T, messages ...string) bool {
119-
t.Helper()
120-
121-
ok := true
122-
123-
if !AssertPoint(t, l.Start, sx, sy, append(messages, "Start.")...) {
124-
ok = false
125-
}
126-
if !AssertPoint(t, l.End, ex, ey, append(messages, "End.")...) {
127-
ok = false
128-
}
129-
130-
return ok
131-
}

padding_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,3 @@ func TestPadding_Unmarshall(t *testing.T) {
7474
assert.NoError(t, json.Unmarshal([]byte(`{"t":0.10,"r":3,"b":0.60,"l":2.40}`), &p2))
7575
AssertPadding(t, p2, 0.1, 3.0, 0.6, 2.4)
7676
}
77-
78-
func AssertPadding[T Number](t *testing.T, p Padding[T], top, right, bottom, left T, messages ...string) bool {
79-
t.Helper()
80-
81-
ok := true
82-
83-
if !assert.EqualDelta(t, float64(p.Top), float64(top), Delta, append(messages, "Top: ")...) {
84-
ok = false
85-
}
86-
if !assert.EqualDelta(t, float64(p.Right), float64(right), Delta, append(messages, "Right: ")...) {
87-
ok = false
88-
}
89-
if !assert.EqualDelta(t, float64(p.Bottom), float64(bottom), Delta, append(messages, "Bottom: ")...) {
90-
ok = false
91-
}
92-
if !assert.EqualDelta(t, float64(p.Left), float64(left), Delta, append(messages, "Left: ")...) {
93-
ok = false
94-
}
95-
96-
return ok
97-
}

point_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,3 @@ func TestPoint_Immutable(t *testing.T) {
157157
AssertPoint(t, p1, 1, 2)
158158
AssertPoint(t, p2, 3, -3)
159159
}
160-
161-
func AssertPoint[T Number](t *testing.T, p Point[T], x, y T, messages ...string) bool {
162-
t.Helper()
163-
164-
ok := true
165-
166-
if !assert.EqualDelta(t, float64(p.X), float64(x), Delta, append(messages, "X: ")...) {
167-
ok = false
168-
}
169-
if !assert.EqualDelta(t, float64(p.Y), float64(y), Delta, append(messages, "Y: ")...) {
170-
ok = false
171-
}
172-
173-
return ok
174-
}

polygon_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,3 @@ func TestPolygon_Unmarshall(t *testing.T) {
134134
assert.NoError(t, json.Unmarshal([]byte(`[{"x":0,"y":0},{"x":2.5,"y":0.5},{"x":2,"y":1}]`), &p2))
135135
AssertPolygon(t, p2, nil)
136136
}
137-
138-
func AssertPolygon[T Number](t *testing.T, p Polygon[T], vertices []Point[T], messages ...string) bool {
139-
t.Helper()
140-
141-
return AssertVertices(t, p.Vertices, vertices, messages...)
142-
}
143-
144-
func AssertVertices[T Number](t *testing.T, vertices []Point[T], points []Point[T], messages ...string) bool {
145-
t.Helper()
146-
147-
if !assert.Equal(t, len(vertices), len(points), append(messages, "Length: ")...) {
148-
return false
149-
}
150-
151-
ok := true
152-
for i := 0; i < len(vertices); i++ {
153-
if !AssertPoint(t, vertices[i], points[i].X, points[i].Y, append(messages, fmt.Sprintf("#%d.", i))...) {
154-
ok = false
155-
}
156-
}
157-
158-
return ok
159-
}

rectangle_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,3 @@ func TestRectangle_Immutable(t *testing.T) {
235235

236236
AssertRect(t, r, 1, 2, 2, 3)
237237
}
238-
239-
func AssertRect[T Number](t *testing.T, r Rectangle[T], cx, cy, w, h T, messages ...string) bool {
240-
t.Helper()
241-
242-
ok := true
243-
244-
if !AssertPoint(t, r.Center, cx, cy, append(messages, "Center.")...) {
245-
ok = false
246-
}
247-
if !AssertSize(t, r.Size, w, h, append(messages, "Size.")...) {
248-
ok = false
249-
}
250-
251-
return ok
252-
}

regular_polygon_test.go

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ var (
1414

1515
func TestRegularPolygon_New(t *testing.T) {
1616
rp := RegPol(Pt(0, 0), Sz(2, 2), 4, 0)
17-
assertRegularPolygon(t, rp, 0, 0, 2, 2, 4, 0)
17+
AssertRegularPolygon(t, rp, 0, 0, 2, 2, 4, 0)
1818

1919
triangle := Triangle(Pt(1, -1), Sz(3, 3), PointTop)
20-
assertRegularPolygon(t, triangle, 1, -1, 3, 3, 3, RegularPolygonAngle(3, PointTop))
20+
AssertRegularPolygon(t, triangle, 1, -1, 3, 3, 3, RegularPolygonAngle(3, PointTop))
2121
//AssertVertices(t, triangle.Vertices(), []Point[float64]{{0, 0}})
2222

2323
square := Square(Pt(50.0, 50.0), Sz(100.0, 100.0), PointTop)
24-
assertRegularPolygon(t, square, 50, 50, 100, 100, 4, RegularPolygonAngle(4, PointTop))
24+
AssertRegularPolygon(t, square, 50, 50, 100, 100, 4, RegularPolygonAngle(4, PointTop))
2525
//AssertVertices(t, square.Vertices(), []Point[float64]{{0, 0}})
2626

2727
hexagon := Hexagon(Pt(0, 0), Sz(10, 10), PointTop)
28-
assertRegularPolygon(t, hexagon, 0, 0, 10, 10, 6, RegularPolygonAngle(6, PointTop))
28+
AssertRegularPolygon(t, hexagon, 0, 0, 10, 10, 6, RegularPolygonAngle(6, PointTop))
2929
//AssertVertices(t, hexagon.Vertices(), []Point[float64]{{0, 0}})
3030
}
3131

@@ -41,20 +41,20 @@ func TestRegularPolygonAngle(t *testing.T) {
4141
}
4242

4343
func TestRegularPolygon_Translate(t *testing.T) {
44-
assertRegularPolygon(t, regPolygonInt.Translate(Vec(1, -2)), 2, 0, 2, 2, 4, 0)
44+
AssertRegularPolygon(t, regPolygonInt.Translate(Vec(1, -2)), 2, 0, 2, 2, 4, 0)
4545
}
4646

4747
func TestRegularPolygon_MoveTo(t *testing.T) {
48-
assertRegularPolygon(t, regPolygonInt.MoveTo(Pt(-3, 5)), -3, 5, 2, 2, 4, 0)
48+
AssertRegularPolygon(t, regPolygonInt.MoveTo(Pt(-3, 5)), -3, 5, 2, 2, 4, 0)
4949
}
5050

5151
func TestRegularPolygon_Scale(t *testing.T) {
52-
assertRegularPolygon(t, regPolygonInt.Scale(0.5), 1, 2, 1, 1, 4, 0)
53-
assertRegularPolygon(t, regPolygonInt.ScaleXY(2, 3), 1, 2, 4, 6, 4, 0)
52+
AssertRegularPolygon(t, regPolygonInt.Scale(0.5), 1, 2, 1, 1, 4, 0)
53+
AssertRegularPolygon(t, regPolygonInt.ScaleXY(2, 3), 1, 2, 4, 6, 4, 0)
5454
}
5555

5656
func TestRegularPolygon_Rotate(t *testing.T) {
57-
assertRegularPolygon(t, regPolygonInt.Rotate(math.Pi), 1, 2, 2, 2, 4, math.Pi)
57+
AssertRegularPolygon(t, regPolygonInt.Rotate(math.Pi), 1, 2, 2, 2, 4, math.Pi)
5858
}
5959

6060
func TestRegularPolygon_Vertices(t *testing.T) {
@@ -110,11 +110,11 @@ func TestRegularPolygon_Empty(t *testing.T) {
110110
}
111111

112112
func TestRegularPolygon_Int(t *testing.T) {
113-
assertRegularPolygon(t, regPolygonInt.Int(), 1, 2, 2, 2, 4, 0.0)
113+
AssertRegularPolygon(t, regPolygonInt.Int(), 1, 2, 2, 2, 4, 0.0)
114114
}
115115

116116
func TestRegularPolygon_Float(t *testing.T) {
117-
assertRegularPolygon(t, regPolygonInt.Float(), 1.0, 2.0, 2.0, 2.0, 4, 0.0)
117+
AssertRegularPolygon(t, regPolygonInt.Float(), 1.0, 2.0, 2.0, 2.0, 4, 0.0)
118118
}
119119

120120
func TestRegularPolygon_Immutable(t *testing.T) {
@@ -125,7 +125,7 @@ func TestRegularPolygon_Immutable(t *testing.T) {
125125
rp.Scale(2)
126126
rp.ScaleXY(2, 3)
127127

128-
assertRegularPolygon(t, rp, 0, 1, 2, 3, 4, 0)
128+
AssertRegularPolygon(t, rp, 0, 1, 2, 3, 4, 0)
129129
}
130130

131131
func TestRegularPolygon_String(t *testing.T) {
@@ -139,26 +139,5 @@ func TestRegularPolygon_Marshall(t *testing.T) {
139139
func TestRegularPolygon_Unmarshall(t *testing.T) {
140140
var p1 RegularPolygon[int]
141141
assert.NoError(t, json.Unmarshal([]byte(`{"x":1,"y":2,"w":2,"h":2,"n":4,"a":0}`), &p1))
142-
assertRegularPolygon(t, p1, 1, 2, 2, 2, 4, 0)
143-
}
144-
145-
func assertRegularPolygon[T Number](t *testing.T, p RegularPolygon[T], x, y, w, h T, n int, angle float64, messages ...string) bool {
146-
t.Helper()
147-
148-
ok := true
149-
150-
if !AssertPoint(t, p.Center, x, y, append(messages, "Center.")...) {
151-
ok = false
152-
}
153-
if !AssertSize(t, p.Size, w, h, append(messages, "Size.")...) {
154-
ok = false
155-
}
156-
if !assert.Equal(t, p.N, n, append(messages, "N: ")...) {
157-
ok = false
158-
}
159-
if !assert.EqualDelta(t, p.Angle, angle, Delta, append(messages, "Angle: ")...) {
160-
ok = false
161-
}
162-
163-
return ok
142+
AssertRegularPolygon(t, p1, 1, 2, 2, 2, 4, 0)
164143
}

size_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,3 @@ func TestSize_Immutable(t *testing.T) {
120120

121121
AssertSize(t, s, 2, 3)
122122
}
123-
124-
func AssertSize[T Number](t *testing.T, s Size[T], w, h T, messages ...string) bool {
125-
t.Helper()
126-
127-
ok := true
128-
129-
if !assert.EqualDelta(t, float64(s.Width), float64(w), Delta, append(messages, "Width: ")...) {
130-
ok = false
131-
}
132-
if !assert.EqualDelta(t, float64(s.Height), float64(h), Delta, append(messages, "Height: ")...) {
133-
ok = false
134-
}
135-
136-
return ok
137-
}

0 commit comments

Comments
 (0)