-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteger_test.go
171 lines (115 loc) · 3.16 KB
/
integer_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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package cpy_test
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"go.nhat.io/cpy/v3"
)
func TestPyLongCheck(t *testing.T) {
cpy.Py_Initialize()
pyLong := cpy.PyLong_FromGoInt(345)
defer pyLong.DecRef()
assert.True(t, cpy.PyLong_Check(pyLong))
assert.True(t, cpy.PyLong_CheckExact(pyLong))
}
func TestPyLongFromAsLong(t *testing.T) {
cpy.Py_Initialize()
v := 2354
pyLong := cpy.PyLong_FromLong(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsLong(pyLong))
}
func TestPyLongFromAsUnsignedLong(t *testing.T) {
cpy.Py_Initialize()
v := uint(2354)
pyLong := cpy.PyLong_FromUnsignedLong(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsUnsignedLong(pyLong))
}
func TestPyLongFromAsLongLong(t *testing.T) {
cpy.Py_Initialize()
v := int64(2354)
pyLong := cpy.PyLong_FromLongLong(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsLongLong(pyLong))
}
func TestPyLongFromAsUnsignedLongLong(t *testing.T) {
cpy.Py_Initialize()
v := uint64(2354)
pyLong := cpy.PyLong_FromUnsignedLongLong(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsUnsignedLongLong(pyLong))
}
func TestPyLongFromAsDouble(t *testing.T) {
cpy.Py_Initialize()
v := float64(2354.0)
pyLong := cpy.PyLong_FromDouble(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.InDelta(t, v, cpy.PyLong_AsDouble(pyLong), 0.01)
}
func TestPyLongFromAsGoFloat64(t *testing.T) {
cpy.Py_Initialize()
v := float64(2354.0)
pyLong := cpy.PyLong_FromGoFloat64(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.InDelta(t, v, cpy.PyLong_AsDouble(pyLong), 0.01)
}
func TestPyLongFromAsString(t *testing.T) {
cpy.Py_Initialize()
v := 2354
s := strconv.Itoa(v)
pyLong := cpy.PyLong_FromString(s, 10)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsLong(pyLong))
}
func TestPyLongFromAsUnicodeObject(t *testing.T) {
cpy.Py_Initialize()
v := 2354
s := strconv.Itoa(v)
pyUnicode := cpy.PyUnicode_FromString(s)
defer pyUnicode.DecRef()
assert.NotNil(t, pyUnicode)
pyLong := cpy.PyLong_FromUnicodeObject(pyUnicode, 10)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsLong(pyLong))
}
func TestPyLongFromAsGoInt(t *testing.T) {
cpy.Py_Initialize()
v := 2354
pyLong := cpy.PyLong_FromGoInt(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsLong(pyLong))
}
func TestPyLongFromAsGoUint(t *testing.T) {
cpy.Py_Initialize()
v := uint(2354)
pyLong := cpy.PyLong_FromGoUint(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsUnsignedLong(pyLong))
}
func TestPyLongFromAsGoInt64(t *testing.T) {
cpy.Py_Initialize()
v := int64(2354)
pyLong := cpy.PyLong_FromGoInt64(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsLongLong(pyLong))
}
func TestPyLongFromAsGoUint64(t *testing.T) {
cpy.Py_Initialize()
v := uint64(2354)
pyLong := cpy.PyLong_FromGoUint64(v)
defer pyLong.DecRef()
assert.NotNil(t, pyLong)
assert.Equal(t, v, cpy.PyLong_AsUnsignedLongLong(pyLong))
}