2020-07-04 22:56:49 +08:00
|
|
|
import unittest
|
2015-07-04 07:57:09 +08:00
|
|
|
|
|
|
|
|
2020-07-04 22:56:49 +08:00
|
|
|
class TestReverse(unittest.TestCase):
|
2015-07-12 03:34:14 +08:00
|
|
|
|
2016-08-13 18:40:13 +08:00
|
|
|
def test_reverse(self, func):
|
2020-07-04 22:56:49 +08:00
|
|
|
self.assertEqual(func(None), None)
|
|
|
|
self.assertEqual(func(['']), [''])
|
|
|
|
self.assertEqual(func(
|
2015-07-12 03:34:14 +08:00
|
|
|
['f', 'o', 'o', ' ', 'b', 'a', 'r']),
|
|
|
|
['r', 'a', 'b', ' ', 'o', 'o', 'f'])
|
2015-07-04 07:57:09 +08:00
|
|
|
print('Success: test_reverse')
|
|
|
|
|
2016-08-13 18:40:13 +08:00
|
|
|
def test_reverse_inplace(self, func):
|
2016-01-21 02:40:10 +08:00
|
|
|
target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']
|
2016-08-13 18:40:13 +08:00
|
|
|
func(target_list)
|
2020-07-04 22:56:49 +08:00
|
|
|
self.assertEqual(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])
|
2016-01-21 02:40:10 +08:00
|
|
|
print('Success: test_reverse_inplace')
|
|
|
|
|
2015-07-12 03:34:14 +08:00
|
|
|
|
2015-07-04 07:57:09 +08:00
|
|
|
def main():
|
|
|
|
test = TestReverse()
|
2016-08-13 18:40:13 +08:00
|
|
|
reverse_string = ReverseString()
|
|
|
|
test.test_reverse(reverse_string.reverse)
|
|
|
|
test.test_reverse_inplace(reverse_string.reverse)
|
2015-07-12 03:34:14 +08:00
|
|
|
|
|
|
|
|
2015-07-04 07:57:09 +08:00
|
|
|
if __name__ == '__main__':
|
2020-07-04 22:56:49 +08:00
|
|
|
main()
|