import unittest

from exercises.arrays import sign_sort


class SignSortTest(unittest.TestCase):

    def test_invert(self):
        arr = range(10)
        sign_sort.invert(arr, 0, 10)
        self.assertEqual(arr, range(9, -1, -1))
        sign_sort.invert(arr, 3, 7)
        self.assertEqual(arr, [9, 8, 7, 3, 4, 5, 6, 2, 1, 0])

    def test_rotate(self):
        arr = range(10)
        sign_sort.rotate(arr, 0, 10, 3)
        self.assertEqual(arr, [3, 4, 5, 6, 7, 8, 9, 0, 1, 2])
        sign_sort.rotate(arr, 3, 7, 2)
        self.assertEqual(arr, [3, 4, 5, 8, 9, 6, 7, 0, 1, 2])

    def test_sign_sort(self):
        arr = [1, -1, 0, 2, 2, -3, -1, 0, 4]
        sign_sort.sign_sort(arr)
        self.assertEqual(arr, [-1, -3, -1, 1, 0, 2, 2, 0, 4])
        arr = [-1, -2, -3, -4, -5, -6, -7]
        sign_sort.sign_sort(arr)
        self.assertEqual(arr, [-1, -2, -3, -4, -5, -6, -7])
        arr = [4, 1, 5, 0, 3, 2, 6]
        sign_sort.sign_sort(arr)
        self.assertEqual(arr, [4, 1, 5, 0, 3, 2, 6])

    def test_sign_sort_empty(self):
        arr = []
        sign_sort.sign_sort(arr)
        self.assertEqual(arr, [])