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'
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)
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)
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)
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)
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
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
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) """
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
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)
def test_inverse(self): reverser = Composable(reverse) nulltran = reverser * reverser for s in "", "a", "0123456789", "abcdefghijklmnopqrstuvwxyz": self.assertEqual(nulltran(s), s)
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)
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)
def test_Powers_TypeError(self): with self.assertRaises(TypeError): squarer = Composable(square) po4 = squarer**"a"
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)
def test_inverse(self): reverser = Composable(reverse) nulltran = reverser * reverser for s in "", "a", "0123456789", string.ascii_lowercase : self.assertEqual(nulltran(s), s)
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)
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)
def test_Powers_ValueError(self): with self.assertRaises(ValueError): squarer = Composable(square) po4 = squarer**-1