-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsizeof_test.go
131 lines (125 loc) · 1.81 KB
/
sizeof_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
package sizeof
import (
"testing"
)
func TestQuantileProcessing(t *testing.T) {
type testCase struct {
obj interface{}
size uint64
}
type otra struct { // just a struct to use in tests
una int
dos int8
tres int8
cuatro int8
cinco int8
seis int8
siete string
}
type cosa struct { // just a struct to use in tests
una int
dos int8
tres int8
cuatro int8
cinco int8
seis int8
siete string
sub otra
SubPtr *otra
}
var testCases = []testCase{
testCase{
obj: int8(120),
size: 1,
},
testCase{
obj: uint16(5000),
size: 2,
},
testCase{
obj: uint32(65535),
size: 4,
},
testCase{
obj: float64(3.14),
size: 8,
},
testCase{
obj: []int{1, 2, 3},
size: 48,
},
testCase{
obj: [3]int{1, 2, 3},
size: 24,
},
testCase{
obj: &[3]int{1, 2, 3},
size: 32,
},
testCase{
obj: struct {
a int64
b int8
c int32
d int8
e int8
}{
1, 2, 3, 4, 5,
},
size: 24,
},
testCase{
obj: "",
size: 16,
},
testCase{
obj: "Hello World!",
size: 28,
},
testCase{
obj: []*cosa{
&cosa{},
&cosa{},
},
size: 184,
},
testCase{
obj: map[cosa]*cosa{
cosa{una: 1}: &cosa{},
cosa{una: 2}: nil,
},
size: 428,
},
testCase{
obj: map[*cosa]*cosa{
&cosa{una: 1}: &cosa{},
&cosa{una: 2}: nil,
},
size: 444,
},
testCase{
obj: map[[2]int]int{
[2]int{1, 2}: 3,
},
size: 196,
},
testCase{
obj: map[otra]*cosa{
otra{}: &cosa{
siete: " ",
SubPtr: &otra{
siete: " ",
},
},
otra{siete: "7 "}: nil,
},
size: 388,
},
}
for i, tc := range testCases {
size := SizeOf(tc.obj)
if size != tc.size {
t.Errorf("Failed test %d, expected %d but got %d", i, tc.size, size)
}
}
}