-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for Unit method of XY
It was untested by any existing unit tests (and is not used internally anywhere). We don't want to remove it though, since it's part of the public API. So I added some unit tests instead.
- Loading branch information
1 parent
145d718
commit 4b383d3
Showing
3 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package geom_test | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
|
||
"github.com/peterstace/simplefeatures/geom" | ||
) | ||
|
||
func TestXYUnit(t *testing.T) { | ||
sqrt2 := math.Sqrt(2) | ||
sqrt5 := math.Sqrt(5) | ||
for _, tc := range []struct { | ||
description string | ||
input geom.XY | ||
output geom.XY | ||
}{ | ||
{ | ||
description: "+ve unit in X", | ||
input: geom.XY{X: 1}, | ||
output: geom.XY{X: 1}, | ||
}, | ||
{ | ||
description: "+ve unit in Y", | ||
input: geom.XY{Y: 1}, | ||
output: geom.XY{Y: 1}, | ||
}, | ||
{ | ||
description: "-ve unit in X", | ||
input: geom.XY{X: -1}, | ||
output: geom.XY{X: -1}, | ||
}, | ||
{ | ||
description: "-ve unit in Y", | ||
input: geom.XY{Y: -1}, | ||
output: geom.XY{Y: -1}, | ||
}, | ||
{ | ||
description: "non-aligned unit", | ||
input: geom.XY{X: -1 / sqrt2, Y: 1 / sqrt2}, | ||
output: geom.XY{X: -1 / sqrt2, Y: 1 / sqrt2}, | ||
}, | ||
{ | ||
description: "non-unit", | ||
input: geom.XY{X: 1, Y: -2}, | ||
output: geom.XY{X: 1 / sqrt5, Y: -2 / sqrt5}, | ||
}, | ||
} { | ||
t.Run(tc.description, func(t *testing.T) { | ||
got := tc.input.Unit() | ||
expectXYWithinTolerance(t, got, tc.output, 0.0000001) | ||
}) | ||
} | ||
} |