示例#1
0
 def test_functional_cache(self):
     """Basic tests of is_functional()."""
     c = ac['clan3']
     self.assertEqual(c.cached_functional, CacheStatus.UNKNOWN)
     self.assertTrue(is_functional(c))
     self.assertTrue(_props.is_functional(c))
     self.assertEqual(c.cached_functional, CacheStatus.IS)
     self.assertTrue(is_functional(c))
     self.assertTrue(_props.is_functional(c))
     c = ac['clan4']
     self.assertEqual(c.cached_functional, CacheStatus.UNKNOWN)
     self.assertFalse(is_functional(c))
     self.assertFalse(_props.is_functional(c))
     self.assertEqual(c.cached_functional, CacheStatus.IS_NOT)
 def test_functional_cache(self):
     """Basic tests of is_functional()."""
     c = ac['clan3']
     self.assertEqual(c.cached_functional, CacheStatus.UNKNOWN)
     self.assertTrue(is_functional(c))
     self.assertTrue(_props.is_functional(c))
     self.assertEqual(c.cached_functional, CacheStatus.IS)
     self.assertTrue(is_functional(c))
     self.assertTrue(_props.is_functional(c))
     c = ac['clan4']
     self.assertEqual(c.cached_functional, CacheStatus.UNKNOWN)
     self.assertFalse(is_functional(c))
     self.assertFalse(_props.is_functional(c))
     self.assertEqual(c.cached_functional, CacheStatus.IS_NOT)
示例#3
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)))
 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)))
 def _test_undef(cc):
     self.assertIs(cc.get_left_set(), Undef())
     self.assertIs(is_functional(cc), Undef())
     self.assertIs(cc.get_right_set(), Undef())
     self.assertIs(is_right_functional(cc), Undef())
     self.assertIs(is_bijective(cc), Undef())
     self.assertIs(is_transitive(cc), Undef())
     self.assertIs(is_equivalence_relation(cc), Undef())
 def _test_undef(cc):
     self.assertIs(cc.get_left_set(), Undef())
     self.assertIs(is_functional(cc), Undef())
     self.assertIs(cc.get_right_set(), Undef())
     self.assertIs(is_right_functional(cc), Undef())
     self.assertIs(is_bijective(cc), Undef())
     self.assertIs(is_transitive(cc), Undef())
     self.assertIs(is_equivalence_relation(cc), Undef())
示例#7
0
 def test_properties(self):
     a = ba['2']
     self.assertIs(a.get_left_set(), Undef())
     self.assertIs(is_functional(a), Undef())
     self.assertIs(a.get_right_set(), Undef())
     self.assertIs(is_right_functional(a), Undef())
     self.assertIs(is_bijective(a), Undef())
     self.assertIs(is_reflexive(a), Undef())
     self.assertIs(is_symmetric(a), Undef())
     self.assertIs(is_transitive(a), Undef())
     self.assertIs(is_equivalence_relation(a), Undef())
 def test_properties(self):
     a = ba['2']
     self.assertIs(a.get_left_set(), Undef())
     self.assertIs(is_functional(a), Undef())
     self.assertIs(a.get_right_set(), Undef())
     self.assertIs(is_right_functional(a), Undef())
     self.assertIs(is_bijective(a), Undef())
     self.assertIs(is_reflexive(a), Undef())
     self.assertIs(is_symmetric(a), Undef())
     self.assertIs(is_transitive(a), Undef())
     self.assertIs(is_equivalence_relation(a), Undef())
