[Python-checkins] python/dist/src/Lib/test test_sets.py,1.12,1.13

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sun, 25 Aug 2002 11:43:12 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv26090/lib/test

Modified Files:
	test_sets.py 
Log Message:
Implemented <, <=, >, >= for sets, giving subset and proper-subset
meanings.  I did not add new, e.g., ispropersubset() methods; we're
going nuts on those, and, e.g., there was no "friendly name" for
== either.


Index: test_sets.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_sets.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** test_sets.py	25 Aug 2002 18:21:47 -0000	1.12
--- test_sets.py	25 Aug 2002 18:43:10 -0000	1.13
***************
*** 365,369 ****
                     ">=": "issuperset",
                    }
!     cases_with_ops = Set(["==", "!="])
  
      def test_issubset(self):
--- 365,376 ----
                     ">=": "issuperset",
                    }
! 
!     reverse = {"==": "==",
!                "!=": "!=",
!                "<":  ">",
!                ">":  "<",
!                "<=": ">=",
!                ">=": "<=",
!               }
  
      def test_issubset(self):
***************
*** 372,385 ****
          for case in "!=", "==", "<", "<=", ">", ">=":
              expected = case in self.cases
              if case in TestSubsets.case2method:
-                 # Test the method-name spelling.
                  method = getattr(x, TestSubsets.case2method[case])
                  result = method(y)
                  self.assertEqual(result, expected)
-             if case in TestSubsets.cases_with_ops:
-                 # Test the binary infix spelling.
-                 result = eval("x" + case + "y", locals())
-                 self.assertEqual(result, expected)
  
  #------------------------------------------------------------------------------
  
--- 379,399 ----
          for case in "!=", "==", "<", "<=", ">", ">=":
              expected = case in self.cases
+             # Test the binary infix spelling.
+             result = eval("x" + case + "y", locals())
+             self.assertEqual(result, expected)
+             # Test the "friendly" method-name spelling, if one exists.
              if case in TestSubsets.case2method:
                  method = getattr(x, TestSubsets.case2method[case])
                  result = method(y)
                  self.assertEqual(result, expected)
  
+             # Now do the same for the operands reversed.
+             rcase = TestSubsets.reverse[case]
+             result = eval("y" + rcase + "x", locals())
+             self.assertEqual(result, expected)
+             if rcase in TestSubsets.case2method:
+                 method = getattr(y, TestSubsets.case2method[rcase])
+                 result = method(x)
+                 self.assertEqual(result, expected)
  #------------------------------------------------------------------------------
  
***************
*** 411,415 ****
     left  = Set([1])
     right = Set([1, 2])
!    name  = "one a non-empty subset of other"
     cases = "!=", "<", "<="
  
--- 425,429 ----
     left  = Set([1])
     right = Set([1, 2])
!    name  = "one a non-empty proper subset of other"
     cases = "!=", "<", "<="