mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
30 lines
811 B
Python
30 lines
811 B
Python
import unittest
|
|
|
|
|
|
class TestReverse(unittest.TestCase):
|
|
|
|
def test_reverse(self, func):
|
|
self.assertEqual(func(None), None)
|
|
self.assertEqual(func(['']), [''])
|
|
self.assertEqual(func(
|
|
['f', 'o', 'o', ' ', 'b', 'a', 'r']),
|
|
['r', 'a', 'b', ' ', 'o', 'o', 'f'])
|
|
print('Success: test_reverse')
|
|
|
|
def test_reverse_inplace(self, func):
|
|
target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']
|
|
func(target_list)
|
|
self.assertEqual(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])
|
|
print('Success: test_reverse_inplace')
|
|
|
|
|
|
def main():
|
|
test = TestReverse()
|
|
reverse_string = ReverseString()
|
|
test.test_reverse(reverse_string.reverse)
|
|
test.test_reverse_inplace(reverse_string.reverse)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|