Closed gozeloglu closed 1 year ago
@gozeloglu three PRs in a row, you're on fire!
As for testing, I think something like this should work:
c := prepCache("1", "2", "3", "4", "5")
var results []string
c.Range(func(item *Item) {
results = append(results, item.Key())
return item.Key() != "4"
})
assert.Equal(t, []string{"1", "2", "3", "4"}, results) // order is important
@gozeloglu three PRs in a row, you're on fire!
As for testing, I think something like this should work:
c := prepCache("1", "2", "3", "4", "5") var results []string c.Range(func(item *Item) { results = append(results, item.Key()) return item.Key() != "4" }) assert.Equal(t, []string{"1", "2", "3", "4"}, results) // order is important
I added a simple test but I only checked the "5" because of map internal.
Hi @swithek. Can you review the last changes?
@gozeloglu sorry for the delay. I'll review your changes sometime in the next few days.
I added a simple test but I only checked the "5" because of map internal.
My proposal in the comment above uses the LRU list instead of the map, so you should be able to get predictable results and check all items in the result slice. @gozeloglu
I added a simple test but I only checked the "5" because of map internal.
My proposal in the comment above uses the LRU list instead of the map, so you should be able to get predictable results and check all items in the result slice. @gozeloglu
I updated the test. The keys are added to the front of the linked list. So, I checked in reverse order.