forked from regen-network/mainnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math_test.go
55 lines (42 loc) · 1.16 KB
/
math_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestMath(t *testing.T) {
zero := Dec{}
one := NewDecFromInt64(1)
two := NewDecFromInt64(2)
three := NewDecFromInt64(3)
four := NewDecFromInt64(4)
five := NewDecFromInt64(5)
minusOne := NewDecFromInt64(-1)
res, err := two.Add(zero)
require.NoError(t, err)
require.True(t, res.IsEqual(two))
res, err = five.Sub(two)
require.NoError(t, err)
require.True(t, res.IsEqual(three))
res, err = four.Quo(two)
require.NoError(t, err)
require.True(t, res.IsEqual(two))
res, err = five.QuoInteger(two)
require.NoError(t, err)
require.True(t, res.IsEqual(two))
res, err = five.Rem(two)
require.NoError(t, err)
require.True(t, res.IsEqual(one))
x, err := four.Int64()
require.NoError(t, err)
require.Equal(t, int64(4), x)
require.Equal(t, "5", five.String())
require.True(t, zero.IsZero())
require.False(t, zero.IsPositive())
require.False(t, zero.IsNegative())
require.False(t, one.IsZero())
require.True(t, one.IsPositive())
require.False(t, one.IsNegative())
require.False(t, minusOne.IsZero())
require.False(t, minusOne.IsPositive())
require.True(t, minusOne.IsNegative())
}