mirror of
https://github.com/AdrianKuta/Tree-Data-Structure.git
synced 2025-04-19 23:19:03 +02:00
Fixed tree initialization in Kotlin
This commit is contained in:
parent
eb2d5f07be
commit
f00ab975dc
@ -27,7 +27,7 @@ open class TreeNode<T>(val value: T) : Iterable<TreeNode<T>>, ChildDeclarationIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
override fun child(child: T, childDeclaration: ChildDeclaration<T>?) {
|
override fun child(value: T, childDeclaration: ChildDeclaration<T>?) {
|
||||||
val newChild = TreeNode(value)
|
val newChild = TreeNode(value)
|
||||||
if(childDeclaration != null)
|
if(childDeclaration != null)
|
||||||
newChild.childDeclaration()
|
newChild.childDeclaration()
|
||||||
|
@ -128,18 +128,31 @@ class TreeNodeTest {
|
|||||||
europe.addChild(poland)
|
europe.addChild(poland)
|
||||||
europe.addChild(france)
|
europe.addChild(france)
|
||||||
|
|
||||||
val rootExt = treeNode("World") {
|
val rootExt = tree("World") {
|
||||||
treeNode("North America") {
|
child("North America") {
|
||||||
treeNode("USA")
|
child("USA")
|
||||||
}
|
}
|
||||||
treeNode("Europe") {
|
child("Europe") {
|
||||||
treeNode("Poland")
|
child("Poland")
|
||||||
treeNode("France")
|
child("France")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println(root)
|
assertEquals(root.prettyString(), rootExt.prettyString())
|
||||||
assertEquals(root.toString(), rootExt.toString())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
// fun getVisibleNodes() {
|
||||||
|
// val root = tree("World") {
|
||||||
|
// child("Level 1") {
|
||||||
|
// child("Level 2") {
|
||||||
|
// child("Level 3") {
|
||||||
|
// child("Level 4")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// print(root.prettyString())
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user