-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLRUCachePlainTest.java
More file actions
73 lines (55 loc) · 1.99 KB
/
LRUCachePlainTest.java
File metadata and controls
73 lines (55 loc) · 1.99 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package linkedList;
import org.junit.Assert;
import org.junit.Test;
public class LRUCachePlainTest {
@Test
public final void shouldBeAbleToAccessAllStoredEntriesWhenCapacityIsNotExceeded() throws Exception {
LRUCachePlain cache = new LRUCachePlain(3);
cache.set(1, 1);
cache.set(2, 2);
cache.set(3, 3);
Assert.assertTrue(cache.contains(1));
Assert.assertTrue(cache.contains(2));
Assert.assertTrue(cache.contains(3));
}
@Test
public final void shouldEvictTheLeastRecentlyUsedEntryWhenCapacityIsExceeded() throws Exception {
LRUCachePlain cache = new LRUCachePlain(2);
cache.set(1, 1);
cache.set(2, 2);
cache.set(3, 3);
Assert.assertFalse(cache.contains(1));
Assert.assertTrue(cache.contains(2));
Assert.assertTrue(cache.contains(3));
}
@Test
public final void shouldMakeAnEntryTheMostRecentlyUsedAfterGetCall() throws Exception {
LRUCachePlain cache = new LRUCachePlain(2);
cache.set(1, 1);
cache.set(2, 2);
cache.get(1);
cache.set(3, 3);
Assert.assertTrue(cache.contains(1));
Assert.assertFalse(cache.contains(2));
Assert.assertTrue(cache.contains(3));
}
@Test
public final void shouldMakeAnEntryTheMostRecentlyUsedAfterSetCall() throws Exception {
LRUCachePlain cache = new LRUCachePlain(2);
cache.set(1, 1);
cache.set(2, 2);
cache.set(3, 3);
cache.set(1, 11);
Assert.assertTrue(cache.contains(1));
Assert.assertFalse(cache.contains(2));
Assert.assertTrue(cache.contains(3));
}
@Test (expected = Exception.class)
public final void shouldThrowAnExceptionWhenInitializedWithNegativeCapacity() throws Exception {
new LRUCachePlain(-1);
}
@Test (expected = Exception.class)
public final void shouldThrowAnExceptionWhenInitializedWithZeroCapacity() throws Exception {
new LRUCachePlain(0);
}
}