Skip to content

Commit

Permalink
More tests and assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
durban committed Nov 24, 2024
1 parent f9ae798 commit d790ebc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ private[mcas] abstract class AbstractHamt[K <: Hamt.HasHash, V <: Hamt.HasKey[K]
// temporary assertion to diagnose a bug here:
if (arrIdx >= arr.length) {
throw new AssertionError(
s"indexing array of length ${arr.length} with index ${arrIdx} (a = ${a}; arr = ${arr.mkString("[", ", ", "]")})"
s"indexing array of length ${arr.length} with index ${arrIdx} (" +
s"a = ${a}; arr = ${arr.mkString("[", ", ", "]")}; " +
s"contents = ${contents.mkString("[", ", ", "]")})"
)
}
// end of temporary assertion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,31 @@ final class MutHamtSpec extends ScalaCheckSuite with MUnitUtils with PropertyHel
assertEquals(oldIsBlue, h.definitelyBlue)
}
}

property("repro") {
forAll { (seed: Long, flip: Boolean) =>
val rng = new Random(seed)
val x1d3 = 0x1d32989eb776f07fL
val x981 = 0x981f5faca10443fdL
val x455 = 0x45556be62505908dL
val x785 = 0x7859b1954a0356ccL // exchanger hole
val xe5d = 0xe5d970efe9590ff3L
val _ids = List[Long](x1d3, x981, x455, x785, xe5d)
val ids = rng.shuffle(_ids)
val mutHamt1 = LongMutHamt.newEmpty()
mutHamt1.insert(Val(ids(0)))
val mutHamt2 = LongMutHamt.newEmpty()
mutHamt2.insert(Val(ids(1)))
val hamt1 = mutHamt1.copyToImmutable()
val hamt2 = mutHamt2.copyToImmutable()
val merged0 = if (flip) { hamt2 insertedAllFrom hamt1 } else { hamt1 insertedAllFrom hamt2 }
val merged1 = merged0.inserted(Val(ids(4)))
val merged2 = merged1.inserted(Val(ids(3)))
val merged3 = merged2.inserted(Val(ids(2)))
assertEquals(merged3.size, 5)
assertEquals(merged3.toArray.toList, List(Val(x1d3), Val(x455), Val(x785), Val(x981), Val(xe5d)))
}
}
}

object MutHamtSpec {
Expand Down

0 comments on commit d790ebc

Please sign in to comment.