// EXEC: cjc %import-path %L %l %f --test
// EXEC: ./main
import std.unittest.*
import std.unittest.testmacro.*
import memorycache.*
import std.collection.*
@Test
public class FifoCacheTest {
@TestCase
public func testcontains(): Unit {
var cache = FifoCache(10)
cache.put("key", "val")
var res = cache.contains("key")
@Assert(res,true)
var val = cache.get("key").getOrThrow()
@Assert(val,"val")
println(true)
}
@TestCase
public func testclear(): Unit {
var cache = FifoCache(10)
cache.put("key", "val")
cache.clear()
var val = cache.get("key").isNone()
@Assert(val,true)
println(true)
}
@TestCase
public func testremove(): Unit {
var cache = FifoCache(10)
cache.put("key", "val")
cache.remove()
var res = cache.contains("key")
@Assert(res,false)
println(true)
}
@TestCase
public func tesgetcap(): Unit {
var cache = FifoCache(10)
cache.setCapacity(5)
var res = cache.getCapacity()
@Assert(res,5)
println(true)
}
@TestCase
public func tesgetcap2(): Unit {
var cache = FifoCache(10)
cache.put("key", "val")
cache.put("key2", "val")
cache.put("key3", "val")
cache.put("key4", "val")
cache.setCapacity(1)
var res = cache.getCapacity()
@Assert(res,1)
println(true)
}
}