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

Function TestDecimal_DivRound2

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

Source from the content-addressed store, hash-verified

2101}
2102
2103func TestDecimal_DivRound2(t *testing.T) {
2104 for _, tc := range createDivTestCases() {
2105 d := tc.d
2106 if sign(tc.d2) == 0 {
2107 continue
2108 }
2109 d2 := tc.d2
2110 prec := tc.prec
2111 q := d.DivRound(d2, prec)
2112 if sign(q)*sign(d)*sign(d2) < 0 {
2113 t.Errorf("sign of quotient wrong, got: %v/%v is about %v", d, d2, q)
2114 }
2115 x := q.Mul(d2).Abs().Sub(d.Abs()).Mul(New(2, 0))
2116 if x.Cmp(d2.Abs().Mul(New(1, -prec))) > 0 {
2117 t.Errorf("wrong rounding, got: %v/%v prec=%d is about %v", d, d2, prec, q)
2118 }
2119 if x.Cmp(d2.Abs().Mul(New(-1, -prec))) <= 0 {
2120 t.Errorf("wrong rounding, got: %v/%v prec=%d is about %v", d, d2, prec, q)
2121 }
2122 }
2123}
2124
2125func TestDecimal_RoundCash(t *testing.T) {
2126 tests := []struct {

Callers

nothing calls this directly

Calls 8

createDivTestCasesFunction · 0.85
signFunction · 0.85
NewFunction · 0.85
DivRoundMethod · 0.80
MulMethod · 0.80
SubMethod · 0.80
AbsMethod · 0.80
CmpMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…