26.2 Test binomial
The following works, but is non-recursive.
671⟨test binomial 671⟩≡ (669) 672 ⊳
testBinomial1(): () == {
import from I, Integer;
assertEq(z: Integer, n: I, k: I): () == {
assertEquals(Integer, z, binomial(n, k)$MultinomialTools);
}
assertEq(1, 0, 0);
assertEq(1, 1, 0);
assertEq(1, 1, 1);
assertEq(0, 0, 1);
assertEq(0, 0, -1);
assertEq(1, -1, 0);
assertEq(-1,-1, 1);
assertEq(-1, -1, 5);
}
Uses I 47, Integer 66, and MultinomialTools 367.
In the following function, we only need N and K in order to recognize where the
test failed.
672⟨test binomial 671⟩+
≡ (669) ⊲671
testBinomial2(): () == {
import from I, Integer;
assertEq(z: Integer, n: I, k: I): () == {
N: Integer := n::Integer;
K: Integer := k::Integer;
b: Integer := binomial(n, k)$MultinomialTools;
import from List Integer;
assertEquals(List Integer, [N, K, z], [N, K, b]);
}
for n: I in 0..100 repeat for k: I in 0..n repeat {
assertEq(binomialAux(n, k), n, k);
}
}
Uses I 47, Integer 66, and MultinomialTools 367.