### ----------------------------------------------------
### -- Statistics
### -- Licenses: Artistic-2.0
### -- Authors: Suman Khanal <suman81765@gmail.com>
### -- File: t/01-descriptive.rakutest
### ----------------------------------------------------
use Test;
use Statistics;
# use Descriptive::CentralTendency;
# use Descriptive::Dispersion;
# use Descriptive::FiveNum;

diag("Testing mean, median, range, variance, coef-variation, fivenum...");

my @new_data = [1,2,3,4,5,5,6,6,6];
my @data = [6,6,4,6,8,6,8,4,4,6,6,8,8,8,8,8,8,4,4,4,4,8,8,8,8,4,4,4,8,6,8,4];
is-approx mean(@new_data), 4.222222;
is mean([3, 4]), 3.5;
is mean(@data), 6.1875;
is mean([0]), 0;


is geometric_mean([1,1,2,3.8]), 1.660364342672428;
is-approx geometric_mean([1, 3, 5, 7, 9, 11, 13]), 5.407130298648435, 0.000000001;
is geometric_mean([1, 0.3, 5, 7.2, 9, 11]), 3.197740065288673;



my @test_data = [1,2,3,4,5,5,6,6,6,10];
is median(@new_data), 5;
is median(@test_data), 5;
is median(@data), 6;

is range([1]), (1,1);
is range([1,2,5,6,7,8]), (1,8);
# is range([1,2,5,6,7,8, "a","b","z"]), (1,"z");

is range([1,2,5,6,7,8, "a","b","z"]), (1,"z");
is range(["a","b","y","w","x"]), ("a","y");

my @test-data2 = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5];
my @test-data3 = [0.0, 0.25, 0.25, 1.25, 1.5, 1.75, 2.75, 3.25];

is-approx variance(@test-data2), 1.3720238095238095;
is variance(@test-data3, sample => False), 1.25;
is-approx sd(@test-data2), 1.171334200612195;
is-approx sd(@test-data2, sample => False), 1.084444746477784;

is-approx sd(@data), 1.7859216469465444;
is-approx sd(@data, sample => False), 1.757795138803154;


is-approx coef_variation(@data), 28.863380152671;
is-approx coef_variation(@test-data3), 86.9257170425;


my @data1 = [160.0,160.0,108.0,258.0,360.0,225.0,360.0,146.7,140.8,167.6,167.6,275.8,275.8,275.8,
             472.0,460.0,440.0,78.7,75.7,71.1,120.1,318.0,304.0,350.0,400.0,79.0,120.3,95.1,351.0,145.0,301.0,121.0];
my @data2 = [1,2,3];

my @data3 = [1,2];
my @data4 = [1];


is fivenum(@data1), (71.1, 120.65, 196.3, 334.0, 472.0);
is fivenum(@data2), (1, 1.5, 2, 2.5, 3);
is fivenum(@data3), (1, 1, 1.5, 2, 2);
is fivenum(@data4), (1, 1, 1, 1, 1);

done-testing


