/
test_swap_k.py
55 lines (40 loc) · 1.37 KB
/
test_swap_k.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import a1
import unittest
class TestSwapK(unittest.TestCase):
""" Test class for function a1.swap_k. """
# Add your test methods for a1.swap_k here.
def test_empty_list(self):
"""Testing with empty list. The function should still return empty list for any k"""
L = list()
k = 0
L_expected = list()
a1.swap_k(L, k)
self.assertEquals(L_expected, L)
k = 1
a1.swap_k(L, k)
self.assertEquals(L_expected, L)
k = 2
a1.swap_k(L, k)
self.assertEquals(L_expected, L)
def test_single_element_list(self):
"""Testing with single element. The list should return the same"""
L = [1.0]
k = 0
L_expected = [1.0]
a1.swap_k(L, k)
self.assertEquals(L_expected, L)
k = 1
a1.swap_k(L, k)
self.assertEquals(L_expected, L)
def test_two_elements_swap(self):
"""Test two elements with k = 1, should reverse the list"""
L = [1, 2]
k = 1
L_expected = [2, 1]
a1.swap_k(L, k)
self.assertEquals(L_expected, L)
def test_two_elements_not_swapping(self):
"""Test two elements where k is bigger than len(L)"""
self.fail()
if __name__ == '__main__':
unittest.main(exit=False)