-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecimals_test.go
More file actions
66 lines (46 loc) · 1.24 KB
/
Copy pathdecimals_test.go
File metadata and controls
66 lines (46 loc) · 1.24 KB
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
56
57
58
59
60
61
62
63
64
65
66
package godash
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDecimalsMult(t *testing.T) {
is := assert.New(t)
v, _ := DecimalsMult("0.001", "1000000000000000000")
is.Equal("1000000000000000", v)
v, _ = DecimalsMult("0.001", "1000000000000000000", "0.1")
is.Equal("100000000000000", v)
v, _ = DecimalsMult("0.001", "1000000000000000000", "0.1", "10")
is.Equal("1000000000000000", v)
}
func TestDecimalsPlus(t *testing.T) {
is := assert.New(t)
v, _ := DecimalsPlus("0.1", "0.2")
is.Equal("0.3", v)
v, _ = DecimalsPlus("0.1", "0.2", "0.3")
is.Equal("0.6", v)
v, _ = DecimalsPlus("10", "0.2", "31")
is.Equal("41.2", v)
_, err := DecimalsPlus("0.1")
is.Error(err)
}
func TestDecimalsDiv(t *testing.T) {
is := assert.New(t)
v, _ := DecimalsDiv("100", "0.2", "5")
is.Equal("100", v)
}
func TestDecimalsDivRound(t *testing.T) {
is := assert.New(t)
v, _ := DecimalsDivRound("100", "0.2", 5)
is.Equal("500", v)
v, _ = DecimalsDivRound("0.01", "10", 5)
is.Equal("0.001", v)
v, _ = DecimalsDivRound("0.006", "10", 3)
is.Equal("0.001", v)
v, _ = DecimalsDivRound("0.006", "10", 2)
is.Equal("0", v)
}
func TestDecimalsPow(t *testing.T) {
is := assert.New(t)
v, _ := DecimalsPow("0.1", "2")
is.Equal("0.01", v)
}