<commit_before>use v6;

use Test;

plan 129;

=begin pod

Basic tests functions specific to complex numbers.

L<S29/Num/"=item cis">

=end pod

my $pi = 3.141592653589793238;

{
    is_approx(cis(0),        1 + 0i,       "cis(0)     == 1");
    is_approx(cis($pi),      -1 + 0i,      "cis(pi)    == -1");
    is_approx(cis($pi / 2),  1i,           "cis(pi/2)  == i");
    #?rakudo todo "prefix:<-> not implemented for Complex"
    is_approx(cis(3*$pi / 2),-1i,          "cis(3pi/2) == i");
}

# L<S29/Num/"=item cis">
# L<S29/Num/"=item unpolar">
#
# Test that 1.unpor == cis

{
    for 1..20 -> $i {
        my $angle = 2 * $pi * $i / 20;
        is_approx(cis($i), 1.unpolar($i), "cis(x) == 1.unpolar(x) No $i");
    }
}

# L<S29/Num/"=item unpolar">
# L<S29/Num/"=item abs">
#
# Test that unpolar() doesn't change the absolute value

{
    my $counter = 1;
    for 1..10 -> $abs {
        for 1..10 -> $a {
            my $angle = 2 * $pi * $a / 10;
            is_approx(abs($abs.unpolar($angle)), $abs,
                    "unpolar doesn't change the absolute value (No $counter)");
            $counter++;
        }
    }
}

{
    # L<S29/Num/"=item unpolar">
    #
    # Basic tests for unpolar()

    is_approx(4.unpolar(0),         4,     "4.unpolar(0)    == 4");
    #?rakudo todo "test incorrect"
    is_approx(4.unpolar($pi/4),     2 + 2i,"4.unpolar(pi/4) == 2+2i");
    is_approx(4.unpolar($pi/2),     4i,    "4.unpolar(pi/2) == 4i");
    #?rakudo todo "test incorrect"
    is_approx(4.unpolar(3*$pi/4),   -2 +2i,"4.unpolar(pi/4) == -2+2i");
    is_approx(4.unpolar($pi),       -4,    "4.unpolar(pi)   == -4");
}<commit_msg>[spec] S29-num/complex.t: fixed two tests<commit_after>use v6;

use Test;

plan 129;

=begin pod

Basic tests functions specific to complex numbers.

L<S29/Num/"=item cis">

=end pod

my $pi = 3.141592653589793238;

{
    is_approx(cis(0),        1 + 0i,       "cis(0)     == 1");
    is_approx(cis($pi),      -1 + 0i,      "cis(pi)    == -1");
    is_approx(cis($pi / 2),  1i,           "cis(pi/2)  == i");
    #?rakudo todo "prefix:<-> not implemented for Complex"
    is_approx(cis(3*$pi / 2),-1i,          "cis(3pi/2) == -i");
}

# L<S29/Num/"=item cis">
# L<S29/Num/"=item unpolar">
#
# Test that 1.unpor == cis

{
    for 1..20 -> $i {
        my $angle = 2 * $pi * $i / 20;
        is_approx(cis($i), 1.unpolar($i), "cis(x) == 1.unpolar(x) No $i");
    }
}

# L<S29/Num/"=item unpolar">
# L<S29/Num/"=item abs">
#
# Test that unpolar() doesn't change the absolute value

{
    my $counter = 1;
    for 1..10 -> $abs {
        for 1..10 -> $a {
            my $angle = 2 * $pi * $a / 10;
            is_approx(abs($abs.unpolar($angle)), $abs,
                    "unpolar doesn't change the absolute value (No $counter)");
            $counter++;
        }
    }
}

{
    # L<S29/Num/"=item unpolar">
    #
    # Basic tests for unpolar()
    my $s = 2 * sqrt(2);

    is_approx(4.unpolar(0),         4,     "4.unpolar(0)    == 4");
    is_approx(4.unpolar($pi/4),     $s + ($s)i ,"4.unpolar(pi/4) == 2+2i");
    is_approx(4.unpolar($pi/2),     4i,    "4.unpolar(pi/2) == 4i");
    is_approx(4.unpolar(3*$pi/4),   -$s + ($s)i,"4.unpolar(pi/4) == -2+2i");
    is_approx(4.unpolar($pi),       -4,    "4.unpolar(pi)   == -4");
}
{'fraction_non_alphanumeric': 0.21328029375764995, 'fraction_numerical': 0.06303549571603427, 'mean_word_length': 2.098578199052133, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4373862', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1364, 'n_words': 287}