def test_string_methods(self): hiya = MutableString("Hiya") self.assertEqual(hiya.replace('i', 'e'), "Heya") self.assertEqual(hiya.upper(), "HIYA") self.assertEqual(hiya.lower(), "hiya") self.assertTrue(hiya.endswith('ya')) self.assertFalse(hiya.endswith('ye')) self.assertTrue(hiya.endswith(('a', 'e'))) self.assertFalse(hiya.endswith(('i', 'e')))
def test_correct_type_returned(self): hiya = MutableString("hiya") self.assertIs(type(hiya[-3]), MutableString) self.assertIs(type(hiya[-3:]), MutableString) self.assertEqual({type(c) for c in hiya}, {MutableString}) self.assertIs(type(hiya[0]), MutableString) hiya[0] = "H" self.assertIs(type(hiya[0]), MutableString) self.assertIs(type(hiya + "!"), MutableString) self.assertIs(type(hiya.replace('i', 'e')), MutableString) self.assertIs(type(hiya.lower()), MutableString)