| 84 | } |
| 85 | |
| 86 | func TestUpscale(t *testing.T) { |
| 87 | tests := []struct { |
| 88 | x, y *Decimal |
| 89 | a, b *BigInt |
| 90 | s int32 |
| 91 | }{ |
| 92 | {x: New(1, 0), y: New(100, -1), a: NewBigInt(10), b: NewBigInt(100), s: -1}, |
| 93 | {x: New(1, 0), y: New(10, -1), a: NewBigInt(10), b: NewBigInt(10), s: -1}, |
| 94 | {x: New(1, 0), y: New(10, 0), a: NewBigInt(1), b: NewBigInt(10), s: 0}, |
| 95 | {x: New(1, 1), y: New(1, 0), a: NewBigInt(10), b: NewBigInt(1), s: 0}, |
| 96 | {x: New(10, -2), y: New(1, -1), a: NewBigInt(10), b: NewBigInt(10), s: -2}, |
| 97 | {x: New(1, -2), y: New(100, 1), a: NewBigInt(1), b: NewBigInt(100000), s: -2}, |
| 98 | } |
| 99 | for _, tc := range tests { |
| 100 | t.Run(fmt.Sprintf("%s, %s", tc.x, tc.y), func(t *testing.T) { |
| 101 | a, b, s, err := upscale(tc.x, tc.y, new(BigInt)) |
| 102 | if err != nil { |
| 103 | t.Fatal(err) |
| 104 | } |
| 105 | if a.Cmp(tc.a) != 0 { |
| 106 | t.Errorf("a: expected %s, got %s", tc.a, a) |
| 107 | } |
| 108 | if b.Cmp(tc.b) != 0 { |
| 109 | t.Errorf("b: expected %s, got %s", tc.b, b) |
| 110 | } |
| 111 | if s != tc.s { |
| 112 | t.Errorf("s: expected %d, got %d", tc.s, s) |
| 113 | } |
| 114 | }) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | func TestAdd(t *testing.T) { |
| 119 | tests := []struct { |