def test_count_inversions(self): # no inversions list = [0, 1, 2, 3, 4] res = count_inversions(list) assert res['count'] == 0 # list in reverse order has (n - 1)! inversions list = [4, 3, 2, 1, 0] res = count_inversions(list) assert res['count'] == 4 + 3 + 2 + 1
def test_count_inversions(self): array1 = [2, 4, 5, 6, 1, 3] array2 = [1, 2, 3, 4, 0] array3 = [1, 2, 3, 4, 5] array4 = [5, 4, 3, 2, 1] array5 = [1] array6 = [1, 2] array7 = [2, 1] self.assertEqual(7, count_inversions(array1)) self.assertEqual(4, count_inversions(array2)) self.assertEqual(0, count_inversions(array3)) self.assertEqual(10, count_inversions(array4)) self.assertEqual(0, count_inversions(array5)) self.assertEqual(0, count_inversions(array6)) self.assertEqual(1, count_inversions(array7))
def test_count_inversions_1(self): self.assertEqual(count_inversions.count_inversions([2, 1, 3, 1, 2]), 4)
def test_count_inversions(self): self.assertEqual(count_inversions.count_inversions([1, 1, 1, 2, 2]), 0)
def test_count_inversions_3(self): self.assertEqual(count_inversions.count_inversions([3, 2, 1]), 3)
def test_count_inversions_2(self): self.assertEqual(count_inversions.count_inversions([7, 5, 3, 1]), 6)
from count_inversions import count_inversions with open("input.txt") as f: a = [int(l) for l in f.readlines()] print(count_inversions(a))
def test_vector(self): for test_vector in self.vectors: inv, list = count_inversions.count_inversions(test_vector[0]) self.assertEqual(inv, test_vector[1])
def test_count_inversions(): assert_equal(count_inversions([1, 3, 5, 2, 4, 6]), 3) assert_equal(count_inversions([6, 5, 4, 3, 2, 1]), 15)
def test_multiple_inversions(self): self.array = [1, 3, 5, 2, 4, 6] self.assertEqual(3, count_inversions(self.array))
def test_one_inversion(self): self.array = [1, 3, 2] self.assertEqual([1, 3, 2], self.array) self.assertEqual(1, count_inversions(self.array))
def test_no_inversions(self): self.assertEqual(0, count_inversions(self.array))
def test_one(self): f = 'test_one.txt' correct = 22 inversions = count_inversions(f, merge_sort) self.assertEqual(correct, inversions)