minmaxtest.groovy
来自「Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业」· GROOVY 代码 · 共 50 行
GROOVY
50 行
/**
* Tests the min() and max() functions
*
* @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
* @version $Revision: 2289 $
*/
class MinMaxTest extends GroovyTestCase {
void testSimpleMinMax() {
def list = [5, 2, 6, 1, 9, 8]
def n = list.min()
assert n == 1
n = list.max()
assert n == 9
}
void testMinMaxWithComparator() {
def people = getPeople()
// lets find the maximum by name
def order = new OrderBy( { it.get('@cheese') } )
println("People ${people}")
def p = people.min(order)
println("Found ${p}")
assert p.get("@name") == "Joe" , "found person ${p}"
p = people.max(order)
assert p.get("@name") == "Chris" , "found person ${p}"
}
def getPeople() {
def builder = new NodeBuilder()
def tree = builder.people {
person(name:'James', cheese:'Edam', location:'London')
person(name:'Bob', cheese:'Cheddar', location:'Atlanta')
person(name:'Chris', cheese:'Red Leicester', location:'London')
person(name:'Joe', cheese:'Brie', location:'London')
}
return tree.children()
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?