(t *testing.T)
| 943 | } |
| 944 | |
| 945 | func TestDecimal_rescale(t *testing.T) { |
| 946 | type Inp struct { |
| 947 | int int64 |
| 948 | exp int32 |
| 949 | rescale int32 |
| 950 | } |
| 951 | tests := map[Inp]string{ |
| 952 | Inp{1234, -3, -5}: "1.234", |
| 953 | Inp{1234, -3, 0}: "1", |
| 954 | Inp{1234, 3, 0}: "1234000", |
| 955 | Inp{1234, -4, -4}: "0.1234", |
| 956 | } |
| 957 | |
| 958 | // add negatives |
| 959 | for p, s := range tests { |
| 960 | if p.int > 0 { |
| 961 | tests[Inp{-p.int, p.exp, p.rescale}] = "-" + s |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | for input, s := range tests { |
| 966 | d := New(input.int, input.exp).rescale(input.rescale) |
| 967 | |
| 968 | if d.String() != s { |
| 969 | t.Errorf("expected %s, got %s (%s, %d)", |
| 970 | s, d.String(), |
| 971 | d.value.String(), d.exp) |
| 972 | } |
| 973 | |
| 974 | // test StringScaled |
| 975 | s2 := New(input.int, input.exp).StringScaled(input.rescale) |
| 976 | if s2 != s { |
| 977 | t.Errorf("expected %s, got %s", s, s2) |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | func TestDecimal_Floor(t *testing.T) { |
| 983 | assertFloor := func(input, expected Decimal) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…