-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlong_test.go
138 lines (121 loc) · 2.77 KB
/
long_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
package gp
import (
"math"
"testing"
)
func TestLongCreation(t *testing.T) {
setupTest(t)
tests := []struct {
name string
input int64
expected int64
}{
{"zero", 0, 0},
{"positive", 42, 42},
{"negative", -42, -42},
{"max_int64", math.MaxInt64, math.MaxInt64},
{"min_int64", math.MinInt64, math.MinInt64},
}
for _, tt := range tests {
l := MakeLong(tt.input)
if got := l.Int64(); got != tt.expected {
t.Errorf("MakeLong(%d) = %d; want %d", tt.input, got, tt.expected)
}
}
}
func TestLongFromFloat64(t *testing.T) {
setupTest(t)
tests := []struct {
name string
input float64
expected int64
}{
{"integer_float", 42.0, 42},
{"truncated_float", 42.9, 42},
{"negative_float", -42.9, -42},
}
for _, tt := range tests {
l := LongFromFloat64(tt.input)
if got := l.Int64(); got != tt.expected {
t.Errorf("LongFromFloat64(%f) = %d; want %d", tt.input, got, tt.expected)
}
}
}
func TestLongFromString(t *testing.T) {
setupTest(t)
tests := []struct {
name string
input string
base int
expected int64
}{
{"decimal", "42", 10, 42},
{"hex", "2A", 16, 42},
{"binary", "101010", 2, 42},
{"octal", "52", 8, 42},
{"negative", "-42", 10, -42},
}
for _, tt := range tests {
l := LongFromString(tt.input, tt.base)
if got := l.Int64(); got != tt.expected {
t.Errorf("LongFromString(%q, %d) = %d; want %d", tt.input, tt.base, got, tt.expected)
}
}
}
func TestLongConversions(t *testing.T) {
setupTest(t)
l := MakeLong(42)
if got := l.Int(); got != 42 {
t.Errorf("Int() = %d; want 42", got)
}
if got := l.Uint(); got != 42 {
t.Errorf("Uint() = %d; want 42", got)
}
if got := l.Uint64(); got != 42 {
t.Errorf("Uint64() = %d; want 42", got)
}
if got := l.Float64(); got != 42.0 {
t.Errorf("Float64() = %f; want 42.0", got)
}
if got := l.Uintptr(); got != 42 {
t.Errorf("Uintptr() = %d; want 42", got)
}
}
func TestLongFromUintptr(t *testing.T) {
setupTest(t)
tests := []struct {
name string
input uintptr
expected int64
}{
{"zero", 0, 0},
{"positive", 42, 42},
{"large_number", 1 << 30, 1 << 30},
}
for _, tt := range tests {
l := LongFromUintptr(tt.input)
if got := l.Int64(); got != tt.expected {
t.Errorf("LongFromUintptr(%d) = %d; want %d", tt.input, got, tt.expected)
}
}
}
func TestLongFromUnicode(t *testing.T) {
setupTest(t)
tests := []struct {
name string
input string
base int
expected int64
}{
{"unicode_decimal", "42", 10, 42},
{"unicode_hex", "2A", 16, 42},
}
for _, tt := range tests {
// Create Unicode object from string
u := MakeStr(tt.input)
l := LongFromUnicode(u.Object, tt.base)
if got := l.Int64(); got != tt.expected {
t.Errorf("LongFromUnicode(%q, %d) = %d; want %d", tt.input, tt.base, got, tt.expected)
}
}
}