minmaxtest.groovy
来自「大名鼎鼎的java动态脚本语言。已经通过了sun的认证」· GROOVY 代码 · 共 50 行
GROOVY
50 行
/** * Tests the min() and max() functions * * @author <a href="mailto:james@coredevelopers.net">James Strachan</a> * @version $Revision: 1.5 $ */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 + -
显示快捷键?