Permalink
Browse files

Bag union and bag intersection are infective, so move those tests.

  • Loading branch information...
1 parent 0bf94c0 commit 068fb14b63ef6e03ef21d1102b6a26a801ec7c88 @colomon colomon committed Feb 21, 2012
Showing with 40 additions and 30 deletions.
  1. +39 −1 S03-operators/bag.t
  2. +1 −29 S03-operators/set.t
View
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 48;
+plan 76;
sub showkv($x) {
$x.keys.sort.map({ $^k ~ ':' ~ $x{$^k} }).join(' ')
@@ -18,6 +18,44 @@ my $ks = KeySet.new(<blood rhetoric>);
my $b = bag { blood => 2, rhetoric => 1, love => 2 };
my $kb = KeyBag.new({ blood => 1, love => 2 });
+# Bag Union
+
+is showkv($b $b), showkv($b), "Bag union with itself yields self";
+isa_ok ($b $b), Bag, "... and it's actually a Bag";
+is showkv($kb $kb), showkv($kb), "KeyBag union with itself yields (as Bag)";
+isa_ok ($kb $kb), Bag, "... and it's actually a Bag";
+
+is showkv($s $b), "blood:2 love:2 rhetoric:1", "Set union with Bag works";
+isa_ok ($s $b), Bag, "... and it's actually a Bag";
+is showkv($s $kb), "blood:1 love:2", "Set union with KeyBag works";
+isa_ok ($s $kb), Bag, "... and it's actually a Bag";
+
+is showkv($s (|) $b), "blood:2 love:2 rhetoric:1", "Set union with Bag works (texas)";
+isa_ok ($s (|) $b), Bag, "... and it's actually a Bag";
+is showkv($s (|) $kb), "blood:1 love:2", "Set union with KeyBag works (texas)";
+isa_ok ($s (|) $kb), Bag, "... and it's actually a Bag";
+
+# Bag Intersection
+
+is showkv($b $b), showkv($b), "Bag intersection with itself yields self (as Bag)";
+isa_ok ($b $b), Bag, "... and it's actually a Bag";
+is showkv($kb $kb), showkv($kb), "KeyBag intersection with itself yields self (as Bag)";
+isa_ok ($kb $kb), Bag, "... and it's actually a Bag";
+
+is showkv($s $b), "blood:1 love:1", "Set intersection with Bag works";
+isa_ok ($s $b), Bag, "... and it's actually a Bag";
+is showkv($s $kb), "blood:1 love:1", "Set intersection with KeyBag works";
+isa_ok ($s $kb), Bag, "... and it's actually a Bag";
+is showkv($kb <glad green blood>), "blood:1", "KeyBag intersection with array of strings works";
+isa_ok ($kb <glad green blood>), Bag, "... and it's actually a Bag";
+
+is showkv($s (&) $b), "blood:1 love:1", "Set intersection with Bag works (texas)";
+isa_ok ($s (&) $b), Bag, "... and it's actually a Bag";
+is showkv($s (&) $kb), "blood:1 love:1", "Set intersection with KeyBag works (texas)";
+isa_ok ($s (&) $kb), Bag, "... and it's actually a Bag";
+is showkv($kb (&) <glad green blood>), "blood:1", "KeyBag intersection with array of strings works (texas)";
+isa_ok ($kb (&) <glad green blood>), Bag, "... and it's actually a Bag";
+
# Bag multiplication
is showkv($s $s), "blood:1 love:1", "Bag multiplication with itself yields self squared";
View
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 308;
+plan 280;
sub showset($s) { $s.keys.sort.join(' ') }
@@ -72,26 +72,14 @@ is showset($s ∪ $s), showset($s), "Set union with itself yields self";
isa_ok ($s $s), Set, "... and it's actually a Set";
is showset($ks $ks), showset($ks), "KeySet union with itself yields self (as Set)";
isa_ok ($ks $ks), Set, "... and it's actually a Set";
-is showset($b $b), showset($b), "Bag union with itself yields self (as Set)";
-isa_ok ($b $b), Set, "... and it's actually a Set";
-is showset($kb $kb), showset($kb), "KeyBag union with itself yields (as Set)";
-isa_ok ($kb $kb), Set, "... and it's actually a Set";
is showset($s $ks), showset(set <I'm afraid it is isn't your day>), "Set union with KeySet works";
isa_ok ($s $ks), Set, "... and it's actually a Set";
-is showset($s $b), showset(set($s, $b)), "Set union with Bag works";
-isa_ok ($s $b), Set, "... and it's actually a Set";
-is showset($s $kb), showset(set($s, $kb)), "Set union with KeyBag works";
-isa_ok ($s $kb), Set, "... and it's actually a Set";
is showset($ks <blue green>), showset(set <I'm afraid it is blue green>), "KeySet union with array of strings works";
isa_ok ($ks <blue green>), Set, "... and it's actually a Set";
is showset($s (|) $ks), showset(set <I'm afraid it is isn't your day>), "Set union with KeySet works (texas)";
isa_ok ($s (|) $ks), Set, "... and it's actually a Set (texas)";
-is showset($s (|) $b), showset(set($s, $b)), "Set union with Bag works (texas)";
-isa_ok ($s (|) $b), Set, "... and it's actually a Set (texas)";
-is showset($s (|) $kb), showset(set($s, $kb)), "Set union with KeyBag works (texas)";
-isa_ok ($s (|) $kb), Set, "... and it's actually a Set (texas)";
is showset($ks (|) <blue green>), showset(set <I'm afraid it is blue green>), "KeySet union with array of strings works (texas)";
isa_ok ($ks (|) <blue green>), Set, "... and it's actually a Set (texas)";
@@ -101,28 +89,12 @@ is showset($s ∩ $s), showset($s), "Set intersection with itself yields self";
isa_ok ($s $s), Set, "... and it's actually a Set";
is showset($ks $ks), showset($ks), "KeySet intersection with itself yields self (as Set)";
isa_ok ($ks $ks), Set, "... and it's actually a Set";
-is showset($b $b), showset($b), "Bag intersection with itself yields self (as Set)";
-isa_ok ($b $b), Set, "... and it's actually a Set";
-is showset($kb $kb), showset($kb), "KeyBag intersection with itself yields self (as Set)";
-isa_ok ($kb $kb), Set, "... and it's actually a Set";
is showset($s $ks), showset(set <I'm afraid it>), "Set intersection with KeySet works";
isa_ok ($s $ks), Set, "... and it's actually a Set";
-is showset($s $b), showset(∅), "Set intersection with Bag works";
-isa_ok ($s $b), Set, "... and it's actually a Set";
-is showset($s $kb), showset(set <your>), "Set intersection with KeyBag works";
-isa_ok ($s $kb), Set, "... and it's actually a Set";
-is showset($kb <glad green bread>), showset(set <glad bread>), "KeyBag intersection with array of strings works";
-isa_ok ($kb <glad green bread>), Set, "... and it's actually a Set";
is showset($s (&) $ks), showset(set <I'm afraid it>), "Set intersection with KeySet works (texas)";
isa_ok ($s (&) $ks), Set, "... and it's actually a Set (texas)";
-is showset($s (&) $b), showset(∅), "Set intersection with Bag works (texas)";
-isa_ok ($s (&) $b), Set, "... and it's actually a Set (texas)";
-is showset($s (&) $kb), showset(set <your>), "Set intersection with KeyBag works (texas)";
-isa_ok ($s (&) $kb), Set, "... and it's actually a Set (texas)";
-is showset($kb (&) <glad green bread>), showset(set <glad bread>), "KeyBag intersection with array of strings works (texas)";
-isa_ok ($kb (&) <glad green bread>), Set, "... and it's actually a Set (texas)";
# set subtraction

0 comments on commit 068fb14

Please sign in to comment.