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

Function TestDecimal_QuoRem2

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

Source from the content-addressed store, hash-verified

1996}
1997
1998func TestDecimal_QuoRem2(t *testing.T) {
1999 for _, tc := range createDivTestCases() {
2000 d := tc.d
2001 if sign(tc.d2) == 0 {
2002 continue
2003 }
2004 d2 := tc.d2
2005 prec := tc.prec
2006 q, r := d.QuoRem(d2, prec)
2007 // rule 1: d = d2*q +r
2008 if !d.Equal(d2.Mul(q).Add(r)) {
2009 t.Errorf("not fitting, d=%v, d2=%v, prec=%d, q=%v, r=%v",
2010 d, d2, prec, q, r)
2011 }
2012 // rule 2: q is integral multiple of 10^(-prec)
2013 if !q.Equal(q.Truncate(prec)) {
2014 t.Errorf("quotient wrong precision, d=%v, d2=%v, prec=%d, q=%v, r=%v",
2015 d, d2, prec, q, r)
2016 }
2017 // rule 3: abs(r)<abs(d) * 10^(-prec)
2018 if r.Abs().Cmp(d2.Abs().Mul(New(1, -prec))) >= 0 {
2019 t.Errorf("remainder too large, d=%v, d2=%v, prec=%d, q=%v, r=%v",
2020 d, d2, prec, q, r)
2021 }
2022 // rule 4: r and d have the same sign
2023 if r.value.Sign()*d.value.Sign() < 0 {
2024 t.Errorf("signum of divisor and rest do not match, "+
2025 "d=%v, d2=%v, prec=%d, q=%v, r=%v",
2026 d, d2, prec, q, r)
2027 }
2028 }
2029}
2030
2031// this is the old Div method from decimal
2032// Div returns d / d2. If it doesn't divide exactly, the result will have

Callers

nothing calls this directly

Calls 11

createDivTestCasesFunction · 0.85
signFunction · 0.85
NewFunction · 0.85
QuoRemMethod · 0.80
EqualMethod · 0.80
AddMethod · 0.80
MulMethod · 0.80
TruncateMethod · 0.80
CmpMethod · 0.80
AbsMethod · 0.80
SignMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…