MCPcopy Create free account
hub / github.com/cockroachdb/apd / TestModf

Function TestModf

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

Source from the content-addressed store, hash-verified

169}
170
171func TestModf(t *testing.T) {
172 tests := []struct {
173 x string
174 i string
175 f string
176 }{
177 {x: "1", i: "1", f: "0"},
178 {x: "1.0", i: "1", f: "0.0"},
179 {x: "1.0e1", i: "10", f: "0"},
180 {x: "1.0e2", i: "1.0E+2", f: "0"},
181 {x: "1.0e-1", i: "0", f: "0.10"},
182 {x: "1.0e-2", i: "0", f: "0.010"},
183 {x: "1.1", i: "1", f: "0.1"},
184 {x: "1234.56", i: "1234", f: "0.56"},
185 {x: "1234.56e2", i: "123456", f: "0"},
186 {x: "1234.56e4", i: "1.23456E+7", f: "0"},
187 {x: "1234.56e-2", i: "12", f: "0.3456"},
188 {x: "1234.56e-4", i: "0", f: "0.123456"},
189 {x: "1234.56e-6", i: "0", f: "0.00123456"},
190 {x: "123456e-8", i: "0", f: "0.00123456"},
191 {x: ".123456e8", i: "1.23456E+7", f: "0"},
192
193 {x: "-1", i: "-1", f: "-0"},
194 {x: "-1.0", i: "-1", f: "-0.0"},
195 {x: "-1.0e1", i: "-10", f: "-0"},
196 {x: "-1.0e2", i: "-1.0E+2", f: "-0"},
197 {x: "-1.0e-1", i: "-0", f: "-0.10"},
198 {x: "-1.0e-2", i: "-0", f: "-0.010"},
199 {x: "-1.1", i: "-1", f: "-0.1"},
200 {x: "-1234.56", i: "-1234", f: "-0.56"},
201 {x: "-1234.56e2", i: "-123456", f: "-0"},
202 {x: "-1234.56e4", i: "-1.23456E+7", f: "-0"},
203 {x: "-1234.56e-2", i: "-12", f: "-0.3456"},
204 {x: "-1234.56e-4", i: "-0", f: "-0.123456"},
205 {x: "-1234.56e-6", i: "-0", f: "-0.00123456"},
206 {x: "-123456e-8", i: "-0", f: "-0.00123456"},
207 {x: "-.123456e8", i: "-1.23456E+7", f: "-0"},
208 }
209 for _, tc := range tests {
210 t.Run(tc.x, func(t *testing.T) {
211 x := newDecimal(t, testCtx, tc.x)
212 integ, frac := new(Decimal), new(Decimal)
213 x.Modf(integ, frac)
214 if tc.i != integ.String() {
215 t.Fatalf("integ: expected: %s, got: %s", tc.i, integ)
216 }
217 if tc.f != frac.String() {
218 t.Fatalf("frac: expected: %s, got: %s", tc.f, frac)
219 }
220 a := new(Decimal)
221 if _, err := testCtx.Add(a, integ, frac); err != nil {
222 t.Fatal(err)
223 }
224 if a.Cmp(x) != 0 {
225 t.Fatalf("%s != %s", a, x)
226 }
227 if integ.Exponent < 0 {
228 t.Fatal(integ.Exponent)

Callers

nothing calls this directly

Calls 7

newDecimalFunction · 0.85
RunMethod · 0.80
ModfMethod · 0.80
CmpTotalMethod · 0.80
StringMethod · 0.45
AddMethod · 0.45
CmpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…