### ----------------------------------------------------
### -- Base::Any
### -- Licenses: Artistic-2.0
### -- Authors: Steve Schulze (thundergnat)
### -- File: t/01-basic.t
### ----------------------------------------------------
use v6.c;
use Test;
use Base::Any;

plan 34;


is 'R_a_k_u'.&from-base(62), 'Raku'.&from-base(62), 'Underscores in numeric strings ok';

dies-ok { 222.&from-base(22) }, 'from-base needs a string';
dies-ok { '222'.&to-base(22) }, 'to-base needs a numeric';

is-deeply 0.&to-base-hash(15), { :whole([0]), :fraction([0]), :base(15) }, 'sensible hash return type for 0 - fast path';
is-deeply 0.&to-base-hash(45), { :whole([0]), :fraction([0]), :base(45) }, 'sensible hash return type for 0 - slow path';
is-deeply 0.&to-base-hash(-45), { :whole([0]), :fraction([0]), :base(-45) }, 'sensible hash return type for 0 - negative';

is-deeply 0.&to-base-array(15), ([0], [0], 15), 'sensible array return type for 0 - fast path';
is-deeply 0.&to-base-array(45), ([0], [0], 45), 'sensible array return type for 0 - slow path';
is-deeply 0.&to-base-array(-45), ([0], [0], -45), 'sensible array return type for 0 - negative';

is 'raku'.&from-base(-36), 'RAKU'.&from-base(-36), 'Ignores case in negative -36 <-> -2';

dies-ok { '12374'.&from-base(-7) }, 'dies ok with out-of-range, negative base';
dies-ok { '123Ɛ4'.&from-base(-7) }, 'dies ok with out-of-range, negative base';
dies-ok { '12374'.&from-base(7) }, 'dies ok with out-of-range, "small" positive base';
dies-ok { '123Ɛ4'.&from-base(7) }, 'dies ok with out-of-range, "small" positive base';
dies-ok { '123z4'.&from-base(57) }, 'dies ok with out-of-range, "large" positive base';
dies-ok { '123Ɛ4'.&from-base(57) }, 'dies ok with out-of-range, "large" positive base';

lives-ok { 1234.&to-base(4516) }, 'ok with threshold positive radix';
lives-ok { 1234.&to-base(-4516) }, 'ok with threshold negative radix';

lives-ok { '123Ɛ4'.&from-base(4516) }, 'ok with threshold positive radix';
lives-ok { '123Ɛ4'.&from-base(-4516) }, 'ok with threshold negative radix';

dies-ok { 1234.&to-base(4517) }, 'dies ok with out-of-range positive radix';
dies-ok { 1234.&to-base(-4517) }, 'dies ok with out-of-range negative radix';

dies-ok { '123Ɛ4'.&from-base(4517) }, 'dies ok with out-of-range positive radix';
dies-ok { '123Ɛ4'.&from-base(-4517) }, 'dies ok with out-of-range negative radix';

dies-ok { '1.23.4'.&from-base(-7) }, 'dies ok invalid, too many radicimal points';
dies-ok { '1.23.4'.&from-base(7) }, 'dies ok invalid, too many radicimal points';
dies-ok { '1.23.4'.&from-base(47) }, 'dies ok invalid, too many radicimal points';
dies-ok { '1.23.4'.&from-base(-47) }, 'dies ok invalid, too many radicimal points';

dies-ok { Inf.&to-base(12) }, 'dies ok with Inf, "small" positive base';
dies-ok { Inf.&to-base(92) }, 'dies ok with Inf, "large" positive base';
dies-ok { Inf.&to-base(-52) }, 'dies ok with Inf, negative base';

dies-ok { NaN.&to-base(12) }, 'dies ok with NaN, "small" positive base';
dies-ok { NaN.&to-base(92) }, 'dies ok with NaN, "large" positive base';
dies-ok { NaN.&to-base(-52) }, 'dies ok with NaN, negative base';

done-testing;


