Skip to content

Commit 689e048

Browse files
committed
test(model-sync-lib): check for operation overlap in random testcase
1 parent cc1284a commit 689e048

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

model-sync-lib/src/test/kotlin/org/modelix/model/sync/ModelImporterTest.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,7 @@ class ModelImporterTest {
101101

102102
@Test
103103
fun `operations do not overlap`() {
104-
val stats = importer.stats ?: fail("No import stats found.")
105-
val additionsSet = stats.additions.toSet()
106-
val deletionsSet = stats.deletions.toSet()
107-
val movesSet = stats.moves.toSet()
108-
109-
assert(additionsSet.intersect(deletionsSet).isEmpty())
110-
assert(deletionsSet.intersect(movesSet).isEmpty())
111-
assert(movesSet.intersect(additionsSet).isEmpty())
104+
assertNoOverlappingOperations(importer.stats)
112105
}
113106

114107
@Test
@@ -168,7 +161,10 @@ class ModelImporterTest {
168161
// println(branch1.getRootNode().toJson())
169162

170163
assertAllNodesConformToSpec(specification, branch1.getRootNode())
171-
assert(importer.stats!!.getTotal() <= numChanges)
164+
assertNoOverlappingOperations(importer.stats)
165+
assert(importer.stats!!.getTotal() <= numChanges) {
166+
"expected operations: <= $numChanges, actual: ${importer.stats!!.getTotal()}"
167+
}
172168
}
173169
}
174170
}

model-sync-lib/src/test/kotlin/org/modelix/model/sync/SyncTestUtil.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,15 @@ internal fun assertNodeChildOrderConformsToSpec(expected: NodeData, actual: INod
5656
val specifiedOrder = expected.children.groupBy {it.role}.mapValues { (_, children) -> children.map { it.originalId() }}
5757
val actualOrder = actual.allChildren.groupBy { it.roleInParent }.mapValues { (_, children) -> children.map { it.originalId() }}
5858
assertEquals(specifiedOrder, actualOrder)
59+
}
60+
61+
internal fun assertNoOverlappingOperations(stats: ImportStats?) {
62+
stats ?: fail("No import stats found.")
63+
val additionsSet = stats.additions.toSet()
64+
val deletionsSet = stats.deletions.toSet()
65+
val movesSet = stats.moves.toSet()
66+
67+
assert(additionsSet.intersect(deletionsSet).isEmpty())
68+
assert(deletionsSet.intersect(movesSet).isEmpty())
69+
assert(movesSet.intersect(additionsSet).isEmpty())
5970
}

0 commit comments

Comments
 (0)