forked from TheAlgorithms/Go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashmap_test.go
More file actions
59 lines (49 loc) · 1.25 KB
/
Copy pathhashmap_test.go
File metadata and controls
59 lines (49 loc) · 1.25 KB
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 hashmap
import (
"testing"
)
func TestHashMap(t *testing.T) {
mp := New()
t.Run("Test 1: Put(10) and checking if Get() is correct", func(t *testing.T) {
mp.Put("test", 10)
got := mp.Get("test")
if got != 10 {
t.Errorf("Put: %v, Got: %v", 10, got)
}
})
t.Run("Test 2: Reassiging the value and checking if its correct", func(t *testing.T) {
mp.Put("test", 20)
got := mp.Get("test")
if got != 20 {
t.Errorf("Put (reassign): %v, Got: %v", 20, got)
}
})
t.Run("Test 3: Adding new key when there is already some data", func(t *testing.T) {
mp.Put("test2", 30)
got := mp.Get("test2")
if got != 30 {
t.Errorf("Put: %v, Got: %v", got, 30)
}
})
t.Run("Test 4: Adding numeric key", func(t *testing.T) {
mp.Put(1, 40)
got := mp.Get(1)
if got != 40 {
t.Errorf("Put: %v, Got: %v", got, 40)
}
})
t.Run("Test 5: Checking the Contains function", func(t *testing.T) {
want := true
got := mp.Contains(1)
if want != got {
t.Errorf("Key '1' exists but couldn't be retrieved")
}
})
t.Run("Test 6: Checking if the key that doesnt exists returns false", func(t *testing.T) {
want := false
got := mp.Contains(2)
if got != want {
t.Errorf("Key '2' doesn't exists in the map but it says otherwise")
}
})
}