mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 12:30:49 +01:00
Added unittests
This commit is contained in:
parent
ba54fe1418
commit
d23c457004
1 changed files with 48 additions and 0 deletions
|
@ -3339,3 +3339,51 @@ func ExampleNewFromFloat() {
|
|||
//0.123123123123123
|
||||
//-10000000000000
|
||||
}
|
||||
|
||||
func TestDecimal_String(t *testing.T) {
|
||||
type testData struct {
|
||||
input string
|
||||
expected string
|
||||
}
|
||||
|
||||
tests := []testData{
|
||||
{"1.22", "1.22"},
|
||||
{"1.00", "1"},
|
||||
{"153.192", "153.192"},
|
||||
{"999.999", "999.999"},
|
||||
{"0.0000000001", "0.0000000001"},
|
||||
{"0.0000000000", "0"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
d, err := NewFromString(test.input);
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if d.String() != test.expected {
|
||||
t.Errorf("expected %s, got %s", test.expected, d.String())
|
||||
}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
StringTrimTrailingZeros = true
|
||||
}()
|
||||
|
||||
StringTrimTrailingZeros = false
|
||||
tests = []testData{
|
||||
{"1.00", "1.00"},
|
||||
{"0.00", "0.00"},
|
||||
{"129.123000", "129.123000"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
d, err := NewFromString(test.input);
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if d.String() != test.expected {
|
||||
t.Errorf("expected %s, got %s", test.expected, d.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue