Create a gist now

Instantly share code, notes, and snippets.

anonymous /BindTest.fx
Created Mar 19, 2010

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