From 8b4d98f6e274cda679d3add48f432dd837702e27 Mon Sep 17 00:00:00 2001 From: Grigorii Kirgizov Date: Thu, 30 May 2019 17:48:24 +0300 Subject: [PATCH] Add few more checks in TestIncrementalProgram tests and one test in TestStoreAwareJournal --- reactor/Test/test/TestIncrementalProgram.kt | 11 +++- reactor/Test/test/TestStoreAwareJournal.kt | 73 ++++++++++++++++++++- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/reactor/Test/test/TestIncrementalProgram.kt b/reactor/Test/test/TestIncrementalProgram.kt index 0a7a6dd1..fef941df 100644 --- a/reactor/Test/test/TestIncrementalProgram.kt +++ b/reactor/Test/test/TestIncrementalProgram.kt @@ -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.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")) } } diff --git a/reactor/Test/test/TestStoreAwareJournal.kt b/reactor/Test/test/TestStoreAwareJournal.kt index 6d85986f..f81305a9 100644 --- a/reactor/Test/test/TestStoreAwareJournal.kt +++ b/reactor/Test/test/TestStoreAwareJournal.kt @@ -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 + } + } + } }