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

Function TestNewFromBigIntWithExponent

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

Source from the content-addressed store, hash-verified

546}
547
548func TestNewFromBigIntWithExponent(t *testing.T) {
549 type Inp struct {
550 val *big.Int
551 exp int32
552 }
553 tests := map[Inp]string{
554 Inp{big.NewInt(123412345), -3}: "123412.345",
555 Inp{big.NewInt(2234), -1}: "223.4",
556 Inp{big.NewInt(323412345), 1}: "3234123450",
557 Inp{big.NewInt(423412345), 0}: "423412345",
558 Inp{big.NewInt(52341235), -5}: "523.41235",
559 Inp{big.NewInt(623412345), -6}: "623.412345",
560 Inp{big.NewInt(723412345), -7}: "72.3412345",
561 }
562
563 // add negatives
564 for p, s := range tests {
565 if p.val.Cmp(Zero.value) > 0 {
566 tests[Inp{p.val.Neg(p.val), p.exp}] = "-" + s
567 }
568 }
569
570 for input, s := range tests {
571 d := NewFromBigInt(input.val, input.exp)
572 if d.String() != s {
573 t.Errorf("expected %s, got %s (%s, %d)",
574 s, d.String(),
575 d.value.String(), d.exp)
576 }
577 }
578}
579
580func TestNewFromBigRat(t *testing.T) {
581 mustParseRat := func(val string) *big.Rat {

Callers

nothing calls this directly

Calls 4

NewFromBigIntFunction · 0.85
CmpMethod · 0.80
NegMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…