add more test case

This commit is contained in:
chiahung 2023-03-10 17:55:55 +08:00
parent 291a6f273a
commit 8c9ed0538f

View File

@ -9,51 +9,57 @@ import (
func Test_FormatString(t *testing.T) { func Test_FormatString(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
t.Run("Value(57000000) with prec = 5, expected 0.57", func(t *testing.T) { t.Run("0.57 with prec = 5, expected 0.57", func(t *testing.T) {
v := MustNewFromString("0.57") v := MustNewFromString("0.57")
s := v.FormatString(5) s := v.FormatString(5)
assert.Equal("0.57000", s) assert.Equal("0.57000", s)
}) })
t.Run("Value(57123456) with prec = 5, expected 0.57123", func(t *testing.T) { t.Run("0.57123456 with prec = 5, expected 0.57123", func(t *testing.T) {
v := MustNewFromString("0.57123456") v := MustNewFromString("0.57123456")
s := v.FormatString(5) s := v.FormatString(5)
assert.Equal("0.57123", s) assert.Equal("0.57123", s)
}) })
t.Run("Value(123456789) with prec = 9, expected 1.23456789", func(t *testing.T) { t.Run("1.23456789 with prec = 9, expected 1.23456789", func(t *testing.T) {
v := MustNewFromString("1.23456789") v := MustNewFromString("1.23456789")
s := v.FormatString(9) s := v.FormatString(9)
assert.Equal("1.234567890", s) assert.Equal("1.234567890", s)
}) })
t.Run("Value(102345678) with prec = 9, expected 1.02345678", func(t *testing.T) { t.Run("1.02345678 with prec = 9, expected 1.02345678", func(t *testing.T) {
v := MustNewFromString("1.02345678") v := MustNewFromString("1.02345678")
s := v.FormatString(9) s := v.FormatString(9)
assert.Equal("1.023456780", s) assert.Equal("1.023456780", s)
}) })
t.Run("Value(-57000000) with prec = 5, expected -0.57", func(t *testing.T) { t.Run("-0.57 with prec = 5, expected -0.57", func(t *testing.T) {
v := MustNewFromString("-0.57") v := MustNewFromString("-0.57")
s := v.FormatString(5) s := v.FormatString(5)
assert.Equal("-0.57000", s) assert.Equal("-0.57000", s)
}) })
t.Run("Value(-123456789) with prec = 9, expected 1.23456789", func(t *testing.T) { t.Run("-1.23456789 with prec = 9, expected 1.23456789", func(t *testing.T) {
v := MustNewFromString("-1.23456789") v := MustNewFromString("-1.23456789")
s := v.FormatString(9) s := v.FormatString(9)
assert.Equal("-1.234567890", s) assert.Equal("-1.234567890", s)
}) })
t.Run("Value(1234567890) with prec = -1, expected 10", func(t *testing.T) { t.Run("12.3456789 with prec = -1, expected 10", func(t *testing.T) {
v := MustNewFromString("12.3456789") v := MustNewFromString("12.3456789")
s := v.FormatString(-1) s := v.FormatString(-1)
assert.Equal("10", s) assert.Equal("10", s)
}) })
t.Run("Value(-1234) with prec = 3, expected = 0.000", func(t *testing.T) { t.Run("-0.00001234 with prec = 3, expected = 0.000", func(t *testing.T) {
v := MustNewFromString("-0.00001234") v := MustNewFromString("-0.00001234")
s := v.FormatString(3) s := v.FormatString(3)
assert.Equal("0.000", s) assert.Equal("0.000", s)
}) })
t.Run("12.3456789 with prec = -3, expected = 0", func(t *testing.T) {
v := MustNewFromString("12.3456789")
s := v.FormatString(-2)
assert.Equal("0", s)
})
} }