Implement CommonizerTarget.allLeaves
This commit is contained in:
@@ -111,6 +111,10 @@ public fun CommonizerTarget.withAllAncestors(): Set<CommonizerTarget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun CommonizerTarget.allLeaves(): Set<LeafCommonizerTarget> {
|
||||||
|
return withAllAncestors().filterIsInstance<LeafCommonizerTarget>().toSet()
|
||||||
|
}
|
||||||
|
|
||||||
public infix fun CommonizerTarget.isAncestorOf(other: CommonizerTarget): Boolean {
|
public infix fun CommonizerTarget.isAncestorOf(other: CommonizerTarget): Boolean {
|
||||||
if (this is SharedCommonizerTarget) {
|
if (this is SharedCommonizerTarget) {
|
||||||
return targets.any { it == other } || targets.any { it.isAncestorOf(other) }
|
return targets.any { it == other } || targets.any { it.isAncestorOf(other) }
|
||||||
|
|||||||
+23
@@ -53,5 +53,28 @@ class CommonizerTargetUtilsTest {
|
|||||||
"Expected all targets present"
|
"Expected all targets present"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun allLeaves() {
|
||||||
|
val target = parseCommonizerTarget("((a, b), (c, d), (e, (f, g)))")
|
||||||
|
assertEquals(
|
||||||
|
setOf(
|
||||||
|
LeafCommonizerTarget("a"),
|
||||||
|
LeafCommonizerTarget("b"),
|
||||||
|
LeafCommonizerTarget("c"),
|
||||||
|
LeafCommonizerTarget("d"),
|
||||||
|
LeafCommonizerTarget("e"),
|
||||||
|
LeafCommonizerTarget("f"),
|
||||||
|
LeafCommonizerTarget("g")
|
||||||
|
),
|
||||||
|
target.allLeaves(),
|
||||||
|
"Expected leaf targets present"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
setOf(LeafCommonizerTarget("a")), LeafCommonizerTarget("a").allLeaves(),
|
||||||
|
"Expected LeafCommonizerTarget returns itself in 'allLeaves'"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user