This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
/
integer_test.go
137 lines (120 loc) · 3.06 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
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the MIT License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
package python3
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPyLongCheck(t *testing.T) {
Py_Initialize()
pyLong := PyLong_FromGoInt(345)
assert.True(t, PyLong_Check(pyLong))
assert.True(t, PyLong_CheckExact(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsLong(t *testing.T) {
Py_Initialize()
v := 2354
pyLong := PyLong_FromLong(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsLong(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsUnsignedLong(t *testing.T) {
Py_Initialize()
v := uint(2354)
pyLong := PyLong_FromUnsignedLong(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsUnsignedLong(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsLongLong(t *testing.T) {
Py_Initialize()
v := int64(2354)
pyLong := PyLong_FromLongLong(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsLongLong(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsUnsignedLongLong(t *testing.T) {
Py_Initialize()
v := uint64(2354)
pyLong := PyLong_FromUnsignedLongLong(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsUnsignedLongLong(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsDouble(t *testing.T) {
Py_Initialize()
v := float64(2354.0)
pyLong := PyLong_FromDouble(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsDouble(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsGoFloat64(t *testing.T) {
Py_Initialize()
v := float64(2354.0)
pyLong := PyLong_FromGoFloat64(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsDouble(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsString(t *testing.T) {
Py_Initialize()
v := 2354
s := strconv.Itoa(v)
pyLong := PyLong_FromString(s, 10)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsLong(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsUnicodeObject(t *testing.T) {
Py_Initialize()
v := 2354
s := strconv.Itoa(v)
pyUnicode := PyUnicode_FromString(s)
assert.NotNil(t, pyUnicode)
pyLong := PyLong_FromUnicodeObject(pyUnicode, 10)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsLong(pyLong))
pyLong.DecRef()
pyUnicode.DecRef()
}
func TestPyLongFromAsGoInt(t *testing.T) {
Py_Initialize()
v := 2354
pyLong := PyLong_FromGoInt(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsLong(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsGoUint(t *testing.T) {
Py_Initialize()
v := uint(2354)
pyLong := PyLong_FromGoUint(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsUnsignedLong(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsGoInt64(t *testing.T) {
Py_Initialize()
v := int64(2354)
pyLong := PyLong_FromGoInt64(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsLongLong(pyLong))
pyLong.DecRef()
}
func TestPyLongFromAsGoUint64(t *testing.T) {
Py_Initialize()
v := uint64(2354)
pyLong := PyLong_FromGoUint64(v)
assert.NotNil(t, pyLong)
assert.Equal(t, v, PyLong_AsUnsignedLongLong(pyLong))
pyLong.DecRef()
}