This repository was archived by the owner on Mar 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchange_test.py
More file actions
54 lines (37 loc) · 1.93 KB
/
Copy pathchange_test.py
File metadata and controls
54 lines (37 loc) · 1.93 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import unittest
from change import find_fewest_coins
# Tests adapted from `problem-specifications//canonical-data.json`
class ChangeTest(unittest.TestCase):
def test_single_coin_change(self):
self.assertEqual(find_fewest_coins([1, 5, 10, 25, 100], 25), [25])
def test_multiple_coin_change(self):
self.assertEqual(find_fewest_coins([1, 5, 10, 25, 100], 15), [5, 10])
def test_change_with_lilliputian_coins(self):
self.assertEqual(find_fewest_coins([1, 4, 15, 20, 50], 23), [4, 4, 15])
def test_change_with_lower_elbonia_coins(self):
self.assertEqual(find_fewest_coins([1, 5, 10, 21, 25], 63), [21, 21, 21])
def test_large_target_values(self):
self.assertEqual(
find_fewest_coins([1, 2, 5, 10, 20, 50, 100], 999),
[2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100],
)
def test_possible_change_without_unit_coins_available(self):
self.assertEqual(find_fewest_coins([2, 5, 10, 20, 50], 21), [2, 2, 2, 5, 10])
def test_another_possible_change_without_unit_coins_available(self):
self.assertEqual(find_fewest_coins([4, 5], 27), [4, 4, 4, 5, 5, 5])
def test_no_coins_make_0_change(self):
self.assertEqual(find_fewest_coins([1, 5, 10, 21, 25], 0), [])
def test_error_testing_for_change_smaller_than_the_smallest_of_coins(self):
with self.assertRaisesWithMessage(ValueError):
find_fewest_coins([5, 10], 3)
def test_error_if_no_combination_can_add_up_to_target(self):
with self.assertRaisesWithMessage(ValueError):
find_fewest_coins([5, 10], 94)
def test_cannot_find_negative_change_values(self):
with self.assertRaisesWithMessage(ValueError):
find_fewest_coins([1, 2, 5], -5)
# Utility functions
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
if __name__ == "__main__":
unittest.main()