def test_simple_operations(self): result = union(_multiset1, _multiset2) self.assertEqual(result, Multiset(_collections.Counter("badog"))) result = addition(_multiset1, _multiset2) self.assertEqual(result, _multiset3) result = intersect(_multiset1, _multiset2) self.assertEqual(result, Multiset(_collections.Counter("d"))) result = minus(_multiset_magic, _multiset1) self.assertEqual(result, Multiset(_collections.Counter("racaabra"))) p1 = Multiset(_collections.Counter("aaa")) p2 = Multiset(_collections.Counter("bbb")) p3 = Multiset(_collections.Counter("ccc")) combined = Set({p1, p2, p3}) result = big_union(combined) self.assertEqual(result, Multiset(_collections.Counter("abc"*3))) result = big_intersect(Set( {_multiset_magic, Multiset(_collections.Counter("abc"*3)), Multiset("a", "a", "b", "c")})) self.assertEqual(result, Multiset(_collections.Counter("aabc")))
def test_addition(self): self._check_wrong_argument_types_binary(addition) result = addition(_set1, _set2) self.assertEqual(result, _set1a2)
ms_3 = _mo.Multiset({'a': 3, 'b': 3, 'c': 1}) if ms_3 == simple_union: print("multiset's union takes the max of all the multiples merges the arguments into one result multiset.\n") # Multiset Intersect Operation Example simple_intersect = _multisets.intersect(ms_1, ms_2) print(str(ms_1) + ' INTERSECT ' + str(ms_2)) print('=> EVALUATES TO ' + str(simple_intersect)) ms_4 = _mo.Multiset({'b': 2}) if ms_4 == simple_intersect: print("multiset's intersect takes the min of all the multiples merges the arguments into one result multiset.\n") # Multiset Addition operation Example simple_addition = _multisets.addition(ms_1, ms_2) print(str(ms_1) + ' ADDITION ' + str(ms_2)) print('=> EVALUATES TO ' + str(simple_addition)) ms_5 = _mo.Multiset({'a': 3, 'b': 5, 'c': 1}) if ms_5 == simple_addition: print("multiset's addition sums all the multiples of like values in the arguments into one result multiset.\n") # Multiset Intersect Operation Example simple_minus = _multisets.minus(ms_1, ms_2) print(str(ms_1) + ' MINUS ' + str(ms_2)) print('=> EVALUATES TO ' + str(simple_minus)) ms_6 = _mo.Multiset({'a': 3, 'b': 1})