Skip to content

Commit c49e082

Browse files
committed
Tests for Bag.ACCEPTS and KeyBag.Accepts.
1 parent bbf6549 commit c49e082

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

S02-types/bag.t

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 126;
4+
plan 137;
55

66
sub showkv($x) {
77
$x.keys.sort.map({ $^k ~ ':' ~ $x{$k} }).join(' ')
@@ -44,6 +44,22 @@ sub showkv($x) {
4444
is +$b, 8, '+$bag gives sum of values';
4545
}
4646

47+
#?rakudo skip "Bag.ACCEPTS NYI"
48+
{
49+
ok (bag <a b c>) ~~ (bag <a b c>), "Identical bags smartmatch with each other";
50+
ok (bag <a b c c>) ~~ (bag <a b c c>), "Identical bags smartmatch with each other";
51+
nok (bag <b c>) ~~ (bag <a b c>), "Subset does not smartmatch";
52+
nok (bag <a b c>) ~~ (bag <a b c c>), "Subset (only quantity different) does not smartmatch";
53+
nok (bag <a b c d>) ~~ (bag <a b c>), "Superset does not smartmatch";
54+
nok (bag <a b c c c>) ~~ (bag <a b c c>), "Superset (only quantity different) does not smartmatch";
55+
nok "a" ~~ (bag <a b c>), "Smartmatch is not element of";
56+
ok (bag <a b c>) ~~ Bag, "Type-checking smartmatch works";
57+
58+
ok (set <a b c>) ~~ (bag <a b c>), "Set smartmatches with equivalent bag";
59+
nok (set <a a a b c>) ~~ (bag <a a a b c>), "... but not if the Bag has greater quantities";
60+
nok (set <a b c>) ~~ Bag, "Type-checking smartmatch works";
61+
}
62+
4763
#?rakudo skip ".Set NYI"
4864
{
4965
isa_ok "a".Bag, Bag, "Str.Bag makes a Bag";

S02-types/keybag.t

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 160;
4+
plan 171;
55

66
# L<S02/Mutable types/KeyHash of UInt>
77

@@ -67,6 +67,22 @@ sub showkv($x) {
6767
nok $b.exists("farve"), "... and everything is still okay";
6868
}
6969

70+
#?rakudo skip "KeyBag.ACCEPTS NYI"
71+
{
72+
ok (KeyBag.new: <a b c>) ~~ (KeyBag.new: <a b c>), "Identical bags smartmatch with each other";
73+
ok (KeyBag.new: <a b c c>) ~~ (KeyBag.new: <a b c c>), "Identical bags smartmatch with each other";
74+
nok (KeyBag.new: <b c>) ~~ (KeyBag.new: <a b c>), "Subset does not smartmatch";
75+
nok (KeyBag.new: <a b c>) ~~ (KeyBag.new: <a b c c>), "Subset (only quantity different) does not smartmatch";
76+
nok (KeyBag.new: <a b c d>) ~~ (KeyBag.new: <a b c>), "Superset does not smartmatch";
77+
nok (KeyBag.new: <a b c c c>) ~~ (KeyBag.new: <a b c c>), "Superset (only quantity different) does not smartmatch";
78+
nok "a" ~~ (KeyBag.new: <a b c>), "Smartmatch is not element of";
79+
ok (KeyBag.new: <a b c>) ~~ KeyBag, "Type-checking smartmatch works";
80+
81+
ok (set <a b c>) ~~ (KeyBag.new: <a b c>), "Set smartmatches with equivalent KeyBag.new:";
82+
nok (set <a a a b c>) ~~ (KeyBag.new: <a a a b c>), "... but not if the Bag has greater quantities";
83+
nok (set <a b c>) ~~ KeyBag, "Type-checking smartmatch works";
84+
}
85+
7086
#?rakudo skip ".KeyBag NYI"
7187
{
7288
isa_ok "a".KeyBag, KeyBag, "Str.KeyBag makes a KeyBag";

0 commit comments

Comments
 (0)