blob: 1d929c0fbe311b29e10e7ae857b08631ee75d45e [file] [log] [blame]
var rnd = new Native('java.util.Random');
@test
operation allInstancesWorks() {
if (Class.all.size <> 6) {
'allInstancesWorks failed!'.println();
}
}
@test
operation failingTest() {
if (1 + 1 <> 1) {
'failingTest failed!'.println();
}
}
@test
$times 10 * 10
operation randomTest() {
var base = 2 + rnd.nextInt(9);
var exp = rnd.nextInt(10);
if (slowPow(base, exp) <> fastPow(base, exp)) {
'randomTest failed!'.println();
}
}
operation fastPow(base, exp) {
if (exp == 0) {
return 1;
} else if (exp == 1) {
return base;
} else if (exp.mod(2) == 0) {
return fastPow(base * base, exp/2);
} else {
return base * fastPow(base * base, (exp - 1)/2);
}
}
operation slowPow(base, exp) {
var result = 1;
while (exp >= 1) {
result *= base;
exp -= 1;
}
return result;
}