### ----------------------------------------------------
### -- Math::SparseMatrix::Native
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/01-creation.rakutest
### ----------------------------------------------------
use v6.d;

#use lib <. lib>;
use Math::SparseMatrix::Native;
use Math::SparseMatrix::Native::Utilities;
use Test;

my $nrow = 5;
my $ncol = 8;
my $density = 0.25;
my $nnz = ($nrow * $ncol * $density).Int;
my $seed = 7834;

## 1
ok Math::SparseMatrix::Native::CSRStruct.new.random(:$nrow, :$ncol, :$nnz, :$seed);

## 2
my $matrix1 = Math::SparseMatrix::Native::CSRStruct.new.random(:$nrow, :$ncol, :$nnz, :$seed);
my $matrix2 = Math::SparseMatrix::Native::CSRStruct.new.random(nrow => $ncol, ncol => $nrow, :$nnz, :$seed);

subtest {
    isa-ok $matrix1, Math::SparseMatrix::Native::CSRStruct:D;
    isa-ok $matrix2, Math::SparseMatrix::Native::CSRStruct:D;
}, "Expected types";

## 3
isa-ok
        Math::SparseMatrix::Native::CSRStruct.new(dense-matrix => $matrix1.Array),
        Math::SparseMatrix::Native::CSRStruct:D,
        "Creation from dense matrix";

## 4
my $matrix3 = Math::SparseMatrix::Native::CSRStruct.new(dense-matrix => $matrix1.Array);
is-deeply
        $matrix3.Array,
        $matrix1.Array,
        "Same matrice (random vs dense-array)";

## 5
subtest {
    my @rules = (1, 1) => 1, (0, 1) => 3, (3, 4) => -1;
    ok Math::SparseMatrix::Native::CSRStruct.new(:@rules);
    my $matrix = Math::SparseMatrix::Native::CSRStruct.new(:@rules);
    is-deeply $matrix.dimensions, (4, 5);
    $matrix2 = Math::SparseMatrix::Native::CSRStruct.new(:@rules, :6nrow, :8ncol);
    is-deeply $matrix2.dimensions, (6, 8);
    my @dense-matrix = [0, 3, 0, 0, 0], [0, 1, 0, 0, 0], (0 xx 5).Array,  [0, 0, 0, 0, -1];
    @dense-matrix .= deepmap(*.Num);
    is-deeply
            $matrix.Array,
            @dense-matrix,
            "Same dense arrays";
    }, "Creation from rules";

done-testing;