示例#9
0
    def test_functional(self):
        self.assertTrue(is_functional(Set()))
        self.assertIs(Undef(), is_functional(Set('a', 'b', 'c')))
        f = is_functional(basic_sets['left func'])
        self.assertTrue(f)
        f = is_functional(basic_sets['not left func'])
        self.assertFalse(f)
        f = is_functional(basic_clans['left func'])
        self.assertTrue(f)
        f = is_functional(basic_clans['not left func'])
        self.assertFalse(f)
        f = is_functional(basic_hordes['left func'])
        self.assertTrue(f)
        f = is_functional(basic_hordes['not left func'])
        self.assertFalse(f)

        s = basic_sets['left func']
        self.assertEqual(s.cached_functional, CacheStatus.IS)
        s = basic_sets['not left func']
        self.assertEqual(s.cached_functional, CacheStatus.IS_NOT)
    def test_functional(self):
        self.assertTrue(is_functional(Set()))
        self.assertIs(Undef(), is_functional(Set("a", "b", "c")))
        f = is_functional(basic_sets["left func"])
        self.assertTrue(f)
        f = is_functional(basic_sets["not left func"])
        self.assertFalse(f)
        f = is_functional(basic_clans["left func"])
        self.assertTrue(f)
        f = is_functional(basic_clans["not left func"])
        self.assertFalse(f)
        f = is_functional(basic_hordes["left func"])
        self.assertTrue(f)
        f = is_functional(basic_hordes["not left func"])
        self.assertFalse(f)

        s = basic_sets["left func"]
        self.assertEqual(s.cached_functional, CacheStatus.IS)
        s = basic_sets["not left func"]
        self.assertEqual(s.cached_functional, CacheStatus.IS_NOT)
    def test_functional(self):
        self.assertTrue(is_functional(Set()))
        self.assertIs(Undef(), is_functional(Set('a', 'b', 'c')))
        f = is_functional(basic_sets['left func'])
        self.assertTrue(f)
        f = is_functional(basic_sets['not left func'])
        self.assertFalse(f)
        f = is_functional(basic_clans['left func'])
        self.assertTrue(f)
        f = is_functional(basic_clans['not left func'])
        self.assertFalse(f)
        f = is_functional(basic_hordes['left func'])
        self.assertTrue(f)
        f = is_functional(basic_hordes['not left func'])
        self.assertFalse(f)

        s = basic_sets['left func']
        self.assertEqual(s.cached_functional, CacheStatus.IS)
        s = basic_sets['not left func']
        self.assertEqual(s.cached_functional, CacheStatus.IS_NOT)
 def _couplet_assert(self, test_couplet_name):
     """Assert that 'couplet' is a proper Couplet with left 'left' and right 'right'."""
     test_couplet = basic_couplets[test_couplet_name]
     left = test_couplet._test_val['left']
     right = test_couplet._test_val['right']
     couplet = Couplet(left=left, right=right)
     # Convert the arguments into Atoms if they are values.
     if not isinstance(left, MathObject):
         left = Atom(left)
     if not isinstance(right, MathObject):
         right = Atom(right)
     # Test the type structure.
     self.assertTrue(isinstance(couplet, MathObject))
     self.assertFalse(isinstance(couplet, Atom))
     self.assertTrue(isinstance(couplet, Couplet))
     self.assertFalse(isinstance(couplet, Set))
     # Compare the values of right and left.
     left_val = couplet.left
     right_val = couplet.right
     self.assertEqual(left_val, left)
     self.assertEqual(right_val, right)
     # Test that the representation caching doesn't change the value.
     couplet_repr = repr(couplet)
     self.assertEqual(couplet_repr, repr(couplet))
     # Check structure.
     self.assertEqual(test_couplet.get_ground_set(),
                      _basic_couplets_structs[test_couplet_name])
     # Test left set and functionality.
     self.assertIs(couplet.get_left_set(), Undef())
     self.assertIs(is_functional(couplet), Undef())
     self.assertIs(couplet('callable'), Undef())
     # Make sure that the representation evaluates to a couplet that compares equal.
     repr_exec = 'self.assertEqual(couplet, {0})'.format(repr(couplet))
     exec(repr_exec)
     # Print the representation and the string conversion.
     if self.print_examples:
         print('repr(Couplet(left={left}, right={right})) = {repr}'.format(
             left=repr(left_val), right=repr(right_val), repr=couplet_repr))
         print('str(Couplet(left={left}, right={right})) = {str}'.format(
             left=str(left_val), right=str(right_val), str=str(couplet)))
 def _couplet_assert(self, test_couplet_name):
     """Assert that 'couplet' is a proper Couplet with left 'left' and right 'right'."""
     test_couplet = basic_couplets[test_couplet_name]
     left = test_couplet._test_val['left']
     right = test_couplet._test_val['right']
     couplet = Couplet(left=left, right=right)
     # Convert the arguments into Atoms if they are values.
     if not isinstance(left, MathObject):
         left = Atom(left)
     if not isinstance(right, MathObject):
         right = Atom(right)
     # Test the type structure.
     self.assertTrue(isinstance(couplet, MathObject))
     self.assertFalse(isinstance(couplet, Atom))
     self.assertTrue(isinstance(couplet, Couplet))
     self.assertFalse(isinstance(couplet, Set))
     # Compare the values of right and left.
     left_val = couplet.left
     right_val = couplet.right
     self.assertEqual(left_val, left)
     self.assertEqual(right_val, right)
     # Test that the representation caching doesn't change the value.
     couplet_repr = repr(couplet)
     self.assertEqual(couplet_repr, repr(couplet))
     # Check structure.
     self.assertEqual(test_couplet.get_ground_set(), _basic_couplets_structs[test_couplet_name])
     # Test left set and functionality.
     self.assertIs(couplet.get_left_set(), Undef())
     self.assertIs(is_functional(couplet), Undef())
     self.assertIs(couplet('callable'), Undef())
     # Make sure that the representation evaluates to a couplet that compares equal.
     repr_exec = 'self.assertEqual(couplet, {0})'.format(repr(couplet))
     exec(repr_exec)
     # Print the representation and the string conversion.
     if self.print_examples:
         print('repr(Couplet(left={left}, right={right})) = {repr}'.format(
             left=repr(left_val), right=repr(right_val), repr=couplet_repr))
         print('str(Couplet(left={left}, right={right})) = {str}'.format(
             left=str(left_val), right=str(right_val), str=str(couplet)))