2019-05-30 04:41:04 +00:00
|
|
|
package attribute_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gitlab.codemonkeysoftware.net/b/hatmill/attribute"
|
|
|
|
)
|
|
|
|
|
2019-08-31 18:46:32 +00:00
|
|
|
func TestCoordsList(t *testing.T) {
|
|
|
|
t.Run("String returns empty string for empty list", func(t *testing.T) {
|
|
|
|
expectEqualStrings(t, attribute.CoordsList(nil).String(), "")
|
2019-05-30 04:41:04 +00:00
|
|
|
})
|
2019-08-31 18:46:32 +00:00
|
|
|
|
|
|
|
t.Run("String uses valid number format", func(t *testing.T) {
|
|
|
|
for _, testcase := range []struct {
|
|
|
|
name string
|
|
|
|
f float32
|
|
|
|
s string
|
|
|
|
}{
|
|
|
|
{name: "zero", f: 0, s: "0"},
|
|
|
|
{name: "integral", f: 45, s: "45"},
|
|
|
|
{name: "positive fractional, small positive exponent", f: 12.55, s: "12.55"},
|
2020-05-25 21:18:17 +00:00
|
|
|
{name: "positive fractional, large positive exponent", f: 1.55e+12, s: "1.55E+12"},
|
|
|
|
{name: "positive fractional, large negative exponent", f: 1.55e-12, s: "1.55E-12"},
|
2019-08-31 18:46:32 +00:00
|
|
|
{name: "negative fractional, small positive exponent", f: -12.55, s: "-12.55"},
|
2020-05-25 21:18:17 +00:00
|
|
|
{name: "negative fractional, large positive exponent", f: -1.55e+12, s: "-1.55E+12"},
|
|
|
|
{name: "negative fractional, large negative exponent", f: -1.55e-12, s: "-1.55E-12"},
|
2019-08-31 18:46:32 +00:00
|
|
|
} {
|
|
|
|
t.Run(testcase.name, func(t *testing.T) {
|
|
|
|
expectEqualStrings(t, attribute.CoordsList{testcase.f}.String(), testcase.s)
|
|
|
|
})
|
|
|
|
}
|
2019-05-30 04:41:04 +00:00
|
|
|
})
|
2019-08-31 18:46:32 +00:00
|
|
|
|
|
|
|
t.Run("String inserts delimiter in lists with length > 1", func(t *testing.T) {
|
|
|
|
actual := attribute.CoordsList{0, 0}.String()
|
|
|
|
expected := "0,0"
|
|
|
|
expectEqualStrings(t, actual, expected)
|
2019-05-30 04:41:04 +00:00
|
|
|
})
|
|
|
|
}
|