-
Notifications
You must be signed in to change notification settings - Fork 2
/
lru_cache_test.go
64 lines (54 loc) · 1.09 KB
/
lru_cache_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
package collection
import "testing"
func TestLRUCache_Put_replace(t *testing.T) {
const key = 1
const firstPut = "first"
const secondPut = "second"
subject := NewLRUCache[int, string](10)
subject.Put(key, firstPut)
subject.Put(key, secondPut)
want := secondPut
got, ok := subject.Get(key)
if !ok {
t.Logf("key should have been present")
t.Fail()
}
if got != want {
t.Logf("Unexpected result\n\tgot: %s\n\twant: %s", got, want)
t.Fail()
}
}
func TestLRUCache_Remove_empty(t *testing.T) {
subject := NewLRUCache[int, int](10)
got := subject.Remove(7)
if got != false {
t.Fail()
}
}
func TestLRUCache_Remove_present(t *testing.T) {
const key = 10
subject := NewLRUCache[int, string](6)
subject.Put(key, "ten")
ok := subject.Remove(key)
if !ok {
t.Fail()
}
_, ok = subject.Get(key)
if ok {
t.Fail()
}
}
func TestLRUCache_Remove_notPresent(t *testing.T) {
const key1 = 10
const key2 = key1 + 1
subject := NewLRUCache[int, string](6)
subject.Put(key2, "eleven")
ok := subject.Remove(key1)
if ok {
t.Fail()
}
_, ok = subject.Get(key2)
if !ok {
t.Fail()
}
}