1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 type shiftTest
struct {
18 var shifttests
= []shiftTest
{
21 {1, 100, "1267650600228229401496703205376"},
23 "0.00000000000000000000000000000078886090522101180541" +
24 "17285652827862296732064351090230047702789306640625",
26 {12345678, 8, "3160493568"},
27 {12345678, -8, "48225.3046875"},
28 {195312, 9, "99999744"},
29 {1953125, 9, "1000000000"},
32 func TestDecimalShift(t
*testing
.T
) {
33 for i
:= 0; i
< len(shifttests
); i
++ {
34 test
:= &shifttests
[i
]
35 d
:= NewDecimal(test
.i
)
39 t
.Errorf("Decimal %v << %v = %v, want %v",
40 test
.i
, test
.shift
, s
, test
.out
)
45 type roundTest
struct {
48 down
, round
, up
string
52 var roundtests
= []roundTest
{
53 {0, 4, "0", "0", "0", 0},
54 {12344999, 4, "12340000", "12340000", "12350000", 12340000},
55 {12345000, 4, "12340000", "12340000", "12350000", 12340000},
56 {12345001, 4, "12340000", "12350000", "12350000", 12350000},
57 {23454999, 4, "23450000", "23450000", "23460000", 23450000},
58 {23455000, 4, "23450000", "23460000", "23460000", 23460000},
59 {23455001, 4, "23450000", "23460000", "23460000", 23460000},
61 {99994999, 4, "99990000", "99990000", "100000000", 99990000},
62 {99995000, 4, "99990000", "100000000", "100000000", 100000000},
63 {99999999, 4, "99990000", "100000000", "100000000", 100000000},
65 {12994999, 4, "12990000", "12990000", "13000000", 12990000},
66 {12995000, 4, "12990000", "13000000", "13000000", 13000000},
67 {12999999, 4, "12990000", "13000000", "13000000", 13000000},
70 func TestDecimalRound(t
*testing
.T
) {
71 for i
:= 0; i
< len(roundtests
); i
++ {
72 test
:= &roundtests
[i
]
73 d
:= NewDecimal(test
.i
)
77 t
.Errorf("Decimal %v RoundDown %d = %v, want %v",
78 test
.i
, test
.nd
, s
, test
.down
)
80 d
= NewDecimal(test
.i
)
84 t
.Errorf("Decimal %v Round %d = %v, want %v",
85 test
.i
, test
.nd
, s
, test
.down
)
87 d
= NewDecimal(test
.i
)
91 t
.Errorf("Decimal %v RoundUp %d = %v, want %v",
92 test
.i
, test
.nd
, s
, test
.up
)
97 type roundIntTest
struct {
103 var roundinttests
= []roundIntTest
{
116 func TestDecimalRoundedInteger(t
*testing
.T
) {
117 for i
:= 0; i
< len(roundinttests
); i
++ {
118 test
:= roundinttests
[i
]
119 d
:= NewDecimal(test
.i
)
121 int := d
.RoundedInteger()
123 t
.Errorf("Decimal %v >> %v RoundedInteger = %v, want %v",
124 test
.i
, test
.shift
, int, test
.int)