Fix MatchHistory tests: fix impl of storeView, taking into account current pos in history (not all of it)
This commit is contained in:
parent
c4309084c5
commit
e5942d2c77
|
|
@ -36,7 +36,8 @@ internal class ControllerImpl (
|
|||
{
|
||||
|
||||
/** For tests only */
|
||||
override fun storeView(): StoreView = state.storeView()
|
||||
// override fun storeView(): StoreView = state.storeView()
|
||||
override fun storeView(): StoreView = TODO()
|
||||
|
||||
/** For tests only */
|
||||
override fun evaluate(occ: Occurrence): StoreView {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package jetbrains.mps.logic.reactor.core.internal
|
|||
|
||||
import gnu.trove.set.TIntSet
|
||||
import gnu.trove.set.hash.TIntHashSet
|
||||
import jetbrains.mps.logic.reactor.core.Dispatcher
|
||||
import jetbrains.mps.logic.reactor.core.Occurrence
|
||||
import jetbrains.mps.logic.reactor.evaluation.ConstraintOccurrence
|
||||
import jetbrains.mps.logic.reactor.evaluation.RuleMatch
|
||||
|
|
@ -69,8 +70,8 @@ interface MatchHistory {
|
|||
fun rollTo(chunk: Chunk)
|
||||
|
||||
companion object {
|
||||
fun fromSeed(chunkIdSeed: Int = 0): MatchHistory = MatchHistoryImpl(ProcessingStateImpl(), chunkIdSeed)
|
||||
fun fromView(view: MatchHistory.View): MatchHistory = MatchHistoryImpl(ProcessingStateImpl(), view)
|
||||
fun fromSeed(disp: Dispatcher, chunkIdSeed: Int = 0): MatchHistory = MatchHistoryImpl(ProcessingStateImpl(disp), chunkIdSeed)
|
||||
fun fromView(disp: Dispatcher, view: MatchHistory.View): MatchHistory = MatchHistoryImpl(ProcessingStateImpl(disp), view)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -109,13 +110,19 @@ internal class MatchHistoryImpl(val state: ProcessingStateImpl, view: MatchHisto
|
|||
pos = hist.listIterator()
|
||||
}
|
||||
|
||||
// TODO:
|
||||
override fun storeView(): StoreView = StoreViewImpl(allOccurrences())
|
||||
|
||||
private fun allOccurrences(): Sequence<Occurrence> {
|
||||
// the following lop doesn't handle this case of starting pos, when 'current' isn't valid
|
||||
if (!pos.hasPrevious())
|
||||
return emptySequence()
|
||||
|
||||
val set = HashSet<Id<Occurrence>>()
|
||||
hist.flatMap { it.occurrences } .forEach {
|
||||
if (it.isDiscarded) set.add(Id(it.occ)) else set.remove(Id(it.occ))
|
||||
for (chunk in hist) {
|
||||
chunk.occurrences.forEach {
|
||||
if (it.isDiscarded) set.remove(Id(it.occ)) else set.add(Id(it.occ))
|
||||
}
|
||||
if (chunk == current) break
|
||||
}
|
||||
return set.map { it.wrapped }.asSequence()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ fun occurrence(id: String, vararg args: Any): Occurrence =
|
|||
MockConstraint(ConstraintSymbol.symbol(id, args.size)).occurrence(MockController(), listOf(* args))
|
||||
|
||||
fun justifiedOccurrence(id: String, justs: TIntSet, vararg args: Any): Occurrence =
|
||||
MockConstraint(ConstraintSymbol.symbol(id, args.size), true).occurrence(listOf(* args), { fooObservable }, justs)
|
||||
MockConstraint(ConstraintSymbol.symbol(id, args.size), true).occurrence(MockController(), listOf(* args), justs)
|
||||
fun justifiedOccurrence(id: String, justs: Set<Int>, vararg args: Any): Occurrence = justifiedOccurrence(id, TIntHashSet(justs), * args)
|
||||
|
||||
fun sym0(id: String): ConstraintSymbol =
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ class TestMatchHistory {
|
|||
|
||||
@Test
|
||||
fun testJustificationTracking() {
|
||||
val hist = MatchHistory.fromSeed()
|
||||
|
||||
with(programWithRules(
|
||||
rule("rule1",
|
||||
headKept(
|
||||
|
|
@ -60,7 +58,9 @@ class TestMatchHistory {
|
|||
))))
|
||||
{
|
||||
|
||||
var d = Dispatcher(RuleIndex(rulesLists)).front()
|
||||
val disp = Dispatcher(RuleIndex(rulesLists))
|
||||
var d = disp.front()
|
||||
val hist = MatchHistory.fromSeed(disp)
|
||||
val mainOcc = justifiedOccurrence("main", setOf(0))
|
||||
// hist.logOccurrence(mainOcc) // plays a role of the initial constraint, with no preceding RuleMatch
|
||||
d = d.expand(mainOcc)
|
||||
|
|
@ -122,8 +122,6 @@ class TestMatchHistory {
|
|||
|
||||
@Test
|
||||
fun testResetThenRoll() {
|
||||
val hist = MatchHistory.fromSeed()
|
||||
|
||||
with(programWithRules(
|
||||
rule("rule1",
|
||||
headKept(
|
||||
|
|
@ -150,7 +148,9 @@ class TestMatchHistory {
|
|||
))
|
||||
{
|
||||
|
||||
var d = Dispatcher(RuleIndex(rulesLists)).front()
|
||||
val disp = Dispatcher(RuleIndex(rulesLists))
|
||||
var d = disp.front()
|
||||
val hist = MatchHistory.fromSeed(disp)
|
||||
val mainOcc = justifiedOccurrence("main", setOf(0))
|
||||
// hist.logOccurrence(mainOcc) // plays a role of the initial constraint, with no preceding RuleMatch
|
||||
d = d.expand(mainOcc)
|
||||
|
|
@ -195,8 +195,6 @@ class TestMatchHistory {
|
|||
|
||||
@Test
|
||||
fun testPushExecReset() {
|
||||
val hist = MatchHistory.fromSeed()
|
||||
|
||||
with(programWithRules(
|
||||
rule("rule1",
|
||||
headKept(
|
||||
|
|
@ -233,7 +231,9 @@ class TestMatchHistory {
|
|||
))
|
||||
{
|
||||
|
||||
var d = Dispatcher(RuleIndex(rulesLists)).front()
|
||||
val disp = Dispatcher(RuleIndex(rulesLists))
|
||||
var d = disp.front()
|
||||
val hist = MatchHistory.fromSeed(disp)
|
||||
val mainOcc = justifiedOccurrence("main", setOf(0))
|
||||
d = d.expand(mainOcc)
|
||||
|
||||
|
|
@ -305,8 +305,6 @@ class TestMatchHistory {
|
|||
|
||||
@Test
|
||||
fun testRmAddInMiddle() {
|
||||
val hist = MatchHistory.fromSeed()
|
||||
|
||||
with(programWithRules(
|
||||
rule("rule0",
|
||||
headKept(
|
||||
|
|
@ -370,7 +368,9 @@ class TestMatchHistory {
|
|||
// fst exec: rule1 -> rule2a -> rule3 -> ruleMakeP
|
||||
// snd exec: rule1 -> rule2b -> ruleMakeP -> rule3 -> ruleMakeP
|
||||
|
||||
var d = Dispatcher(RuleIndex(rulesLists)).front()
|
||||
val disp = Dispatcher(RuleIndex(rulesLists))
|
||||
var d = disp.front()
|
||||
val hist = MatchHistory.fromSeed(disp)
|
||||
val mainOcc = justifiedOccurrence("main", setOf(0))
|
||||
d = d.expand(mainOcc)
|
||||
|
||||
|
|
@ -471,7 +471,7 @@ class TestMatchHistory {
|
|||
val pOcc2 = justifiedOccurrence("p", hist.current().justifications)
|
||||
hist.logOccurrence(pOcc2); d = d.expand(pOcc2)
|
||||
|
||||
|
||||
// only pOcc2 should be in the store
|
||||
val pStoredBeforeRoll = hist.storeView().occurrences(ConstraintSymbol.symbol("p", 0))
|
||||
pStoredBeforeRoll.count() shouldBe 1
|
||||
// todo?: check history before roll
|
||||
|
|
|
|||
Loading…
Reference in New Issue