-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
62 lines (51 loc) · 1.61 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
package main
import (
"testing"
)
func TestEvictionPolicy(t *testing.T) {
lruCacheInit := &LRUCache{}
cache := lruCacheInit.InitializeCache(3)
cache.Put("boy1", "AmenaCliff1")
cache.Put("boy2", "AmenaCliff2")
cache.Put("boy3", "AmenaCliff3")
cache.Put("boy4", "AmenaCliff4")
firstItemIn := cache.Get("boy1")
if firstItemIn != nil {
t.Error("First Item to go in, wasn't evicted from the cache, after size of cache was exceeded")
}
}
func TestCacheHitReshuffle(t *testing.T) {
lruCacheInit := &LRUCache{}
cache := lruCacheInit.InitializeCache(3)
cache.Put("boy1", "AmenaCliff1")
cache.Put("boy2", "AmenaCliff2")
cache.Put("boy3", "AmenaCliff3")
cache.Put("boy4", "AmenaCliff4")
keyToCheck := "boy1"
firstItemIn := cache.Get(keyToCheck)
if firstItemIn != nil && firstItemIn.key != cache.head.key {
t.Error("A cache hit is suppose to take the node looked up to the head of the cache's, DLL, it didn't")
}
}
func TestLengthOfList(t *testing.T) {
lruCacheInit := &LRUCache{}
cache := lruCacheInit.InitializeCache(3)
cache.Put("boy1", "AmenaCliff1")
cache.Put("boy2", "AmenaCliff2")
cache.Put("boy3", "AmenaCliff3")
cache.Put("boy4", "AmenaCliff4")
cache.Put("boy5", "AmenaCliff5")
if cache.length > cache.maxLength {
t.Error("The Length of the cache should not be more than, the max size of the cache ")
}
}
func TestIncreaseCacheSize(t *testing.T) {
lruCacheInit := &LRUCache{}
initialSize := 10
sizeToAdd := 3
cache := lruCacheInit.InitializeCache(initialSize)
cache.IncreaseCacheSize(sizeToAdd)
if cache.maxLength != initialSize+sizeToAdd {
t.Error("Increase Size Cache Function Failed Test")
}
}