|
| 1 | +package geom |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/gravitton/assert" |
| 5 | + "math" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +func TestIsInt(t *testing.T) { |
| 10 | + testIsInt(t, 1, true) |
| 11 | + testIsInt(t, -2, true) |
| 12 | + testIsInt(t, 986, true) |
| 13 | + testIsInt(t, 1.0, true) |
| 14 | + testIsInt(t, -2.0, true) |
| 15 | + testIsInt(t, 189.2, false) |
| 16 | + testIsInt(t, -9.3333, false) |
| 17 | + testIsInt(t, 1.000001, false) |
| 18 | + testIsInt(t, 23.0000000, true) |
| 19 | + testIsInt(t, math.NaN(), false) |
| 20 | + testIsInt(t, math.Inf(1), false) |
| 21 | +} |
| 22 | + |
| 23 | +func TestToString(t *testing.T) { |
| 24 | + testToString(t, 3, "+3") |
| 25 | + testToString(t, -2, "-2") |
| 26 | + testToString(t, 0.0000, "+0") |
| 27 | + testToString(t, 1.00, "+1") |
| 28 | + testToString(t, 29.59, "+29.59") |
| 29 | + testToString(t, 1.001, "+1.00") |
| 30 | + testToString(t, 1.009, "+1.01") |
| 31 | + testToString(t, -1.011, "-1.01") |
| 32 | +} |
| 33 | + |
| 34 | +func testIsInt[T Number](t *testing.T, value T, expected bool) { |
| 35 | + t.Helper() |
| 36 | + |
| 37 | + assert.Equal(t, IsInt(value), expected) |
| 38 | +} |
| 39 | + |
| 40 | +func testToString[T Number](t *testing.T, value T, expected string) { |
| 41 | + t.Helper() |
| 42 | + |
| 43 | + assert.Equal(t, ToString(value), expected) |
| 44 | +} |
0 commit comments