Created
March 19, 2010 10:38
-
-
Save anonymous/337408 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BindTest extends TestCase { | |
var seq: Bean[]; | |
var tmp: Number[] = bind for (bean: Bean in seq) { | |
sum(bean) | |
}; | |
bound function sum(bean:Bean):Number { | |
return bean.x * bean.y | |
} | |
var bean1:Bean = Bean { | |
x: 2, y:4 | |
} | |
var bean2:Bean = Bean { | |
x: 1, y:2 | |
} | |
function totalSum(tmp: Number[]): Number { | |
var result: Number = 0.0; | |
for (number: Number in tmp) { | |
result += number; | |
} | |
return result | |
} | |
var result: Double = bind totalSum(tmp) on replace oldValue = newValue { | |
println(newValue); | |
} | |
public function testBind() { | |
println("Inserting bean 1"); | |
insert bean1 into seq; | |
Assert.assertEquals(result, Double.valueOf(8)); | |
println("Inserting bean 2"); | |
insert bean2 into seq; | |
Assert.assertEquals(result, Double.valueOf(10)); | |
println("Modifiying bean 1"); | |
bean1.x = 5; | |
Assert.assertEquals(result, Double.valueOf(22)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment