def test_metadata(self):
     self.assertEqual(
         get_ground_set(),
         PowerSet(CartesianProduct(GenesisSetM(), GenesisSetM())))
     self.assertEqual(
         get_absolute_ground_set(),
         PowerSet(CartesianProduct(GenesisSetA(), GenesisSetA())))
     self.assertEqual(get_name(), 'Relations(M): P(M x M)')
예제 #2
0
 def test_GenSetA(self):
     """Basic properties of genesis set A."""
     self._basic_assert(setas, GenesisSetA)
     self._equality_helper(setas)
     # Equality relationships.
     self._inequality_assert(GenesisSetA(), GenesisSetM())
     # Subset relationships.
     self._subset_assert(GenesisSetA(), GenesisSetM())
     # Test hashing.
     self.assertNotEqual(hash(GenesisSetA()), hash(GenesisSetM()))
예제 #3
0
 def test_GenSetN(self):
     """Basic properties of genesis set M."""
     self._basic_assert(setns, GenesisSetN)
     self._equality_helper(setns)
     # Equality relationships.
     self._inequality_assert(GenesisSetN(), GenesisSetA())
     # Subset relationships.
     self.assertFalse(GenesisSetN().is_subset(GenesisSetA()))
     self.assertFalse(GenesisSetN() <= GenesisSetA())
     # Test hashing.
     self.assertNotEqual(hash(GenesisSetN()), hash(GenesisSetA()))
 def test_metadata(self):
     self.assertEqual(
         get_ground_set(),
         PowerSet(
             CartesianProduct(
                 PowerSet(CartesianProduct(GenesisSetM(), GenesisSetM())),
                 GenesisSetN())))
     self.assertEqual(
         get_absolute_ground_set(),
         PowerSet(
             CartesianProduct(
                 PowerSet(CartesianProduct(GenesisSetA(), GenesisSetA())),
                 GenesisSetN())))
     self.assertEqual(get_name(), 'Multiclans(M): P(P(M x M) x N)')
예제 #5
0
 def _atom_assert(self, test_key):
     """Assert that 'test_atom' is a proper Atom (with test additions) with the value 'value'."""
     atom = ba[test_key]
     value = atom._test_val
     value_val = value
     while type(value_val) == Atom:
         value_val = value_val.value
     msg = atom._test_msg
     # Test the type structure.
     self.assertTrue(isinstance(atom, MathObject))
     self.assertTrue(isinstance(atom, Atom))
     self.assertFalse(isinstance(atom, Couplet))
     self.assertFalse(isinstance(atom, Set))
     # Compare the value and make sure it is not a MathObject.
     atom_value = atom.value
     self.assertFalse(isinstance(atom_value, MathObject))
     self.assertEqual(atom_value, value_val)
     # Make sure that the representations and string conversion of the atom and the value match.
     self.assertEqual(repr(atom),
                      'Atom({value})'.format(value=repr(value_val)))
     self.assertEqual(str(atom), repr(value_val))
     # Make sure that the representation evaluates to an atom that compares equal.
     repr_exec = 'self.assertEqual(atom, {0})'.format(repr(atom))
     exec(repr_exec)
     # Check the ground set.
     self.assertEqual(atom.get_ground_set(), GenesisSetA())
     # Test left set and functionality.
     self.assertIs(atom.get_left_set(), Undef())
     self.assertIs(is_functional(atom), Undef())
     self.assertIs(atom('callable'), Undef())
     # Print the representation and the string conversion.
     if self.print_examples:
         print('repr(Atom({msg})) = {repr}'.format(msg=msg,
                                                   repr=repr(atom)))
         print('str(Atom({msg})) = {str}'.format(msg=msg, str=str(atom)))
예제 #6
0
    is_reflexive, is_symmetric, is_transitive, is_equivalence_relation, is_regular
import algebraixlib.algebras.relations as relations
import algebraixlib.algebras.sets as sets
from algebraixlib.mathobjects import Atom, Couplet, MathObject, Set
from algebraixlib.mathobjects.utils import CacheStatus
from algebraixlib.structure import CartesianProduct, GenesisSetA, PowerSet, Structure
from algebraixlib.undef import Undef

