MCPcopy
hub / github.com/shopspring/decimal / TestDecimal_RoundAndStringFixed

Function TestDecimal_RoundAndStringFixed

decimal_test.go:1094–1171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1092}
1093
1094func TestDecimal_RoundAndStringFixed(t *testing.T) {
1095 type testData struct {
1096 input string
1097 places int32
1098 expected string
1099 expectedFixed string
1100 }
1101 tests := []testData{
1102 {"1.454", 0, "1", ""},
1103 {"1.454", 1, "1.5", ""},
1104 {"1.454", 2, "1.45", ""},
1105 {"1.454", 3, "1.454", ""},
1106 {"1.454", 4, "1.454", "1.4540"},
1107 {"1.454", 5, "1.454", "1.45400"},
1108 {"1.554", 0, "2", ""},
1109 {"1.554", 1, "1.6", ""},
1110 {"1.554", 2, "1.55", ""},
1111 {"0.554", 0, "1", ""},
1112 {"0.454", 0, "0", ""},
1113 {"0.454", 5, "0.454", "0.45400"},
1114 {"0", 0, "0", ""},
1115 {"0", 1, "0", "0.0"},
1116 {"0", 2, "0", "0.00"},
1117 {"0", -1, "0", ""},
1118 {"5", 2, "5", "5.00"},
1119 {"5", 1, "5", "5.0"},
1120 {"5", 0, "5", ""},
1121 {"500", 2, "500", "500.00"},
1122 {"545", -1, "550", ""},
1123 {"545", -2, "500", ""},
1124 {"545", -3, "1000", ""},
1125 {"545", -4, "0", ""},
1126 {"499", -3, "0", ""},
1127 {"499", -4, "0", ""},
1128 }
1129
1130 // add negative number tests
1131 for _, test := range tests {
1132 expected := test.expected
1133 if expected != "0" {
1134 expected = "-" + expected
1135 }
1136 expectedStr := test.expectedFixed
1137 if strings.ContainsAny(expectedStr, "123456789") && expectedStr != "" {
1138 expectedStr = "-" + expectedStr
1139 }
1140 tests = append(tests,
1141 testData{"-" + test.input, test.places, expected, expectedStr})
1142 }
1143
1144 for _, test := range tests {
1145 d, err := NewFromString(test.input)
1146 if err != nil {
1147 t.Fatal(err)
1148 }
1149
1150 // test Round
1151 expected, err := NewFromString(test.expected)

Callers

nothing calls this directly

Calls 4

NewFromStringFunction · 0.85
EqualMethod · 0.80
StringFixedMethod · 0.80
RoundMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…