forked from wylaris/SWEN-559-Tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
53 lines (40 loc) · 1.66 KB
/
tests.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
import unittest
import requests
class TestSum(unittest.TestCase):
def test_sum(self):
"""Checks to see if 1 + 2 + 3 = 6"""
self.assertEqual(sum([1, 2, 3]), 6, "Should be 6")
def test_sum_tuple(self):
"""Checks to see if 1 + 2 = 6. THIS SHOULD FAIL"""
self.assertEqual(sum((4, 2)), 6, "Should be 6")
def test_prime_true(self):
"""Checks to see if 101 is prime"""
self.assertTrue(is_prime(101), "101 is a prime number")
def test_prime_false(self):
"""Confirms that 99 is not prime"""
self.assertFalse(is_prime(99), "99 is not a prime number")
def test_split_error(self):
"""Confirms that trying to split a list gives a TypeError"""
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
with self.assertRaises(TypeError):
s.split(2)
def test_replace(self):
"""Checks that I should be staying inside and not infecting people"""
s = 'I am sick and therefore, I should go see my friends'
s = s.replace("go see my friends", "STAY INSIDE")
self.assertEqual(s, 'I am sick and therefore, I should STAY INSIDE')
def test_get_request(self):
"""Checks that the API returns a 200 response"""
response = requests.get(
'https://jsonplaceholder.typicode.com/todos/1', auth=('user', 'pass'))
self.assertEqual(response.status_code, 200)
def is_prime(num):
"""Returns True if the provided number, num, is prime"""
if num > 1:
for i in range(2, num):
if (num % i) == 0:
return False
return True
if __name__ == '__main__':
unittest.main()