41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package attribute_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitlab.codemonkeysoftware.net/b/hatmill/attribute"
|
|
)
|
|
|
|
func TestCoordsList(t *testing.T) {
|
|
t.Run("String returns empty string for empty list", func(t *testing.T) {
|
|
expectEqualStrings(t, attribute.CoordsList(nil).String(), "")
|
|
})
|
|
|
|
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"},
|
|
{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"},
|
|
{name: "negative fractional, small positive exponent", f: -12.55, s: "-12.55"},
|
|
{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"},
|
|
} {
|
|
t.Run(testcase.name, func(t *testing.T) {
|
|
expectEqualStrings(t, attribute.CoordsList{testcase.f}.String(), testcase.s)
|
|
})
|
|
}
|
|
})
|
|
|
|
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)
|
|
})
|
|
}
|