# noinspection PyProtectedMember
from algebraixlib.io.csv import _convert_clan_to_list_of_dicts, export_csv
# noinspection PyUnresolvedReferences
from data_mathobjects import basic_sets, basic_clans, algebra_clans, basic_hordes


# Ground set structures for the basic_sets.
_atom_set_struct = PowerSet(GenesisSetA())
_relation_struct = PowerSet(CartesianProduct(GenesisSetA(), GenesisSetA()))
_basic_sets_structs = {
    'empty': Structure(),
    'contains empty': PowerSet(Structure()),
    'num in dict': _atom_set_struct,
    'str in array': _atom_set_struct,
    'single num': _atom_set_struct,
    'single Coupl': _relation_struct,
    'left func': _relation_struct,
    'left func/lefts': _atom_set_struct,
    'left func/rights': _atom_set_struct,
    'not left func': _relation_struct,
    'not right func': _relation_struct,
    'diagonal': _relation_struct,
}
예제 #7
0
 def test_metadata(self):
     self.assertEqual(get_ground_set(), PowerSet(GenesisSetM()))
     self.assertEqual(get_absolute_ground_set(), PowerSet(GenesisSetA()))
     self.assertEqual(get_name(), 'Sets(M): P(M)')
예제 #8
0
            print('  "{key}": {val}'.format(key=key, val=val))


#: Two 'instances' of Structure. (They should be the same.)
empties = {
    key: create_test_object(Structure(), key, val)
    for key, val in {
        '{}': None,
        '{}-2': None
    }.items()
}
_print_object_collection('empties')

#: Two 'instances' of GenesisSetA. (They should be the same.)
setas = {
    key: create_test_object(GenesisSetA(), key, val)
    for key, val in {
        'A': None,
        'A-2': None
    }.items()
}
_print_object_collection('setas')

#: Two 'instances' of GenesisSetM. (They should be the same.)
setms = {
    key: create_test_object(GenesisSetM(), key, val)
    for key, val in {
        'M': None,
        'M-2': None
    }.items()
}
# --------------------------------------------------------------------------------------------------
import inspect
import os
import unittest

from algebraixlib.algebras.properties import is_functional, is_right_functional, is_bijective, \
    is_reflexive, is_transitive, is_equivalence_relation
from algebraixlib.mathobjects import Atom, CacheStatus, Couplet, MathObject, Set
from algebraixlib.structure import CartesianProduct, GenesisSetA, PowerSet
from algebraixlib.undef import Undef

# noinspection PyUnresolvedReferences
from data_mathobjects import basic_couplets

# Ground set structures for the basic_couplets.
_basic_couplet_struct = CartesianProduct(GenesisSetA(), GenesisSetA())
_complex_couplet_struct = CartesianProduct(_basic_couplet_struct,
                                           PowerSet(GenesisSetA()))
_basic_couplets_structs = {
    '3x2': _basic_couplet_struct,
    "'5'x'4'": _basic_couplet_struct,
    "'7'x6": _basic_couplet_struct,
    'Coupl x Set': _complex_couplet_struct
}


class CoupletTest(unittest.TestCase):
    """Test the Couplet class."""

    print_examples = False
#
# 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 inspect
import os
import unittest

import collections as _collections

from algebraixlib.mathobjects import Atom, CacheStatus, Couplet, Multiset, Set
from algebraixlib.structure import CartesianProduct, GenesisSetN, GenesisSetA, PowerSet, Structure
from algebraixlib.undef import Undef

# Ground set structures for the basic_sets.
_atom_multiset_struct = PowerSet(CartesianProduct(GenesisSetA(),
                                                  GenesisSetN()))


class MultisetTest(unittest.TestCase):
    """Test the Set class."""

    print_examples = False

    #     def test_Multiset(self):
    #         """Create various forms of Sets."""
    #         if self.print_examples:
    #             print('(printing examples)')  # Make 'nosetests -s' more readable.
    #         for test_set_name in basic_multisets.keys():
    #             self._multiset_assert(test_set_name)
    #         self.assertEqual("{}", str(Multiset()))
