def test_metadata(self): self.assertEqual( get_ground_set(), PowerSet(CartesianProduct(GenesisSetM(), GenesisSetN()))) self.assertEqual( get_absolute_ground_set(), PowerSet(CartesianProduct(GenesisSetA(), GenesisSetN()))) self.assertEqual(get_name(), 'Multisets(M): P(M x N)')
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))
def test_multiset_with_one_empty_element(self): m = Multiset(Set()) self.assertEqual(m.cardinality, 1) m_repr = repr(m) m_str = str(m) self.assertEqual(m_repr, "Multiset({Set(): 1})") self.assertEqual(m_str, "[{}:1]") self.assertEqual(m.get_multiplicity(Set()), 1) self.assertEqual(m.get_multiplicity(Atom('b')), 0) m_struct = m.get_ground_set() m_expected_struct = PowerSet( CartesianProduct(Structure(), GenesisSetN())) self.assertEqual(m_struct, m_expected_struct) import algebraixlib.algebras.multiclans as _multiclans self.assertTrue(_multiclans.is_member(m)) self.assertTrue(_multiclans.is_absolute_member(m))
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, }
}.items() } _print_object_collection('setms') setns = { key: create_test_object(GenesisSetN(), key, val) for key, val in { 'N': None, 'N-2': None }.items() } _print_object_collection('setns') #: Basic CartesianProduct instances. basic_cps = { key: create_test_object(CartesianProduct(**val), key, val) for key, val in { 'AxA': { 'left': GenesisSetA(), 'right': GenesisSetA() }, 'AxM': { 'left': GenesisSetA(), 'right': GenesisSetM() }, 'MxM': { 'left': GenesisSetM(), 'right': GenesisSetM() }, 'Ax(AxA)': { 'left': GenesisSetA(),
# -------------------------------------------------------------------------------------------------- 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())) # self.assertTrue(Multiset(1) < Multiset(2))
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)')