-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmem_test.go
59 lines (54 loc) · 1.1 KB
/
mem_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
package mem
import (
"testing"
)
type SimpleStruct struct {
A float64
B int
C string
}
func TestSimpleStruct(t *testing.T) {
testStruct := SimpleStruct{
A: 1.,
B: 2,
C: "3",
}
actualSize := GetMemoryConsumption(testStruct)
expectedSize := 48
if actualSize != expectedSize {
t.Errorf("Size of test struct is incorrect (got %v, expected %v)\n", actualSize, expectedSize)
}
}
type ComplexStruct struct {
A float64
B int
C string
D SimpleStruct
E *SimpleStruct
F map[int]*SimpleStruct
G []SimpleStruct
}
func TestComplexStruct(t *testing.T) {
simpleStruct := SimpleStruct{
A: 1.,
B: 2,
C: "3,",
}
simpleStructMap := make(map[int]*SimpleStruct)
simpleStructMap[1] = &simpleStruct
simpleStructSlice := []SimpleStruct{simpleStruct}
complexStruct := ComplexStruct{
A: 1.,
B: 2,
C: "3",
D: simpleStruct,
E: &simpleStruct,
F: simpleStructMap,
G: simpleStructSlice,
}
actualSize := GetMemoryConsumption(complexStruct)
expectedSize := 216
if actualSize != expectedSize {
t.Errorf("Size of complex struct is incorrect (got %v, expected %v)\n", actualSize, expectedSize)
}
}