def test_simple_operations(self): result = union(_multiset1, _multiset2) self.assertEqual(result, Multiset(_collections.Counter("badog"))) result = add(_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_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_minus(self): self._check_wrong_argument_types_binary(minus) result = minus(_set1, _set2) self.assertEqual(result, _set1m2)
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}) if ms_6 == simple_minus: print("multiset's minus subtracts all the rhs multiples from the lhs.\n") # Moving on to multiclan examples now # Setting up multiclan relations rel_1 = _mo.Set(_mo.Couplet('x', 'y'), _mo.Couplet('w', 'y')) rel_2 = _mo.Set(_mo.Couplet('a', 'x'), _mo.Couplet('b', 'w')) rel_3 = _mo.Set(_mo.Couplet('x', 'z'), _mo.Couplet('v', 'y')) rel_4 = _mo.Set(_mo.Couplet('c', 'z'), _mo.Couplet('a', 'v'))
"result multiset.\n") # Multiset Addition operation Example simple_addition = _multisets.add(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}) if ms_6 == simple_minus: print("multiset's minus subtracts all the rhs multiples from the lhs.\n") # Moving on to multiclan examples now # Setting up multiclan relations rel_1 = _mo.Set(_mo.Couplet('x', 'y'), _mo.Couplet('w', 'y')) rel_2 = _mo.Set(_mo.Couplet('a', 'x'), _mo.Couplet('b', 'w')) rel_3 = _mo.Set(_mo.Couplet('x', 'z'), _mo.Couplet('v', 'y')) rel_4 = _mo.Set(_mo.Couplet('c', 'z'), _mo.Couplet('a', 'v'))