### ----------------------------------------------------
### -- Hash::Sorted
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/01-basic.rakutest
### ----------------------------------------------------
use Test;
use Hash::Sorted;

plan 21;

my %m is Hash::Sorted = b => 42, a => 666;  # [str,Any]
is %m.elems, 2, 'Did we get right number of elems';
is %m.end, 1, 'Did we get right index for last';
is-deeply %m.keys, (my str @ = "a","b"),
  'are keys sorted';
is-deeply %m.values, Array[Any].new(666,42),
  'are values sorted according to keys';
is-deeply %m.head, Pair.new("a",666),
  'is the first "a"';
is-deeply %m.tail, Pair.new("b",42),
  'is the last "b"';

my %n is Hash::Sorted[int,str] = 666 => "a", 42 => "b";
is-deeply %n.elems, 2, 'Did we get right number of elems';
is-deeply +%n, 2, 'Did we get right number of elems implicitly';
is-deeply %n.Int, 2, 'Did we get right number of elems explicitly';
is-deeply ?%n, True, 'Did we get bool ok';
is-deeply %n.end, 1, 'Did we get right index for last';
is-deeply %n.keys, (my int @ = 42,666),
  'are keys sorted';
is-deeply %n.values, (my str @ = "b","a"),
  'are values sorted according to keys';
is-deeply %n.head, Pair.new(42,"b"),
  'is the first 42';
is-deeply %n.tail, Pair.new(666,"a"),
  'is the last 666';

is-deeply Hash::Sorted.raku, 'Hash::Sorted', 'does .raku work on type object';
quietly is-deeply Hash::Sorted.Str, '',       'does .Str  work on type object';
is-deeply Hash::Sorted.gist, '(Sorted)',     'does .gist work on type object';

class A does Hash::Sorted { }

is-deeply A.raku,       'A', 'does .raku work on class type object';
quietly is-deeply A.Str, '', 'does .Str  work on class type object';
is-deeply A.gist,     '(A)', 'does .gist work on class type object';

# vim: expandtab shiftwidth=4


