@@ -11,7 +11,7 @@ func TestAllItemsExpired(t *testing.T) {
11
11
startSize := 3 // initial number of items in map
12
12
pruneInterval := time .Duration (time .Second * 1 ) // search for expired items every 'pruneInterval' seconds
13
13
refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
14
- tm := New (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
14
+ tm := New [ string ] (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
15
15
defer tm .Close ()
16
16
17
17
// populate the TtlMap
@@ -30,7 +30,7 @@ func TestNoItemsExpired(t *testing.T) {
30
30
startSize := 3 // initial number of items in map
31
31
pruneInterval := time .Duration (time .Second * 3 ) // search for expired items every 'pruneInterval' seconds
32
32
refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
33
- tm := New (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
33
+ tm := New [ string ] (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
34
34
defer tm .Close ()
35
35
36
36
// populate the TtlMap
@@ -49,7 +49,7 @@ func TestKeepFloat(t *testing.T) {
49
49
startSize := 3 // initial number of items in map
50
50
pruneInterval := time .Duration (time .Second * 1 ) // search for expired items every 'pruneInterval' seconds
51
51
refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
52
- tm := New (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
52
+ tm := New [ string ] (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
53
53
defer tm .Close ()
54
54
55
55
// populate the TtlMap
@@ -60,7 +60,7 @@ func TestKeepFloat(t *testing.T) {
60
60
dontExpireKey := "int"
61
61
go func () {
62
62
for range time .Tick (time .Second ) {
63
- tm .Get (CustomKeyType ( dontExpireKey ) )
63
+ tm .Get (dontExpireKey )
64
64
}
65
65
}()
66
66
@@ -69,19 +69,19 @@ func TestKeepFloat(t *testing.T) {
69
69
t .Fatalf ("t.Len should equal 1, but actually equals %v\n " , tm .Len ())
70
70
}
71
71
all := tm .All ()
72
- if all [CustomKeyType ( dontExpireKey ) ].Value != 1234 {
73
- t .Errorf ("Value should equal 1234 but actually equals %v\n " , all [CustomKeyType ( dontExpireKey ) ].Value )
72
+ if all [dontExpireKey ].Value != 1234 {
73
+ t .Errorf ("Value should equal 1234 but actually equals %v\n " , all [dontExpireKey ].Value )
74
74
}
75
75
t .Logf ("tm.Len: %v\n " , tm .Len ())
76
- t .Logf ("%v Value: %v\n " , dontExpireKey , all [CustomKeyType ( dontExpireKey ) ].Value )
76
+ t .Logf ("%v Value: %v\n " , dontExpireKey , all [dontExpireKey ].Value )
77
77
}
78
78
79
79
func TestWithNoRefresh (t * testing.T ) {
80
80
maxTTL := time .Duration (time .Second * 4 ) // time in seconds
81
81
startSize := 3 // initial number of items in map
82
82
pruneInterval := time .Duration (time .Second * 1 ) // search for expired items every 'pruneInterval' seconds
83
83
refreshLastAccessOnGet := false // do NOT update item's lastAccessTime on a .Get()
84
- tm := New (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
84
+ tm := New [ string ] (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
85
85
defer tm .Close ()
86
86
87
87
// populate the TtlMap
@@ -107,7 +107,7 @@ func TestDelete(t *testing.T) {
107
107
startSize := 3 // initial number of items in map
108
108
pruneInterval := time .Duration (time .Second * 4 ) // search for expired items every 'pruneInterval' seconds
109
109
refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
110
- tm := New (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
110
+ tm := New [ string ] (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
111
111
defer tm .Close ()
112
112
113
113
// populate the TtlMap
@@ -132,7 +132,7 @@ func TestClear(t *testing.T) {
132
132
startSize := 3 // initial number of items in map
133
133
pruneInterval := time .Duration (time .Second * 4 ) // search for expired items every 'pruneInterval' seconds
134
134
refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
135
- tm := New (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
135
+ tm := New [ string ] (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
136
136
defer tm .Close ()
137
137
138
138
// populate the TtlMap
@@ -155,7 +155,7 @@ func TestAllFunc(t *testing.T) {
155
155
startSize := 3 // initial number of items in map
156
156
pruneInterval := time .Duration (time .Second * 4 ) // search for expired items every 'pruneInterval' seconds
157
157
refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
158
- tm := New (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
158
+ tm := New [ string ] (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
159
159
defer tm .Close ()
160
160
161
161
// populate the TtlMap
@@ -186,7 +186,7 @@ func TestGetNoUpdate(t *testing.T) {
186
186
startSize := 3 // initial number of items in map
187
187
pruneInterval := time .Duration (time .Second * 4 ) // search for expired items every 'pruneInterval' seconds
188
188
refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
189
- tm := New (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
189
+ tm := New [ string ] (maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
190
190
defer tm .Close ()
191
191
192
192
// populate the TtlMap
@@ -209,3 +209,74 @@ func TestGetNoUpdate(t *testing.T) {
209
209
t .Errorf ("t.Len should be 0, but actually equals %v\n " , tm .Len ())
210
210
}
211
211
}
212
+
213
+ func TestUInt64Key (t * testing.T ) {
214
+ maxTTL := time .Duration (time .Second * 2 ) // time in seconds
215
+ startSize := 3 // initial number of items in map
216
+ pruneInterval := time .Duration (time .Second * 4 ) // search for expired items every 'pruneInterval' seconds
217
+ refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
218
+ tm := New [uint64 ](maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
219
+ defer tm .Close ()
220
+
221
+ tm .Put (18446744073709551615 , "largest" )
222
+ tm .Put (9223372036854776000 , "mid" )
223
+ tm .Put (0 , "zero" )
224
+
225
+ allItems := tm .All ()
226
+ for k , v := range allItems {
227
+ t .Logf ("k: %v v: %v\n " , k , v .Value )
228
+ }
229
+
230
+ time .Sleep (maxTTL + pruneInterval )
231
+ t .Logf ("tm.Len: %v\n " , tm .Len ())
232
+ if tm .Len () != 0 {
233
+ t .Errorf ("t.Len should be 0, but actually equals %v\n " , tm .Len ())
234
+ }
235
+ }
236
+
237
+ func TestUFloat32Key (t * testing.T ) {
238
+ maxTTL := time .Duration (time .Second * 2 ) // time in seconds
239
+ startSize := 3 // initial number of items in map
240
+ pruneInterval := time .Duration (time .Second * 4 ) // search for expired items every 'pruneInterval' seconds
241
+ refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
242
+ tm := New [float32 ](maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
243
+ defer tm .Close ()
244
+
245
+ tm .Put (34000000000.12345 , "largest" )
246
+ tm .Put (12312312312.98765 , "mid" )
247
+ tm .Put (0.001 , "tiny" )
248
+
249
+ allItems := tm .All ()
250
+ for k , v := range allItems {
251
+ t .Logf ("k: %v v: %v\n " , k , v .Value )
252
+ }
253
+ t .Logf ("k: 0.001 v:%v (verified)\n " , tm .Get (0.001 ))
254
+
255
+ time .Sleep (maxTTL + pruneInterval )
256
+ t .Logf ("tm.Len: %v\n " , tm .Len ())
257
+ if tm .Len () != 0 {
258
+ t .Errorf ("t.Len should be 0, but actually equals %v\n " , tm .Len ())
259
+ }
260
+ }
261
+
262
+ func TestByteKey (t * testing.T ) {
263
+ maxTTL := time .Duration (time .Second * 2 ) // time in seconds
264
+ startSize := 3 // initial number of items in map
265
+ pruneInterval := time .Duration (time .Second * 4 ) // search for expired items every 'pruneInterval' seconds
266
+ refreshLastAccessOnGet := true // update item's lastAccessTime on a .Get()
267
+ tm := New [byte ](maxTTL , startSize , pruneInterval , refreshLastAccessOnGet )
268
+ defer tm .Close ()
269
+
270
+ tm .Put (0x41 , "A" )
271
+ tm .Put (0x7a , "z" )
272
+
273
+ allItems := tm .All ()
274
+ for k , v := range allItems {
275
+ t .Logf ("k: %x v: %v\n " , k , v .Value )
276
+ }
277
+ time .Sleep (maxTTL + pruneInterval )
278
+ t .Logf ("tm.Len: %v\n " , tm .Len ())
279
+ if tm .Len () != 0 {
280
+ t .Errorf ("t.Len should be 0, but actually equals %v\n " , tm .Len ())
281
+ }
282
+ }
0 commit comments