コード例 #1
0
    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")))
コード例 #2
0
 def test_union(self):
     self._check_wrong_argument_types_binary(union)
     result = union(_set1, _set2)
     self.assertEqual(result, _set1u2)
     abc_ab_ac = Multiset([Multiset('a', 'b', 'c'), Multiset('a', 'b'), Multiset('a', 'c'),
                           Multiset('a', 'c')])
     ab_c = _ab_c
     ac_a = _ac_a
     cu = extension.binary_multi_extend(ab_c, ac_a, union)
     self.assertEqual(cu, abc_ab_ac)
コード例 #3
0
 def test_union(self):
     self._check_wrong_argument_types_binary(union)
     result = union(_set1, _set2)
     self.assertEqual(result, _set1u2)
     abc_ab_ac = Multiset([
         Multiset('a', 'b', 'c'),
         Multiset('a', 'b'),
         Multiset('a', 'c'),
         Multiset('a', 'c')
     ])
     ab_c = _ab_c
     ac_a = _ac_a
     cu = extension.binary_multi_extend(ab_c, ac_a, union)
     self.assertEqual(cu, abc_ab_ac)
コード例 #4
0
    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")))
コード例 #5
0
ファイル: multi_example.py プロジェクト: jdcasi/algebraixlib
#
# You should have received a copy of the GNU Lesser General Public License along with algebraixlib.
# If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------------------------------------
import algebraixlib.algebras.multiclans as _multiclans
import algebraixlib.algebras.multisets as _multisets
import algebraixlib.mathobjects as _mo
from algebraixlib.util.latexprinter import math_object_to_latex as _math_object_to_latex

# --------------------------------------------------------------------------------------------------

ms_1 = _mo.Multiset({'a': 3, 'b': 3})
ms_2 = _mo.Multiset({'b': 2, 'c': 1})

# Multiset Union operation Example
simple_union = _multisets.union(ms_1, ms_2)

print(str(ms_1) + ' UNION ' + str(ms_2))
print('=> EVALUATES TO ' + str(simple_union))

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})
コード例 #6
0
#
# You should have received a copy of the GNU Lesser General Public License along with algebraixlib.
# If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------------------------------------
import algebraixlib.algebras.multiclans as _multiclans
import algebraixlib.algebras.multisets as _multisets
import algebraixlib.mathobjects as _mo
from algebraixlib.util.latexprinter import math_object_to_latex as _math_object_to_latex

# --------------------------------------------------------------------------------------------------

ms_1 = _mo.Multiset({'a': 3, 'b': 3})
ms_2 = _mo.Multiset({'b': 2, 'c': 1})

# Multiset Union operation Example
simple_union = _multisets.union(ms_1, ms_2)

print(str(ms_1) + ' UNION ' + str(ms_2))
print('=> EVALUATES TO ' + str(simple_union))

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))