@@ -5,14 +5,6 @@ import (
55 "testing"
66)
77
8- func TestCapacity (t * testing.T ) {
9- c := & cache {}
10- Capacity (52 )(c )
11- if c .cap != 52 {
12- t .Errorf ("Capacity failed to set cap" )
13- }
14- }
15-
168func TestEvictionPolicy (t * testing.T ) {
179 c := & cache {keyList : list .New ()}
1810 EvictionPolicy (LeastRecentlyUsed )(c )
@@ -33,10 +25,10 @@ func TestNew(t *testing.T) {
3325 optionApplied = true
3426 }
3527
36- c := New (option ).(* cache )
28+ c := New (314159 , option ).(* cache )
3729
38- if c .cap != 10 * 1024 * 1024 {
39- t .Errorf ("Expected default cache capacity of %d" , 10 * 1024 * 1024 )
30+ if c .cap != 314159 {
31+ t .Errorf ("Expected cache capacity of %d" , 314159 )
4032 }
4133 if c .size != 0 {
4234 t .Errorf ("Expected initial size of zero" )
@@ -71,15 +63,15 @@ func TestPutGetRemoveSize(t *testing.T) {
7163 expectedItems []Item
7264 }{{
7365 label : "Items added, key doesn't exist" ,
74- cache : New (),
66+ cache : New (10000 ),
7567 useCache : func (c Cache ) {
7668 c .Put ("foo" , testItem (1 ))
7769 },
7870 expectedSize : 1 ,
7971 expectedItems : []Item {testItem (1 ), nil , nil },
8072 }, {
8173 label : "Items added, key exists" ,
82- cache : New (),
74+ cache : New (10000 ),
8375 useCache : func (c Cache ) {
8476 c .Put ("foo" , testItem (1 ))
8577 c .Put ("foo" , testItem (10 ))
@@ -88,7 +80,7 @@ func TestPutGetRemoveSize(t *testing.T) {
8880 expectedItems : []Item {testItem (10 ), nil , nil },
8981 }, {
9082 label : "Items added, LRA eviction" ,
91- cache : New (Capacity ( 2 ) , EvictionPolicy (LeastRecentlyAdded )),
83+ cache : New (2 , EvictionPolicy (LeastRecentlyAdded )),
9284 useCache : func (c Cache ) {
9385 c .Put ("foo" , testItem (1 ))
9486 c .Put ("bar" , testItem (1 ))
@@ -99,7 +91,7 @@ func TestPutGetRemoveSize(t *testing.T) {
9991 expectedItems : []Item {nil , testItem (1 ), testItem (1 )},
10092 }, {
10193 label : "Items added, LRU eviction" ,
102- cache : New (Capacity ( 2 ) , EvictionPolicy (LeastRecentlyUsed )),
94+ cache : New (2 , EvictionPolicy (LeastRecentlyUsed )),
10395 useCache : func (c Cache ) {
10496 c .Put ("foo" , testItem (1 ))
10597 c .Put ("bar" , testItem (1 ))
@@ -110,7 +102,7 @@ func TestPutGetRemoveSize(t *testing.T) {
110102 expectedItems : []Item {testItem (1 ), nil , testItem (1 )},
111103 }, {
112104 label : "Items removed, key doesn't exist" ,
113- cache : New (),
105+ cache : New (10000 ),
114106 useCache : func (c Cache ) {
115107 c .Put ("foo" , testItem (1 ))
116108 c .Remove ("baz" )
@@ -119,7 +111,7 @@ func TestPutGetRemoveSize(t *testing.T) {
119111 expectedItems : []Item {testItem (1 ), nil , nil },
120112 }, {
121113 label : "Items removed, key exists" ,
122- cache : New (),
114+ cache : New (10000 ),
123115 useCache : func (c Cache ) {
124116 c .Put ("foo" , testItem (1 ))
125117 c .Remove ("foo" )
0 commit comments