-
Notifications
You must be signed in to change notification settings - Fork 16
/
storage_test.go
113 lines (86 loc) · 1.89 KB
/
storage_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
package transaction
// Core
// Storage/sections test
// Copyright © 2017-2018 Eduard Sesigin. All rights reserved. Contacts: <[email protected]>
import "testing"
func TestStorageNew(t *testing.T) {
s := newStorage()
if s == nil {
t.Error("Error creating `Storage`")
}
if uint64(len(s)) != storageNumber {
t.Error("Error in the number of sections")
}
}
func TestStorageAdd(t *testing.T) {
s := newStorage()
if !s.addUnit(1) {
t.Error("Error adding a unit")
}
if s.addUnit(1) {
t.Error("Failed to add unit again")
}
}
func TestStorageGet(t *testing.T) {
s := newStorage()
s.addUnit(1)
if s.getUnit(1) == nil {
t.Error("No unit found (has been added)")
}
if s.getUnit(2) != nil {
t.Error("Found a non-existent unit")
}
}
func TestStorageDel(t *testing.T) {
s := newStorage()
s.addUnit(1)
if _, ok := s.delUnit(1); !ok {
t.Error("Unable to delete unit")
}
if _, ok := s.delUnit(1); ok {
t.Error("Repeated deletion of the same unit!")
}
}
func TestStorageId(t *testing.T) {
s := newStorage()
if s.id(1) != 1 {
t.Error("The lower bits are incorrectly recalculated")
}
if s.id(1048575) != 65535 {
t.Error("Improperly recalculated high-order bits")
}
}
func TestSectionNew(t *testing.T) {
if newSection() == nil {
t.Error("Error creating `Section`")
}
}
func TestSectionAdd(t *testing.T) {
s := newSection()
if !s.addUnit(1) {
t.Error("Error adding a unit")
}
if s.addUnit(1) {
t.Error("Failed to add unit again")
}
}
func TestSectionGet(t *testing.T) {
s := newSection()
s.addUnit(1)
if s.getUnit(1) == nil {
t.Error("No unit found (has been added)")
}
if s.getUnit(2) != nil {
t.Error("Found a non-existent unit")
}
}
func TestSectionDel(t *testing.T) {
s := newSection()
s.addUnit(1)
if _, ok := s.delUnit(1); !ok {
t.Error("Unable to delete unit")
}
if _, ok := s.delUnit(1); ok {
t.Error("Repeated deletion of the same unit!")
}
}