Add few more checks in TestIncrementalProgram tests and one test in TestStoreAwareJournal

This commit is contained in:
Grigorii Kirgizov 2019-05-30 17:48:24 +03:00
parent 5b500340e5
commit 8b4d98f6e2
2 changed files with 81 additions and 3 deletions

View File

@ -78,7 +78,7 @@ class TestIncrementalProgram {
@Test
fun addNewMatch() {
fun addNewMatchAtTheEnd() {
val progSpec = MockIncrProgSpec(
setOf("main", "foo.bar"),
setOf(sym0("foo"))
@ -93,6 +93,7 @@ class TestIncrementalProgram {
))
).launch("addRule", progSpec) { result ->
result.storeView().constraintSymbols() shouldBe setOf(sym0("foo"))
result.lastChunk().activated().constraintSymbols() shouldBe listOf(sym0("foo"))
}.also { (builder, evalRes) ->
builder.programWithRules(
@ -106,6 +107,7 @@ class TestIncrementalProgram {
)
).relaunch("test1", progSpec, evalRes.token()) { result ->
result.storeView().constraintSymbols() shouldBe setOf(sym0("bar"))
result.lastChunk().activated().constraintSymbols() shouldBe listOf(sym0("bar"))
}
}
}
@ -134,6 +136,7 @@ class TestIncrementalProgram {
)
).launch("addRule", progSpec) { result ->
result.storeView().constraintSymbols() shouldBe setOf(sym0("foo"), sym0("bar"))
result.lastChunk().activated().constraintSymbols() shouldBe listOf(sym0("bar"))
}.also { (builder, evalRes) ->
builder.programWithRules(
@ -147,11 +150,13 @@ class TestIncrementalProgram {
)
).relaunch("test1", progSpec, evalRes.token()) { result ->
result.storeView().constraintSymbols() shouldBe setOf(sym0("foo"), sym0("bar"), sym0("baz"))
result.token().journalView.chunks.last().activated().constraintSymbols() shouldBe listOf(sym0("baz"))
result.lastChunk().activated().constraintSymbols() shouldBe listOf(sym0("baz"))
}
}
}
private fun EvaluationResult.lastChunk() = this.token().journalView.chunks.last()
private fun Iterable<Occurrence>.constraintSymbols() = this.map { it.constraint.symbol() }
@Test
@ -253,10 +258,12 @@ class TestIncrementalProgram {
val evalRes1 = p1.launch("initial run", progSpec) { result ->
result.storeView().constraintSymbols() shouldBe setOf(sym0("baz"), sym0("dummy"))
result.lastChunk().activated().constraintSymbols() shouldBe listOf(sym0("dummy"))
}.second
p2.relaunch("test1", progSpec, evalRes1.token()) { result ->
result.storeView().constraintSymbols() shouldBe setOf(sym0("bar"), sym0("baz"), sym0("dummy"))
result.lastChunk().activated().constraintSymbols() shouldBe listOf(sym0("dummy"))
}
}

View File

@ -97,8 +97,79 @@ class TestStoreAwareJournal {
@Test
fun testReplayInitialChunk() {
fun testReplayCorners() {
val mockController = MockController()
with(programWithRules(
rule("rule1",
headKept(
princConstraint("foo")
),
body(
princConstraint("bar")
)),
rule("rule2",
headReplaced(
princConstraint("bar"),
princConstraint("foo")
),
body(
princConstraint("qux")
)),
rule("rule3",
headKept(
princConstraint("qux")
),
body(
princConstraint("lax")
))
))
{
with(JournalDispatcherHelper(Dispatcher(RuleIndex(rulesLists)))) {
val initPos = hist.currentPos()
logExpand(justifiedOccurrence("foo", setOf(1)))
logFirstMatch()
logExpandJustified("bar")
logFirstMatch()
logExpandJustified("qux")
logFirstMatch()
logExpandJustified("lax")
// 'replay' to the saved pos after full 'resetStore' must restore the store
with(hist) {
val lastPos = currentPos()
storeView().constraintSymbols() shouldBe setOf(sym0("qux"), sym0("lax"))
val nchunks = view().chunks.size
nchunks shouldBe 4
// try replay the last chunk
replay(mockController, lastPos)
// should change nothing
storeView().constraintSymbols() shouldBe setOf(sym0("qux"), sym0("lax"))
view().chunks.size shouldBe nchunks
resetStore()
// storeView is reset, but journal remains the same
storeView().allOccurrences().count() shouldBe 0
view().chunks.size shouldBe nchunks
replay(mockController, initPos)
// storeView replays only the initial chunk, journal remains the same
storeView().constraintSymbols() shouldBe setOf(sym0("foo"))
view().chunks.size shouldBe nchunks
}
}
}
}