### ----------------------------------------------------
### -- Math::NumberTheory
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/08-digit-count.rakutest
### ----------------------------------------------------
use Test;

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

plan *;

## 1
is-deeply digit-count(123), %(1 => 1, 2 => 1, 3 => 1);

## 2
is digit-count(1233, d => 3), 2;

## 3
is-deeply digit-count(1233, d => [1, 3]), %(1 => 1, 3 => 2);

## 4
is-deeply
        (1 .. 30).map({ $_ - integer-exponent(factorial($_), 2) }),
        (1 .. 30).map({ digit-count($_, 2, 1) }),
        'formula for digit count';

## 5
subtest {

    is fibonacci(178), 7084593923980518516849609894969925639, 'simple call';

    ## Mathematica / WL
    # KeySort@AssociationThread[Append[Range[9], 0], DigitCount[Fibonacci[10431]]]
    # <|0 -> 209, 1 -> 211, 2 -> 218, 3 -> 208, 4 -> 212, 5 -> 218, 6 -> 236, 7 -> 204, 8 -> 241, 9 -> 223|>
    is-deeply
            digit-count(fibonacci(10431)),
            { "0" => 209, "1" => 211, "2" => 218, "3" => 208, "4" => 212,
              "5" => 218, "6" => 236, "7" => 204, "8" => 241, "9" => 223 },
            'expected digits';
            ;
}, 'fibonacci number digitt';

done-testing


