|
Groovy example source code file (NavigationTest.groovy)
The Groovy NavigationTest.groovy source code
package groovy.tree
/**
* Simple test of tree walking
*/
class NavigationTest extends GroovyTestCase {
void testDepthFirst() {
def tree = createTree()
def names = tree.depthFirst().collect { it.name() }
def expected = ['a', 'b1', 'b2', 'c1', 'c2', 'b3', 'b4', 'c3', 'c4', 'b5']
assert names == expected
}
void testBreadthFirst() {
def tree = createTree()
def names = tree.breadthFirst().collect { it.name() }
def expected = ['a', 'b1', 'b2', 'b3', 'b4', 'b5', 'c1', 'c2', 'c3', 'c4']
assert names == expected
}
protected def createTree() {
def b = NodeBuilder.newInstance()
def root = b.a(a:5, b:7) {
b1()
b2 {
c1()
c2()
}
b3()
b4 {
c3()
c4()
}
b5()
}
assert root != null
println(root)
return root
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy NavigationTest.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.