2020-07-14 09:26:50 +08:00
|
|
|
import unittest
|
2017-03-27 17:24:00 +08:00
|
|
|
|
|
|
|
|
2020-07-14 09:26:50 +08:00
|
|
|
class TestFindMagicIndex(unittest.TestCase):
|
2017-03-27 17:24:00 +08:00
|
|
|
|
|
|
|
def test_find_magic_index(self):
|
|
|
|
magic_index = MagicIndex()
|
2020-07-14 09:26:50 +08:00
|
|
|
self.assertEqual(magic_index.find_magic_index(None), -1)
|
|
|
|
self.assertEqual(magic_index.find_magic_index([]), -1)
|
2017-03-27 17:24:00 +08:00
|
|
|
array = [-4, -2, 2, 6, 6, 6, 6, 10]
|
2020-07-14 09:26:50 +08:00
|
|
|
self.assertEqual(magic_index.find_magic_index(array), 2)
|
2017-03-27 17:24:00 +08:00
|
|
|
array = [-4, -2, 1, 6, 6, 6, 6, 10]
|
2020-07-14 09:26:50 +08:00
|
|
|
self.assertEqual(magic_index.find_magic_index(array), 6)
|
2017-03-27 17:24:00 +08:00
|
|
|
array = [-4, -2, 1, 6, 6, 6, 7, 10]
|
2020-07-14 09:26:50 +08:00
|
|
|
self.assertEqual(magic_index.find_magic_index(array), -1)
|
2017-03-27 17:24:00 +08:00
|
|
|
print('Success: test_find_magic')
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
test = TestFindMagicIndex()
|
|
|
|
test.test_find_magic_index()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-07-14 09:26:50 +08:00
|
|
|
main()
|