From f00ab975dc355451c881d683820416ba6b02ce2a Mon Sep 17 00:00:00 2001 From: Adrian Kuta Date: Tue, 21 Jan 2020 15:11:04 +0100 Subject: [PATCH] Fixed tree initialization in Kotlin --- .../adriankuta/datastructure/tree/TreeNode.kt | 2 +- .../datastructure/tree/TreeNodeTest.kt | 29 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNode.kt b/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNode.kt index 43f4c65..4f8461f 100644 --- a/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNode.kt +++ b/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNode.kt @@ -27,7 +27,7 @@ open class TreeNode(val value: T) : Iterable>, ChildDeclarationIn } @JvmSynthetic - override fun child(child: T, childDeclaration: ChildDeclaration?) { + override fun child(value: T, childDeclaration: ChildDeclaration?) { val newChild = TreeNode(value) if(childDeclaration != null) newChild.childDeclaration() diff --git a/treedatastructure/src/test/java/com/github/adriankuta/datastructure/tree/TreeNodeTest.kt b/treedatastructure/src/test/java/com/github/adriankuta/datastructure/tree/TreeNodeTest.kt index 6ad71b5..c1f17eb 100644 --- a/treedatastructure/src/test/java/com/github/adriankuta/datastructure/tree/TreeNodeTest.kt +++ b/treedatastructure/src/test/java/com/github/adriankuta/datastructure/tree/TreeNodeTest.kt @@ -128,18 +128,31 @@ class TreeNodeTest { europe.addChild(poland) europe.addChild(france) - val rootExt = treeNode("World") { - treeNode("North America") { - treeNode("USA") + val rootExt = tree("World") { + child("North America") { + child("USA") } - treeNode("Europe") { - treeNode("Poland") - treeNode("France") + child("Europe") { + child("Poland") + child("France") } } - println(root) - assertEquals(root.toString(), rootExt.toString()) + assertEquals(root.prettyString(), rootExt.prettyString()) } +// @Test +// fun getVisibleNodes() { +// val root = tree("World") { +// child("Level 1") { +// child("Level 2") { +// child("Level 3") { +// child("Level 4") +// } +// } +// } +// } +// +// print(root.prettyString()) +// } } \ No newline at end of file