### ----------------------------------------------------
### -- Statistics
### -- Licenses: Artistic-2.0
### -- Authors: Suman Khanal <suman81765@gmail.com>
### -- File: t/10-misc.rakutest
### ----------------------------------------------------
use Test;
use Statistics;


diag("####    Testing multinomial coefficient    ####");

is multinomial_coef([0, 0]), 1;
is multinomial_coef([0, 0, -0]), 1;
is multinomial_coef((0, 2)), 1;
is-approx multinomial_coef([2.2, 1, 4]), 129.99167999999977, 1e-12;
is-approx multinomial_coef([2.2, 1.2, 4.9]), 284.8258630083825, 1e-12;
is multinomial_coef([1, 1]), 2;
is multinomial_coef([3, 4, 5]), 27720;
is multinomial_coef([3, 4, 5, 9]), 8147739600;
is-approx multinomial_coef([3,1,1,3,4.2, 8, 90, 40]), 2.717246116384229e+69, :rel-tol<0.0001>;
is-approx multinomial_coef([3,1,1,3,4.2, 8, 90, 140]), 1.0317825100856673e+106, 1e-12;
is multinomial_coef([2,4,5,7]), 220540320;
is multinomial_coef_excel([3,1.9,1,3,4.2]), 554400;

diag("####    Testing linspace    ####");
# similar to numpy python function

is linspace(2.1, 3.2, 5, endpoint => False, retstep => False), [2.1, 2.32, 2.54, 2.76, 2.98];
is linspace(1, 3, 3, endpoint => False, retstep => False), [1, 1.666667, 2.333333];
is linspace(1, 3, 3, endpoint => True, retstep => False), [1, 2, 3];
is linspace(1, 3, 3, endpoint => False, retstep => True), ([1, 1.666667, 2.333333], 0.666667);
is "%.16f".sprintf(linspace(1,3,30000)[3000]) , "1.2000066668888962";
is "%.16f".sprintf(linspace(1,3,300000)[3000]), "1.0200000666668890";
is "%.5f".sprintf(linspace(1,3,10)[9]), "3.00000";

is linspace(0, 0, 20, endpoint=>False), (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
is linspace(-1, 0, 20, endpoint => False), (-1,-0.95,-0.9,-0.85,-0.8,-0.75,-0.7,-0.65,-0.6,-0.55,-0.5,-0.45,-0.4,-0.35,-0.3,-0.25,-0.2,-0.15,-0.1,-0.05);


done-testing;


