forked from Mirror/wren
Reorganize tests and benchmark scripts.
Mainly to get rid of one top level directory. But this will also be useful when there are tests of the embedding API.
This commit is contained in:
14
test/core/list/reduce.wren
Normal file
14
test/core/list/reduce.wren
Normal file
@ -0,0 +1,14 @@
|
||||
var a = [1, 4, 2, 1, 5]
|
||||
var b = ["W", "o", "r", "l", "d"]
|
||||
var max = new Fn {|a, b| a > b ? a : b }
|
||||
var sum = new Fn {|a, b| a + b }
|
||||
|
||||
IO.print(a.reduce(max)) // expect: 5
|
||||
IO.print(a.reduce(10, max)) // expect: 10
|
||||
|
||||
IO.print(a.reduce(sum)) // expect: 13
|
||||
IO.print(a.reduce(-1, sum)) // expect: 12
|
||||
|
||||
// sum also concatenates strings
|
||||
IO.print(b.reduce("Hello ", sum)) // expect: Hello World
|
||||
IO.print(b.reduce(sum)) // expect: World
|
||||
Reference in New Issue
Block a user