-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfloat_test.go
58 lines (40 loc) · 1.14 KB
/
float_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
package cpy_test
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
"go.nhat.io/cpy/v3"
)
func TestPyFloatCheck(t *testing.T) {
cpy.Py_Initialize()
pyFloat := cpy.PyFloat_FromDouble(345.)
defer pyFloat.DecRef()
assert.True(t, cpy.PyFloat_Check(pyFloat))
assert.True(t, cpy.PyFloat_CheckExact(pyFloat))
}
func TestPyFloatFromAsDouble(t *testing.T) {
cpy.Py_Initialize()
v := 2354.
pyFloat := cpy.PyFloat_FromDouble(v)
defer pyFloat.DecRef()
assert.NotNil(t, pyFloat)
assert.InDelta(t, v, cpy.PyFloat_AsDouble(pyFloat), 0.01)
}
func TestPyFloatFromAsString(t *testing.T) {
cpy.Py_Initialize()
pyString := cpy.PyUnicode_FromString("2354")
defer pyString.DecRef()
pyFloat := cpy.PyFloat_FromString(pyString)
defer pyFloat.DecRef()
assert.NotNil(t, pyFloat)
assert.InDelta(t, 2354., cpy.PyFloat_AsDouble(pyFloat), 0.01)
}
func TestPyFloatMinMax(t *testing.T) {
cpy.Py_Initialize()
assert.InDelta(t, math.MaxFloat64, cpy.PyFloat_GetMax(), 0.01)
assert.InDelta(t, 2.2250738585072014e-308, cpy.PyFloat_GetMin(), 0.01)
}
func TestPyFloatInfo(t *testing.T) {
cpy.Py_Initialize()
assert.NotNil(t, cpy.PyFloat_GetInfo())
}