1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 17:40:06 +08:00
SpaceVim/bundle/cmp-dictionary/lua/cmp_dictionary/lfu_spec.lua
2023-06-11 21:41:39 +08:00

29 lines
720 B
Lua

local lfu = require("cmp_dictionary.lfu")
local cache
describe("Test for lfu.lua", function()
before_each(function()
cache = lfu.init(3)
end)
it("single cache", function()
cache:set("a", 1)
assert.are.equals(1, cache:get("a"))
end)
it("remove the least frequent cache", function()
cache:set("a", 1)
cache:set("b", 2)
cache:set("c", 3)
assert.are.equals(1, cache:get("a")) -- freq = 2
assert.are.equals(1, cache:get("a")) -- freq = 3
assert.are.equals(2, cache:get("b")) -- freq = 2
assert.are.equals(3, cache:get("c")) -- freq = 2
cache:set("d", 4)
-- Removed the least frequent cache with the oldest accesses.
assert.is_nil(cache:get("b"))
end)
end)