-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat_test.go
More file actions
93 lines (88 loc) · 1.49 KB
/
Copy pathfloat_test.go
File metadata and controls
93 lines (88 loc) · 1.49 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package numcmp
import (
"testing"
)
import "github.com/stretchr/testify/assert"
func TestFloat_Compare_Float(t *testing.T) {
cases := []struct {
name string
n1, n2 string
expect int
}{
{
"No.1", "10.34", "10.340", 0,
},
{
"No.2", "10.15", "10.1", 1,
},
{
"No.3", "10.132", "10.13", 1,
},
{
"No.4", "10.132", "10.12", 1,
},
{
"No.5", "-10.4", "-8.3", -1,
},
{
"No.6", "-10.986", "-13.7", 1,
},
{
"No.7", "-10.986", "1.7", -1,
},
{
"No.8", "1.1", "3.12", -1,
},
{
"No.9", "1.0", "1.00", 0,
},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
num1, _ := NewNumber(tt.n1)
num2, _ := NewNumber(tt.n2)
assert.Equal(t, tt.expect, num1.Cmp(num2))
})
}
}
func Test_float_appendRune(t *testing.T) {
cases := []struct {
name string
n1 string
n1Append string
n2 string
expect int
}{
{
"No.1", "1", "2", "10", 1,
},
{
"No.2", "1.2", "2", "2", -1,
},
{
// test 0 append number
"No.3", "0", "2", "5", -1,
},
{
// test . append number
"No.4", ".", "2", "1", -1,
},
{
"No.5", "0.0", "2", "0.200", 0,
},
{
"No.6", "0.1", "0002", "0.11", -1,
},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
num1, _ := NewNumber(tt.n1)
num2, _ := NewNumber(tt.n2)
appendRunes := []rune(tt.n1Append)
for _, appendRune := range appendRunes {
num1.AppendRune(appendRune)
}
assert.Equal(t, tt.expect, num1.Cmp(num2))
})
}
}