### ----------------------------------------------------
### -- Math::NumberTheory
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/05-primitive-root.rakutest
### ----------------------------------------------------
use v6.d;
use Test;

#use lib <. lib>;
use Math::NumberTheory;

plan *;

## 1
subtest {
    is primitive-root(9), 2;
    is-deeply (1 .. 10).map({ power-mod(2, $_, 9) }).unique.sort.List, (1, 2, 4, 5, 7, 8);
    is primitive-root(10) ∈ [3, 7], True;
    is-deeply primitive-root([9, 23]), (2, 5);
}, 'primitive-root';

## 2
subtest {
    is primitive-root-list(9), [2, 5];
    is-deeply primitive-root-list([9, 23]), ([2, 5], [5, 7, 10, 11, 14, 15, 17, 19, 20, 21]);
}, 'primitive-root-list';

## 3
subtest {
    is multiplicative-order(5 ,7), 6, 'standard 1';
    is multiplicative-order(20, 257), 256, 'standard 2';
    is multiplicative-order(10 ** 10000, 7919), 3959, 'standard large';
    is multiplicative-order(-5 ,7), 3, 'negative first argument';
    is multiplicative-order(-5 ,7, [3, 11]), 2, 'generalized 1';
    is multiplicative-order(15, 37, [31, 7, 11]), 8, 'generalized 2';
}, 'multiplicative-order';

done-testing;


