-
Notifications
You must be signed in to change notification settings - Fork 4
/
int_or_inf_test.go
48 lines (39 loc) · 955 Bytes
/
int_or_inf_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
package openairt_test
import (
"encoding/json"
"math"
"math/big"
"net"
"testing"
openairt "github.com/WqyJh/go-openai-realtime"
"github.com/stretchr/testify/require"
)
func TestIntOrInfMarshalJSON(t *testing.T) {
v := openairt.IntOrInf(10)
require.Equal(t, 10, int(v))
require.False(t, v.IsInf())
b, err := json.Marshal(v)
require.NoError(t, err)
require.Equal(t, []byte("10"), b)
v = openairt.Inf
require.Equal(t, math.MaxInt, int(v))
require.True(t, v.IsInf())
b, err = json.Marshal(v)
require.NoError(t, err)
require.Equal(t, []byte("\"inf\""), b)
type TestStruct struct {
MaxOutputTokens openairt.IntOrInf `json:"max_output_tokens,omitempty"`
}
s := TestStruct{}
b, err = json.Marshal(s)
require.NoError(t, err)
require.Equal(t, []byte("{}"), b)
}
func TestInetAton(t *testing.T) {
ip := "37.57.95.27"
ret := big.NewInt(0)
i := net.ParseIP(ip).To4()
require.NotNil(t, i)
ret.SetBytes(i)
t.Log(ret.Uint64())
}