-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_continuous_subarray_sum.py
More file actions
30 lines (23 loc) · 1.06 KB
/
test_continuous_subarray_sum.py
File metadata and controls
30 lines (23 loc) · 1.06 KB
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
from continuous_subarray_sum import check_subarray_sum
import unittest
class TestCheckSubarraySum(unittest.TestCase):
def test_returns_true_for_valid_subarray_sum(self):
"""Takes in list and returns True if subarray sum is possible"""
result = check_subarray_sum([23,2,6,4,7], 6)
self.assertTrue(result)
def test_returns_false_for_invalid_sum(self):
"""Takes in a list and returns False if subarray sum is possible"""
result = check_subarray_sum([23,2,6,4,7], 15)
self.assertFalse(result)
def test_raises_typeerror_if_not_list(self):
"""Raises a new TypeError if the first argument is not of type list"""
def result():
return check_subarray_sum({}, 10)
self.assertRaises(TypeError, result)
def test_raises_typeerror_if_not_int(self):
"""Raises a new TypeError if the second argument is not of type int"""
def result():
return check_subarray_sum([1, 2, 3], True)
self.assertRaises(TypeError, result)
if __name__ == "__main__":
unittest.main()