-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
101 lines (92 loc) · 1.5 KB
/
main_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
package main
import (
"testing"
)
func TestCreateHashTable(t *testing.T) {
tableSize := 3
hashtable := CreateHashTable()
if len(hashtable.table.records) != tableSize {
t.Fail()
}
}
func TestHashTable_Put(t *testing.T) {
hashtable := CreateHashTable()
hashtable.Put(1, 2)
present, value := hashtable.Get(1)
if present == false || value != 2 {
t.Fail()
}
hashtable.Put(1, 3)
present, value = hashtable.Get(1)
if present == false || value != 3 {
t.Fail()
}
}
func TestHashTable_Get(t *testing.T) {
hashtable := CreateHashTable()
hashtable.Put(1, 2)
present, value := hashtable.Get(1)
if present == false || value != 2 {
t.Fail()
}
present, value = hashtable.Get(2)
if present == true {
t.Fail()
}
}
func TestHashTable_Del(t *testing.T) {
hashtable := CreateHashTable()
hashtable.Put(1, 2)
result := hashtable.Del(1)
if result == false {
t.Fail()
}
result = hashtable.Del(1)
if result == true {
t.Fail()
}
result = hashtable.Del(3)
if result == true {
t.Fail()
}
}
func TestMain(t *testing.T){
h := CreateHashTable()
h.Display()
h.Put(1,2)
h.Display()
h.Put(2,3)
h.Display()
h.Put(3,4)
h.Display()
h.Put(4,5)
h.Display()
h.Put(5,6)
h.Display()
h.Del(1)
h.Display()
h.Del(2)
h.Display()
h.Del(3)
h.Display()
h.Put(3,4)
h.Display()
h.Put(4,5)
h.Display()
h.Put(5,6)
h.Display()
h.Del(4)
h.Display()
h.Del(5)
h.Display()
h.Put(11,12)
h.Display()
h.Put(12,13)
h.Display()
h.Put(13,14)
h.Display()
h.Put(14,15)
h.Display()
h.Put(15,16)
h.Display()
}