def test_properties(self): c = Couplet(1, 2) self.assertIs(c.get_left_set(), Undef()) self.assertIs(c.is_left_functional(), Undef()) self.assertIs(c.get_right_set(), Undef()) self.assertIs(c.is_right_functional(), Undef()) self.assertIs(c.is_bijection(), Undef()) self.assertFalse(c.is_reflexive()) c2 = Couplet(1, 1) self.assertTrue(c2.is_reflexive()) self.assertFalse(c.is_symmetric()) c2 = Couplet(1, 1) self.assertTrue(c2.is_symmetric()) self.assertIs(c.is_transitive(), Undef()) self.assertIs(c.is_equivalence_relation(), Undef())
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(couplet.is_left_functional(), 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)))