예제 #11
0
 def test_complex_structures(self):
     """Test more complex structures and their subset relationships."""
     # DA-36
     # P((A x P(A x P((A x P(A x A)) U (A x P(A x P(A))) U (A x A)))) U (A x A))
     s1 = PowerSet(
         Union([
             CartesianProduct(
                 GenesisSetA(),
                 PowerSet(
                     CartesianProduct(
                         GenesisSetA(),
                         PowerSet(
                             Union([
                                 CartesianProduct(
                                     GenesisSetA(),
                                     PowerSet(
                                         CartesianProduct(
                                             GenesisSetA(),
                                             GenesisSetA()))),
                                 CartesianProduct(
                                     GenesisSetA(),
                                     PowerSet(
                                         CartesianProduct(
                                             GenesisSetA(),
                                             PowerSet(GenesisSetA())))),
                                 CartesianProduct(GenesisSetA(),
                                                  GenesisSetA())
                             ]))))),
             CartesianProduct(GenesisSetA(), GenesisSetA())
         ]))
     s2 = PowerSet(CartesianProduct(GenesisSetM(), GenesisSetM()))
     self.assertTrue(s1.is_subset(s2))
예제 #12
0
 def test_get_powerset_level(self):
     """Test the get_powerset_level function."""
     for zero_levels in [empties, setas, setms, setns]:
         for zero_level in zero_levels.values():
             for pset in basic_pss.values():
                 self.assertEqual(zero_level.get_powerset_level(pset), 0)
     for cp in basic_cps.values():
         for pset in basic_pss.values():
             self.assertEqual(cp.get_powerset_level(pset), 0)
     for un in basic_unions.values():
         for pset in basic_pss.values():
             self.assertEqual(un.get_powerset_level(pset), 0)
     self.assertEqual(basic_pss['A'].get_powerset_level(basic_pss['AxA']),
                      0)
     self.assertEqual(basic_pss['AxA'].get_powerset_level(basic_pss['A']),
                      0)
     self.assertEqual(basic_pss['AxA'].get_powerset_level(basic_pss['M']),
                      0)
     # One level:
     self.assertEqual(basic_pss['A'].get_powerset_level(GenesisSetA()), 1)
     self.assertEqual(basic_pss['A'].get_powerset_level(GenesisSetM()), 1)
     self.assertEqual(basic_pss['AxA'].get_powerset_level(basic_cps['AxA']),
                      1)
     self.assertEqual(basic_pss['AxA'].get_powerset_level(basic_cps['AxM']),
                      1)
     self.assertEqual(basic_pss['AxA'].get_powerset_level(basic_cps['MxM']),
                      1)
     self.assertEqual(basic_pss['MxM'].get_powerset_level(basic_cps['AxA']),
                      0)
     self.assertEqual(basic_pss['MxM'].get_powerset_level(basic_cps['AxM']),
                      0)
     self.assertEqual(basic_pss['MxM'].get_powerset_level(basic_cps['MxM']),
                      1)
     self.assertEqual(
         basic_pss['P(AxA)'].get_powerset_level(basic_pss['AxA']), 1)
     self.assertEqual(
         basic_pss['P(AxA)'].get_powerset_level(basic_pss['MxM']), 1)
     self.assertEqual(
         basic_pss['P(MxM)'].get_powerset_level(basic_pss['AxA']), 0)
     self.assertEqual(
         basic_pss['P(MxM)'].get_powerset_level(basic_pss['MxM']), 1)
     self.assertEqual(
         basic_pss['PP(AxA)'].get_powerset_level(basic_pss['P(AxA)']), 1)
     self.assertEqual(
         basic_pss['PP(AxA)'].get_powerset_level(basic_pss['P(MxM)']), 1)
     self.assertEqual(
         basic_pss['PP(MxM)'].get_powerset_level(basic_pss['P(AxA)']), 0)
     self.assertEqual(
         basic_pss['PP(MxM)'].get_powerset_level(basic_pss['P(MxM)']), 1)
     self.assertEqual(
         basic_pss['PPP(AxA)'].get_powerset_level(basic_pss['PP(AxA)']), 1)
     self.assertEqual(
         basic_pss['PPP(AxA)'].get_powerset_level(basic_pss['PP(MxM)']), 1)
     self.assertEqual(
         basic_pss['PPP(MxM)'].get_powerset_level(basic_pss['PP(AxA)']), 0)
     self.assertEqual(
         basic_pss['PPP(MxM)'].get_powerset_level(basic_pss['PP(MxM)']), 1)
     # Two levels:
     self.assertEqual(
         basic_pss['P(AxA)'].get_powerset_level(basic_cps['AxA']), 2)
     self.assertEqual(
         basic_pss['P(AxA)'].get_powerset_level(basic_cps['AxM']), 2)
     self.assertEqual(
         basic_pss['P(AxA)'].get_powerset_level(basic_cps['MxM']), 2)
     self.assertEqual(
         basic_pss['P(MxM)'].get_powerset_level(basic_cps['AxA']), 0)
     self.assertEqual(
         basic_pss['P(MxM)'].get_powerset_level(basic_cps['AxM']), 0)
     self.assertEqual(
         basic_pss['P(MxM)'].get_powerset_level(basic_cps['MxM']), 2)
     self.assertEqual(
         basic_pss['PP(AxA)'].get_powerset_level(basic_pss['AxA']), 2)
     self.assertEqual(
         basic_pss['PP(AxA)'].get_powerset_level(basic_pss['MxM']), 2)
     self.assertEqual(
         basic_pss['PP(MxM)'].get_powerset_level(basic_pss['AxA']), 0)
     self.assertEqual(
         basic_pss['PP(MxM)'].get_powerset_level(basic_pss['MxM']), 2)
     self.assertEqual(
         basic_pss['PPP(AxA)'].get_powerset_level(basic_pss['P(AxA)']), 2)
     self.assertEqual(
         basic_pss['PPP(AxA)'].get_powerset_level(basic_pss['P(MxM)']), 2)
     self.assertEqual(
         basic_pss['PPP(MxM)'].get_powerset_level(basic_pss['P(AxA)']), 0)
     self.assertEqual(
         basic_pss['PPP(MxM)'].get_powerset_level(basic_pss['P(MxM)']), 2)
     # Three levels:
     self.assertEqual(
         basic_pss['PP(AxA)'].get_powerset_level(basic_cps['AxA']), 3)
     self.assertEqual(
         basic_pss['PP(AxA)'].get_powerset_level(basic_cps['AxM']), 3)
     self.assertEqual(
         basic_pss['PP(AxA)'].get_powerset_level(basic_cps['MxM']), 3)
     self.assertEqual(
         basic_pss['PP(MxM)'].get_powerset_level(basic_cps['AxA']), 0)
     self.assertEqual(
         basic_pss['PP(MxM)'].get_powerset_level(basic_cps['AxM']), 0)
     self.assertEqual(
         basic_pss['PP(MxM)'].get_powerset_level(basic_cps['MxM']), 3)
     self.assertEqual(
         basic_pss['PPP(AxA)'].get_powerset_level(basic_pss['AxA']), 3)
     self.assertEqual(
         basic_pss['PPP(AxA)'].get_powerset_level(basic_pss['MxM']), 3)
     self.assertEqual(
         basic_pss['PPP(MxM)'].get_powerset_level(basic_pss['AxA']), 0)
     self.assertEqual(
         basic_pss['PPP(MxM)'].get_powerset_level(basic_pss['MxM']), 3)
     # Four levels:
     self.assertEqual(
         basic_pss['PPP(AxA)'].get_powerset_level(basic_cps['AxA']), 4)
     self.assertEqual(
         basic_pss['PPP(AxA)'].get_powerset_level(basic_cps['AxM']), 4)
     self.assertEqual(
         basic_pss['PPP(AxA)'].get_powerset_level(basic_cps['MxM']), 4)
     self.assertEqual(
         basic_pss['PPP(MxM)'].get_powerset_level(basic_cps['AxA']), 0)
     self.assertEqual(
         basic_pss['PPP(MxM)'].get_powerset_level(basic_cps['AxM']), 0)
     self.assertEqual(
         basic_pss['PPP(MxM)'].get_powerset_level(basic_cps['MxM']), 4)
 def test_metadata(self):
     self.assertEqual(get_ground_set(),
                      CartesianProduct(GenesisSetM(), GenesisSetM()))
     self.assertEqual(get_absolute_ground_set(),
                      CartesianProduct(GenesisSetA(), GenesisSetA()))
     self.assertEqual(get_name(), 'Couplets(M): (M x M)')