Skip to content

Commit

Permalink
fix infinite recursion in ORMap
Browse files Browse the repository at this point in the history
  • Loading branch information
rmgk committed Nov 28, 2023
1 parent 39fc744 commit 8bd696c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package deltaAntiEntropy.tests
import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
import deltaAntiEntropy.tools.{AntiEntropy, AntiEntropyContainer, Network}
import kofre.base.Bottom
import kofre.datatypes.contextual.{AddWinsSet, ObserveRemoveMap}
import kofre.dotted.Dotted
import replication.JsoniterCodecs.*
import org.scalacheck.Prop.*

Expand All @@ -12,6 +14,18 @@ import scala.collection.mutable
class ORMapTest extends munit.ScalaCheckSuite {
implicit val intCodec: JsonValueCodec[Int] = JsonCodecMaker.make

property("contains") {
given kofre.syntax.ReplicaId = kofre.syntax.ReplicaId.predefined("test")
given Bottom[Int] with
def empty = Int.MinValue
forAll{ (entries: List[Int]) =>
val orMap = entries.foldLeft(Dotted(ObserveRemoveMap.empty[Int, Int])) {(curr, elem) => curr.update(elem, elem)}
orMap.entries.foreach{(k, v) =>
assert(orMap.contains(k))
}
}
}

property("mutateKey/queryKey") {
forAll { (add: List[Int], remove: List[Int], k: Int) =>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object ObserveRemoveMap {
implicit class syntax[C, K, V](container: C)
extends OpsSyntaxHelper[C, ObserveRemoveMap[K, V]](container) {

def contains(using PermQuery)(k: K): Boolean = current.contains(k)
def contains(using PermQuery)(k: K): Boolean = current.inner.repr.contains(k)

def queryKey[A](using PermQuery, Bottom[V])(k: K): V = {
current.inner.repr.getOrElse(k, Bottom[V].empty)
Expand Down

0 comments on commit 8bd696c

Please sign in to comment.