[poincare] Integer: fix and add tests on Factorial

This commit is contained in:
Émilie Feral
2018-08-16 11:18:44 +02:00
parent e0dbb59c20
commit 3371d41b2c
2 changed files with 9 additions and 1 deletions

View File

@@ -336,7 +336,7 @@ Integer NaturalIntegerAbstract::upow(const NaturalIntegerAbstract * i, const Nat
Integer NaturalIntegerAbstract::ufact(const NaturalIntegerAbstract * i) {
Integer j(2);
Integer result(1);
while (ucmp(i,j.node()) > 0) {
while (ucmp(i,j.node()) >= 0) {
result = Integer::Multiplication(j, result);
j = Integer::Addition(j, Integer(1));
}

View File

@@ -197,6 +197,14 @@ QUIZ_CASE(poincare_integer_pow) {
assert_pow_to(Integer("12345678910111213141516171819202122232425"), Integer(2), Integer("152415787751564791571474464067365843004067618915106260955633159458990465721380625"));
}
static inline void assert_factorial_to(const Integer i, const Integer j) {
assert(Integer::NaturalOrder(Integer::Factorial(i), j) == 0);
}
QUIZ_CASE(poincare_integer_factorial) {
assert_factorial_to(Integer(5), Integer(120));
assert_factorial_to(Integer(123), Integer("12146304367025329675766243241881295855454217088483382315328918161829235892362167668831156960612640202170735835221294047782591091570411651472186029519906261646730733907419814952960000000000000000000000000000"));
}
// Simplify
template<typename T>