File: LRUCacheSpec.hs

package info (click to toggle)
haskell-network-control 0.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 88 kB
  • sloc: haskell: 355; makefile: 2
file content (22 lines) | stat: -rw-r--r-- 972 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Network.Control.LRUCacheSpec (spec) where

import Data.Maybe
import Network.Control
import qualified Network.Control as LRU
import Test.Hspec

spec :: Spec
spec = do
    describe "LRUCache" $ do
        it "can keep entry if looked up" $ do
            let cache = insert 'b' "bar" $ insert 'a' "foo" $ empty 2
                (v, cache') = fromJust $ LRU.lookup' 'a' cache
            v `shouldBe` "foo"
            let cache'' = insert 'c' "baz" cache'
            fst <$> LRU.lookup' 'a' cache'' `shouldBe` Just "foo"
            fst <$> LRU.lookup' 'b' cache'' `shouldBe` Nothing
            fst <$> LRU.lookup' 'c' cache'' `shouldBe` Just "baz"
        it "can rebuild PSQ when reached the limit" $ do
            let cache = insert 'b' "bar" $ insert 'a' "foo" $ empty' 2 (maxBound - 2)
            show cache
                `shouldBe` "LRUCache {lcLimit = 2, lcTick = 2, lcQueue = Winner (E 'a' 0 \"foo\") (RLoser 1 (E 'b' 1 \"bar\") Start 'a' Start) 'b'}"