### ----------------------------------------------------
### -- Math::Polynomial::Chebyshev
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/02-chebyshev-u.rakutest
### ----------------------------------------------------
use v6.d;

use lib <. lib>;

use Math::Polynomial::Chebyshev;
use Test;

plan 16;

my $method = 'recursive';

{
    is-approx chebyshev-u(0, 0, :$method), 1, "Constant is correctly boring";
    is-approx chebyshev-u(0, 1/2, :$method), 1, "Constant is still correctly boring";
}

{

    is-approx chebyshev-u(1, -1/2, :$method), -1, "Linear -1/2 is correct";
    is-approx chebyshev-u(1, 0, :$method), 0, "Linear 0 is correct";
    is-approx chebyshev-u(1, 1/2, :$method), 1, "Linear 1/2 is correct";
}

{
    is-approx chebyshev-u(2, -1/2, :$method), 0, "Quadratic -1/2 is correct";
    is-approx chebyshev-u(2, 0, :$method), -1, "Quadratic 0 is correct";
    is-approx chebyshev-u(2, 1/2, :$method), 0, "Quadratic 1/2 is correct";
}

{
    is-approx chebyshev-u(10, -1/2, :$method), -1, "10th polynomial at -1/2 is correct";
    is-approx chebyshev-u(10, 0, :$method), -1, "10th polynomial at 0 is correct";
    is-approx chebyshev-u(10, 1/2, :$method), -1, "10th polynomial at 1/2 is correct";
}

{
    is-deeply chebyshev-u(3, [-1/2, 0, 1/2], :$method), [1.0, 0, -1.0], "Cubic vector is correct";
}

{
    my $k = 4;
    my @x = (-1.0, -0.9 ... 1.0);

    my @data1 = @x.map({ chebyshev-u($k, $_, :$method) });
    my @data2 = chebyshev-u($k, @x);

    is-deeply @data1, @data2, "Point and vector invokations give the same results";
}

{
    isa-ok chebyshev-u(4, :$method), Callable:D, 'Getting a Callable without x-argument';
    isa-ok chebyshev-u(4, Whatever, :$method), Callable:D, 'Getting a Callable with Whatever as an x-argument';

    my &f = chebyshev-u(4, :$method);
    is-deeply (^5)».&f.Array, chebyshev-u(4, (^5)), 'Same result with function over data and data argument'
}


