-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinSearch unit test.py
More file actions
32 lines (27 loc) · 974 Bytes
/
linSearch unit test.py
File metadata and controls
32 lines (27 loc) · 974 Bytes
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
import unittest
def linSearch(list, target):
if list:
if list[0] == target: #checks if first element is target
return True
else:
return linSearch(list[1:],target) #recursive function moves through list until target is found
return False
class linSearchTests(unittest.TestCase):
def testOne(self):
self.assertTrue(linSearch([3,5,7,1,2,9], 1))
def testTwo(self):
self.assertTrue(linSearch([3,5,7,1,2,9], 3))
def testThree(self):
self.assertTrue(linSearch([3,5,7,1,2,9], 5))
def testFour(self):
self.assertTrue(linSearch([3,5,7,1,2,9], 9))
def testFive(self):
self.assertTrue(linSearch([3,5,7,1,2,9], 7))
def testSix(self):
self.assertTrue(linSearch([3,5,7,1,2,9], 2))
def testSeven(self):
self.assertFalse(linSearch([3,5,7,1,2,9], 4))
def main():
unittest.main()
if __name__ == '__main__':
main()