<commit_before>#! nqp

pir::load_bytecode('nqp-settings.pbc');

my %hash := hash( foo => 1, bar => 2, baz => 42);

say('1..17');

say(%hash.exists('foo') ?? "ok 1" !! "nok 2");
say(%hash.exists('bang') ?? "nok 2" !! "ok 2");

my @keys := %hash.keys;
say(+@keys == 3 ?? 'ok 3' !! 'nok 3');

my @sorted := <bar baz foo>;
for @keys.sort -> $key {
    my $expected := @sorted.shift;
    say($expected == $key ?? 'ok' !! 'nok');
}

my %expected := hash( foo => 1, bar => 2, baz => 42);
my %values;

for %hash.kv -> $k, $v {
    say(%expected.exists($k) ?? 'ok' !! 'nok');
    say(%expected{$k} == $v  ?? 'ok' !! 'nok');
    %expected.delete($k);
    %values{$v} := 1
}

say(+%expected.keys == 0 ?? 'ok' !! 'nok');

for %hash.values -> $v {
    say(%values.exists($v) ?? 'ok' !! 'nok');
    %values.delete($v);
}

say(+%values.keys == 0 ?? 'ok' !! 'nok');

# vim: ft=perl6<commit_msg>Rewrite 02-hash.t using builtin NQP testing.<commit_after>#! nqp

pir::load_bytecode('nqp-settings.pbc' );

my %hash := hash( foo => 1, bar => 2, baz => 42 );

plan(17 );

ok( %hash.exists('foo'), 'Key exists');
ok( !(%hash.exists('bang')), "Key doesn't exists");

my @keys := %hash.keys;
ok(+@keys == 3, "Got 3 keys total" );

my @sorted := <bar baz foo>;
for @keys.sort -> $key {
    my $expected := @sorted.shift;
    ok( $expected == $key, "Key is correct" );
}

my %expected := hash( foo => 1, bar => 2, baz => 42 );
my %values;

for %hash.kv -> $k, $v {
    ok( %expected.exists($k), "Key exists" );
    ok( %expected{$k} == $v,  "Value correct" );
    %expected.delete($k);
    %values{$v} := 1
}

ok( +%expected.keys == 0, "All keys processed" );

for %hash.values -> $v {
    ok( %values.exists($v), "Value correct" );
    %values.delete($v);
}

ok( +%values.keys == 0, "All values processed" );

# vim: ft=perl6
{'fraction_non_alphanumeric': 0.26459143968871596, 'fraction_numerical': 0.022234574763757644, 'mean_word_length': 3.4554455445544554, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4079738', 'n_tokens_mistral': 781, 'n_tokens_neox': 732, 'n_words': 190}