(t *testing.T)
| 578 | } |
| 579 | |
| 580 | func TestNewFromBigRat(t *testing.T) { |
| 581 | mustParseRat := func(val string) *big.Rat { |
| 582 | num, _ := new(big.Rat).SetString(val) |
| 583 | return num |
| 584 | } |
| 585 | |
| 586 | type Inp struct { |
| 587 | val *big.Rat |
| 588 | prec int32 |
| 589 | } |
| 590 | |
| 591 | tests := map[Inp]string{ |
| 592 | Inp{big.NewRat(0, 1), 16}: "0", |
| 593 | Inp{big.NewRat(4, 5), 16}: "0.8", |
| 594 | Inp{big.NewRat(10, 2), 16}: "5", |
| 595 | Inp{big.NewRat(1023427554493, 43432632), 16}: "23563.5628642767953828", // rounded |
| 596 | Inp{big.NewRat(1, 434324545566634), 16}: "0.0000000000000023", |
| 597 | Inp{big.NewRat(1, 3), 16}: "0.3333333333333333", |
| 598 | Inp{big.NewRat(2, 3), 2}: "0.67", // rounded |
| 599 | Inp{big.NewRat(2, 3), 16}: "0.6666666666666667", // rounded |
| 600 | Inp{big.NewRat(10000, 3), 16}: "3333.3333333333333333", |
| 601 | Inp{mustParseRat("30702832066636633479"), 16}: "30702832066636633479", |
| 602 | Inp{mustParseRat("487028320159896636679.1827512895753"), 16}: "487028320159896636679.1827512895753", |
| 603 | Inp{mustParseRat("127028320612589896636633479.173582751289575278357832"), -2}: "127028320612589896636633500", // rounded |
| 604 | Inp{mustParseRat("127028320612589896636633479.173582751289575278357832"), 16}: "127028320612589896636633479.1735827512895753", // rounded |
| 605 | Inp{mustParseRat("127028320612589896636633479.173582751289575278357832"), 32}: "127028320612589896636633479.173582751289575278357832", |
| 606 | } |
| 607 | |
| 608 | // add negatives |
| 609 | for p, s := range tests { |
| 610 | if p.val.Cmp(new(big.Rat)) > 0 { |
| 611 | tests[Inp{p.val.Neg(p.val), p.prec}] = "-" + s |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | for input, s := range tests { |
| 616 | d := NewFromBigRat(input.val, input.prec) |
| 617 | if d.String() != s { |
| 618 | t.Errorf("expected %s, got %s (%s, %d)", |
| 619 | s, d.String(), |
| 620 | d.value.String(), d.exp) |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | func TestCopy(t *testing.T) { |
| 626 | origin := New(1, 0) |
nothing calls this directly
no test coverage detected
searching dependent graphs…