| 1 | package gcachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.15 fmt/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.15 testing/" |
| 6 | "timescip-go gomod github.com/golang/go/src go1.15 time/" |
| 7 | ) |
| 8 | |
| 9 | func TestLFUGetscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TestLFUGet().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 10 | size := 1000 |
| 11 | numbers := 1000 |
| 12 | |
| 13 | gc := buildTestLoadingCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestLoadingCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., size, loaderscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/loader().) |
| 14 | testSetCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/testSetCache().(t, gc, numbers) |
| 15 | testGetCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/testGetCache().(t, gc, numbers) |
| 16 | } |
| 17 | |
| 18 | func TestLoadingLFUGetscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TestLoadingLFUGet().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 19 | size := 1000 |
| 20 | numbers := 1000 |
| 21 | |
| 22 | gc := buildTestLoadingCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestLoadingCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., size, loaderscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/loader().) |
| 23 | testGetCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/testGetCache().(t, gc, numbers) |
| 24 | } |
| 25 | |
| 26 | func TestLFULengthscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TestLFULength().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 27 | gc := buildTestLoadingCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestLoadingCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., 1000, loaderscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/loader().) |
| 28 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.("test1") |
| 29 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.("test2") |
| 30 | length := gc.Lenscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Len.(true) |
| 31 | expectedLength := 2 |
| 32 | if length != expectedLength { |
| 33 | t.Errorfscip-go gomod github.com/golang/go/src go1.15 testing/common#Errorf().("Expected length is %v, not %v", length, expectedLength) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func TestLFUEvictItemscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TestLFUEvictItem().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 38 | cacheSize := 10 |
| 39 | numbers := 11 |
| 40 | gc := buildTestLoadingCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestLoadingCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., cacheSize, loaderscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/loader().) |
| 41 | |
| 42 | for i := 0; i < numbers; i++ { |
| 43 | _, err := gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(fmtscip-go gomod github.com/golang/go/src go1.15 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.15 fmt/Sprintf().("Key-%d", i)) |
| 44 | if err != nil { |
| 45 | t.Errorfscip-go gomod github.com/golang/go/src go1.15 testing/common#Errorf().("Unexpected error: %v", err) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestLFUGetIFPresentscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TestLFUGetIFPresent().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 51 | testGetIFPresentscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/testGetIFPresent().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU.) |
| 52 | } |
| 53 | |
| 54 | func TestLFUHasscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TestLFUHas().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 55 | gc := buildTestLoadingCacheWithExpirationscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestLoadingCacheWithExpiration().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., 2, 10*timescip-go gomod github.com/golang/go/src go1.15 time/.Millisecondscip-go gomod github.com/golang/go/src go1.15 time/Millisecond.) |
| 56 | |
| 57 | for i := 0; i < 10; i++ { |
| 58 | t.Runscip-go gomod github.com/golang/go/src go1.15 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.15 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.15 fmt/Sprint().(i), func(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 59 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.("test1") |
| 60 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.("test2") |
| 61 | |
| 62 | if gc.Hasscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Has.("test0") { |
| 63 | t.Fatalscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatal().("should not have test0") |
| 64 | } |
| 65 | if !gc.Hasscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Has.("test1") { |
| 66 | t.Fatalscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatal().("should have test1") |
| 67 | } |
| 68 | if !gc.Hasscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Has.("test2") { |
| 69 | t.Fatalscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatal().("should have test2") |
| 70 | } |
| 71 | |
| 72 | timescip-go gomod github.com/golang/go/src go1.15 time/.Sleepscip-go gomod github.com/golang/go/src go1.15 time/Sleep().(20 * timescip-go gomod github.com/golang/go/src go1.15 time/.Millisecondscip-go gomod github.com/golang/go/src go1.15 time/Millisecond.) |
| 73 | |
| 74 | if gc.Hasscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Has.("test0") { |
| 75 | t.Fatalscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatal().("should not have test0") |
| 76 | } |
| 77 | if gc.Hasscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Has.("test1") { |
| 78 | t.Fatalscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatal().("should not have test1") |
| 79 | } |
| 80 | if gc.Hasscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Has.("test2") { |
| 81 | t.Fatalscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatal().("should not have test2") |
| 82 | } |
| 83 | }) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | func TestLFUFreqListOrderscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TestLFUFreqListOrder().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 88 | gc := buildTestCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., 5) |
| 89 | for i := 4; i >= 0; i-- { |
| 90 | gc.Setscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Set.(i, i) |
| 91 | for j := 0; j <= i; j++ { |
| 92 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(i) |
| 93 | } |
| 94 | } |
| 95 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 6 { |
| 96 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 6", l) |
| 97 | } |
| 98 | var i uint |
| 99 | for e := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Frontscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Front().(); e != nil; e = e.Nextscip-go gomod github.com/golang/go/src go1.15 `container/list`/Element#Next().() { |
| 100 | if e.Valuescip-go gomod github.com/golang/go/src go1.15 `container/list`/Element#Value..(*freqEntryscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/freqEntry#).freqscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/freqEntry#freq. != i { |
| 101 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != %v", e.Valuescip-go gomod github.com/golang/go/src go1.15 `container/list`/Element#Value..(*freqEntryscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/freqEntry#).freqscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/freqEntry#freq., i) |
| 102 | } |
| 103 | i++ |
| 104 | } |
| 105 | gc.Removescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Remove.(1) |
| 106 | |
| 107 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 5 { |
| 108 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 5", l) |
| 109 | } |
| 110 | gc.Setscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Set.(1, 1) |
| 111 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 5 { |
| 112 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 5", l) |
| 113 | } |
| 114 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(1) |
| 115 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 5 { |
| 116 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 5", l) |
| 117 | } |
| 118 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(1) |
| 119 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 6 { |
| 120 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 6", l) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | func TestLFUFreqListLengthscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TestLFUFreqListLength().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) { |
| 125 | k0, v0 := "k0", "v0" |
| 126 | k1, v1 := "k1", "v1" |
| 127 | |
| 128 | { |
| 129 | gc := buildTestCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., 5) |
| 130 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 1 { |
| 131 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 1", l) |
| 132 | } |
| 133 | } |
| 134 | { |
| 135 | gc := buildTestCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., 5) |
| 136 | gc.Setscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Set.(k0, v0) |
| 137 | for i := 0; i < 5; i++ { |
| 138 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(k0) |
| 139 | } |
| 140 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 2 { |
| 141 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 2", l) |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | { |
| 146 | gc := buildTestCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., 5) |
| 147 | gc.Setscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Set.(k0, v0) |
| 148 | gc.Setscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Set.(k1, v1) |
| 149 | for i := 0; i < 5; i++ { |
| 150 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(k0) |
| 151 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(k1) |
| 152 | } |
| 153 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 2 { |
| 154 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 2", l) |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | { |
| 159 | gc := buildTestCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., 5) |
| 160 | gc.Setscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Set.(k0, v0) |
| 161 | gc.Setscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Set.(k1, v1) |
| 162 | for i := 0; i < 5; i++ { |
| 163 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(k0) |
| 164 | } |
| 165 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 2 { |
| 166 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 2", l) |
| 167 | } |
| 168 | for i := 0; i < 5; i++ { |
| 169 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(k1) |
| 170 | } |
| 171 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 2 { |
| 172 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 2", l) |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | { |
| 177 | gc := buildTestCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/buildTestCache().(t, TYPE_LFUscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/TYPE_LFU., 5) |
| 178 | gc.Setscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Set.(k0, v0) |
| 179 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(k0) |
| 180 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 2 { |
| 181 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 2", l) |
| 182 | } |
| 183 | gc.Removescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Remove.(k0) |
| 184 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 1 { |
| 185 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 1", l) |
| 186 | } |
| 187 | gc.Setscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Set.(k0, v0) |
| 188 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 1 { |
| 189 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 1", l) |
| 190 | } |
| 191 | gc.Getscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/Cache#Get.(k0) |
| 192 | if l := gc.(*LFUCachescip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#).freqListscip-go gomod github.com/bluele/gcache . `github.com/bluele/gcache`/LFUCache#freqList..Lenscip-go gomod github.com/golang/go/src go1.15 `container/list`/List#Len().(); l != 2 { |
| 193 | t.Fatalfscip-go gomod github.com/golang/go/src go1.15 testing/common#Fatalf().("%v != 2", l) |
| 194 | } |
| 195 | } |
| 196 | } |