def test_exceptions(self):
     fc = Composable(square)
     pc = Composable(pwr)
     with self.assertRaises(TypeError):
         fc = fc * 3
     with self.assertRaises(TypeError):
         fc = square * fc
     with self.assertRaises(ValueError):
         pc = pc**-3
     with self.assertRaises(TypeError):
         pc = pc**'a'
Exemple #2
0
    def test_inverse(self):
        "The purpose of this test is to ensure that s = reverse(reverse(s))."

        reverser = Composable(reverse)
        nulltran = reverser**2
        for s in "", "a", "0123456789", "abcdefghijklmnopqrstuvwxyz":
            self.assertEquals(nulltran(s), s)
Exemple #3
0
 def test_square(self):
     print("\n ***** Test Square numbers******")
     squarer = Composable(square)
     po4 = squarer * squarer
     for v, r in ((1, 1), (2, 16), (3, 81), (-1, 1), (-2, 16)):
         print(po4(v))
         self.assertEqual(po4(v), r)
Exemple #4
0
    def test_square(self):
        "The purpose of this test is to ensure that square(x) = x * x."

        squarer = Composable(square)
        po4 = squarer * squarer
        for v, r in ((1, 1), (2, 16), (3, 81)):
            self.assertEqual(po4(v), r)
Exemple #5
0
 def test_inverse(self):
     print("\n ***** Test Inverse String attributes******")
     reverser = Composable(reverse)
     nulltran = reverser * reverser
     for s in "", "a", "0123456789", "abcdefghijklmnopqrstuvwxyz":
         print(nulltran(s))
         self.assertEqual(nulltran(s), s)
Exemple #6
0
 def test_exceptions(self):
     print("\n ***** Test Exceptions Type Errors******")
     fc = Composable(square)
     print("Type is ", type(fc))
     with self.assertRaises(TypeError):    
         fc = fc * 3
     with self.assertRaises(TypeError):
         fc = square * fc
Exemple #7
0
 def test_exceptions(self):
     fc = Composable(square)
     with self.assertRaises(TypeError):
         fc = fc * 3
     with self.assertRaises(TypeError):
         fc = square * fc
     with self.assertRaises(TypeError):
         fc = fc**'not an integer'
     with self.assertRaises(ValueError):
         fc = fc**-5
Exemple #8
0
 def test_exceptions(self):
     fc = Composable(square)
     with self.assertRaises(TypeError):
         fc = fc * 3
     with self.assertRaises(TypeError):
         fc = square * fc
     with self.assertRaises(TypeError):
         fc = square ** 0.5
     with self.assertRaises(TypeError):
         fc = square ** -2
 def test_exceptions(self):
     fc = Composable(square)
     with self.assertRaises(TypeError):
         fc = fc * 3
     with self.assertRaises(TypeError):
         fc = square * fc
     with self.assertRaises(TypeError):
         fc = square ** '1'
     with self.assertRaises(TypeError):
         fc = square ** 1.1
         
     with self.assertRaises(ValueError):
         test = fc**0
         test = fc ** -1
     " or - better "
     with self.assertRaises(ValueError):
         test= fc.__pow__(0)
         test=fc.__pow__(-1)
         
     """            
Exemple #10
0
    def test_exceptions(self):
        """
        The purpose of this test is to ensure that passing
        (1) a non-Composable object to the __mul__ method raises a TypeError and
        (2) a non-integer argument to the __pow__ method raises a TypeError and
        (3) a non-positive argument to the __pow__ method raises a ValueError.
        """

        fc = Composable(square)
        with self.assertRaises(TypeError):
            fc = fc * 3
        with self.assertRaises(TypeError):
            fc**q
        with self.assertRaises(ValueError):
            fc**-1
Exemple #11
0
 def test_pow(self):
     for a in (2, 3, 4, 5, 6):
         raizit = Composable(pwr)
         cuber = raizit(a, 3)
         b = a**3
         self.assertEqual(cuber, b)
Exemple #12
0
 def test_inverse(self):
     reverser = Composable(reverse)
     nulltran = reverser * reverser
     for s in "", "a", "0123456789", "abcdefghijklmnopqrstuvwxyz":
         self.assertEqual(nulltran(s), s)
Exemple #13
0
 def test_power(self):
     powers = Composable(square)
     po4 = powers**2
     for v, r in ((1, 1), (2, 2**4), (3, 3**4)):
         self.assertEqual(po4(v), r)
Exemple #14
0
 def test_power(self):
     sqr = Composable(square)
     pow = sqr * sqr * sqr
     for v, r in ((1,1), (2, 256), (3, 6561)):
         self.assertEqual(pow(v), r)
Exemple #15
0
 def test_Powers_TypeError(self):
     with self.assertRaises(TypeError):
         squarer = Composable(square)
         po4 = squarer**"a"
Exemple #16
0
 def test_power(self):
     squarer = Composable(square)
     po8 = squarer ** 3
     for v, r in ((1,1), (2, 256), (3, 6561)):
         self.assertEqual(po8(v), r)
Exemple #17
0
 def test_inverse(self):
     reverser = Composable(reverse)
     nulltran = reverser * reverser
     for s in "", "a", "0123456789", string.ascii_lowercase :
         self.assertEqual(nulltran(s), s)
Exemple #18
0
 def test_square(self):
     squarer = Composable(square)
     po4 = squarer * squarer
     for v, r in ((1, 1), (2, 16), (3, 81)):
         self.assertEqual(po4(v), r)
Exemple #19
0
 def test_inverse(self):
     reverser = Composable(reverse)
     nulltran = reverser**2  #  reverser -- commenting out what was a mulitplicand
     for s in "", "a", "0123456789", "abcdefghijklmnopqrstuvwxyz":
         self.assertEqual(nulltran(s), s)
Exemple #20
0
 def test_Powers_ValueError(self):
     with self.assertRaises(ValueError):
         squarer = Composable(square)
         po4 = squarer**-1