예제 #1
0
 def test_swap_pivot_exception(self):
     a = [4, 5, 2, 1, 6, 3]
     l = 1
     r = 5
     mode = 'rand'
     with self.assertRaises(ValueError):
         swap_pivot(a, l, r, mode)
예제 #2
0
 def test_swap_pivot_2(self):
     a = [4, 5, 2, 1, 6, 3]
     l = 1
     r = 5
     mode = 'last'
     expected_a = [4, 6, 2, 1, 5, 3]
     new_a = swap_pivot(a, l, r, mode)
     self.assertListEqual(expected_a, new_a)
예제 #3
0
 def test_swap_pivot(self):
     a = [4, 5, 2, 1, 6, 3]
     l = 0
     r = 6
     mode = 'last'
     expected_a = [3, 5, 2, 1, 6, 4]
     new_a = swap_pivot(a, l, r, mode)
     self.assertListEqual(expected_a, new_a)
예제 #4
0
 def test_swap_pivot_3(self):
     a = [4, 5, 2, 1, 6, 3, 7]
     expected_a = [4, 5, 2, 1, 6, 3, 7]
     swapped_a = swap_pivot(a, 0, 7, mode='median')
     self.assertListEqual(expected_a, swapped_a)
예제 #5
0
 def test_swap_pivot_2(self):
     a = [4, 5, 2, 1, 6, 3]
     expected_a = [4, 2, 5, 1, 6, 3]
     swapped_a = swap_pivot(a, 1, 4, mode='median')
     self.assertListEqual(expected_a, swapped_a)