Skip to content

Instantly share code, notes, and snippets.

Created March 19, 2010 10:38
Show Gist options
  • Save anonymous/337408 to your computer and use it in GitHub Desktop.
Save anonymous/337408 to your computer and use it in GitHub Desktop.
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