도서출판 인사이트에서 새로나온 알고리즘 관련된 책 출간으로 간단한 알고리즘 문제풀이 이벤트가 있어서 풀어보았다.

사실 풀었다고 하기에도 좀 민망한 테스트 코드 수준인데 예시로 나온 정도만 해결할수 있을정도의 코드. 테스트 케이스도 하나-_-;

바운더리체크같은건 없으니까 너무 하드하게 돌리진 마셈;


import unittest



def list_rotate(target_list, start_index, end_index):

    return target_list[:start_index] + [target_list[end_index + 1]] \

    + target_list[start_index:end_index + 1] + target_list[end_index + 2:]



class TestInsightQuiz1(unittest.TestCase):

    def test_sample(self):

        self.assertEqual(1, 1)


    def test_list_rotate_squance(self):

        target = range(10)

        target = list_rotate(target, 2, 6)

        self.assertEqual(target, [0, 1, 7, 2, 3, 4, 5, 6, 8, 9])


if __name__ == '__main__':

    print('test start')

    unittest.main()



by 징이 2012. 9. 5. 09:51
| 1 |