// regression tests for bignum.k if(Load("examples/bignum.k"); Error("cannot open file")); /* uncomment when called stand-alone and not from regtest.k ::nerr = 0, ::ntest= 0, PTEST() = (Print(Sprintf("Test %i", ++ntest))); DOTEST(ok) = (if(ok==1; PrintLn(" ok"); (PrintLn(" nok !!!!!!"), ++nerr)), ok); */ // divtest with remainder = 0 divtest(a ,b) = (c=divBn(a, b), mulBn(c, b) == a); // divtest with remainder != 0 divtest_rem(a ,b) = (c=divBn(a, b), addBn(mulBn(c, b), ::divBn_remainder) == a); bignum_test() = ( base={10, 1e6, 0x10000}, ForEach(base,'bignum_test(#)'), ::nerr ); bignum_test(base) = ( ::BIG_NUM_BASE = base, // test for P1a in base 10 PTEST(), DOTEST(divtest_rem(Bn(6000), Bn(61))), // test for P1b in base 10 PTEST(), DOTEST(divtest_rem(Bn(1800),Bn(99))), // test for P2 in base 10 PTEST(), DOTEST(divtest_rem(Bn(3500),Bn(59))), // test for P3 in base 10 PTEST(), DOTEST(divtest_rem(Bn(10000), Bn(501))), PTEST(), DOTEST((f1=fak1Bn(100), f2=fak1Bn(50), divtest(f1, f2))), PTEST(), DOTEST((f1=fak1Bn(100), f2=addBn(fak1Bn(50),Bn(1)), divtest_rem(f1, f2))), if(base>10; PTEST(), DOTEST(Bn2string(string2Bn("12345678901234567890", 10), 10)=="12345678901234567890") ), ::nerr );