Skip to content

Commit

Permalink
add test for LRUHashDict
Browse files Browse the repository at this point in the history
  • Loading branch information
winitzki committed Jul 12, 2024
1 parent fe1a1f4 commit e8af115
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class LRUHashDict[A](maxSize: Int) extends HashDict[A] {

override def store(value: A): Int = {
val key = keyDict.computeIfAbsent(value, _ => valueDict.size + 1)
assert(!valueDict.containsKey(key))
valueDict.put(key, value)
key
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.chymyst.nanodhall.unit

import com.eed3si9n.expecty.Expecty.expect
import io.chymyst.dhall.LRUHashDict
import munit.FunSuite

class LRUHashDictTest extends FunSuite {
test("hash strings") {
val dict = new LRUHashDict[String](10)
val abc = dict.store("abc")
val cde = dict.store("cde")
expect(abc != cde)
expect(dict.store("abc") == abc)
expect(dict.store("cde") == cde)
expect(dict.lookup(abc) == Some("abc"))
expect(dict.lookup(cde) == Some("cde"))
expect(dict.lookup(0) == None)
}
}

0 comments on commit e8af115

Please sign in to comment.