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_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)')
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()))
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)')
def test_Union(self): """Basic properties and subset relationships of the union.""" self._basic_assert(basic_unions, Union) self._equality_helper(basic_unions) # Equality relationships. self.assertEqual(basic_unions['M'], basic_unions['M-2']) self.assertEqual(basic_unions['M-4 U(AxM)'], basic_unions['M-4 U(AxM)-2']) # Subset relationships. self._subset_assert(basic_unions['A'], basic_unions['M']) self._subset_assert(basic_unions['A'], basic_unions['M-2']) self._subset_assert(basic_unions['A'], basic_unions['AU(AxA)']) self._subset_assert(basic_unions['A'], basic_unions['M-3 U(AxA)']) self._subset_assert(basic_unions['A'], basic_unions['M-4 U(AxM)']) self._subset_assert(basic_unions['A'], basic_unions['M-4 U(AxM)-2']) self._subset_assert(basic_unions['M'], basic_unions['M-2']) self._subset_deny(basic_unions['M'], basic_unions['AU(AxA)']) self._subset_assert(basic_unions['M'], basic_unions['M-3 U(AxA)']) self._subset_assert(basic_unions['M'], basic_unions['M-4 U(AxM)']) self._subset_assert(basic_unions['M'], basic_unions['M-4 U(AxM)-2']) self._subset_deny(basic_unions['M-2'], basic_unions['AU(AxA)']) self._subset_assert(basic_unions['M-2'], basic_unions['M-3 U(AxA)']) self._subset_assert(basic_unions['M-2'], basic_unions['M-4 U(AxM)']) self._subset_assert(basic_unions['M-2'], basic_unions['M-4 U(AxM)-2']) self._subset_assert(basic_unions['AU(AxA)'], basic_unions['M-3 U(AxA)']) self._subset_assert(basic_unions['AU(AxA)'], basic_unions['M-4 U(AxM)']) self._subset_assert(basic_unions['AU(AxA)'], basic_unions['M-4 U(AxM)-2']) self._subset_assert(basic_unions['M-3 U(AxA)'], basic_unions['M-4 U(AxM)']) self._subset_assert(basic_unions['M-3 U(AxA)'], basic_unions['M-4 U(AxM)-2']) self._subset_assert(basic_unions['M-4 U(AxM)'], basic_unions['M-4 U(AxM)-2']) # Special case for structure Union's conditional return in is_subset() for GenesisSetM self.assertTrue(Union([GenesisSetM()]).is_subset(GenesisSetM())) # String representation self.assertEqual('M', Union([GenesisSetM()]).__str__()) self.assertEqual('(M U N)', Union([GenesisSetM(), GenesisSetN()]).__str__()) self.assertEqual('Union([GenesisSetM()])', Union([GenesisSetM()]).__repr__()) self.assertEqual('Union([GenesisSetM(), GenesisSetN()])', Union([GenesisSetM(), GenesisSetN()]).__repr__())
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)')
} _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() } _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')
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)')