def count_inversions(f, merge_sort): L = [] with open(f, 'r') as long_integer: for seg in long_integer: L.append(int(seg.strip())) _, inversions = merge_sort(L) return inversions
def count_inversions(f, merge_sort): # reverse tree # seg = open(f).read().splitlines() # q = deque() long_int = [] with open(f, 'r') as long_integer: for seg in long_integer: for i in seg.strip(): long_int.append(int(i)) _, inversions = merge_sort(long_int) return inversions
def test_empty(self): i = [] correct = 0 l, inversions = merge_sort(i) self.assertEqual(correct, inversions)
def test_sorted(self): correct = [5, 8, 10, 12, 2, 1] j = dp(correct) l, inversions = merge_sort(j) correct.sort() self.assertListEqual(correct, l)
def test_larger_three_inversions(self): i = [0, 3, 2, 1] correct = 3 l, inversions = merge_sort(i) self.assertEqual(correct, inversions)
def test_one_inversion(self): i = [2, 1] correct = 1 l, inversions = merge_sort(i) self.assertEqual(correct, inversions)
def test_no_inversions(self): i = [1] correct = 0 l, inversions = merge_sort(i) self.assertEqual(correct, inversions)