2023-07-15 15:27:31 -07:00
|
|
|
# These tests are auto-generated with test data from:
|
|
|
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/two-bucket/canonical-data.json
|
2023-07-21 16:54:40 -07:00
|
|
|
# File last updated on 2023-07-21
|
2023-07-15 15:27:31 -07:00
|
|
|
|
2017-10-08 15:17:14 +05:30
|
|
|
import unittest
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
from two_bucket import (
|
|
|
|
|
measure,
|
|
|
|
|
)
|
2017-10-08 15:17:14 +05:30
|
|
|
|
2019-10-03 21:08:30 +02:00
|
|
|
|
2017-10-08 15:17:14 +05:30
|
|
|
class TwoBucketTest(unittest.TestCase):
|
2019-10-03 21:08:30 +02:00
|
|
|
def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5_start_with_bucket_one(
|
2021-01-31 16:49:12 -05:00
|
|
|
self,
|
2019-10-03 21:08:30 +02:00
|
|
|
):
|
2018-02-20 22:39:48 +08:00
|
|
|
self.assertEqual(measure(3, 5, 1, "one"), (4, "one", 5))
|
2017-10-08 15:17:14 +05:30
|
|
|
|
2019-10-03 21:08:30 +02:00
|
|
|
def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5_start_with_bucket_two(
|
2021-01-31 16:49:12 -05:00
|
|
|
self,
|
2019-10-03 21:08:30 +02:00
|
|
|
):
|
2018-02-20 22:39:48 +08:00
|
|
|
self.assertEqual(measure(3, 5, 1, "two"), (8, "two", 3))
|
2017-10-08 15:17:14 +05:30
|
|
|
|
2019-10-03 21:08:30 +02:00
|
|
|
def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11_start_with_bucket_one(
|
2021-01-31 16:49:12 -05:00
|
|
|
self,
|
2019-10-03 21:08:30 +02:00
|
|
|
):
|
2018-02-20 22:39:48 +08:00
|
|
|
self.assertEqual(measure(7, 11, 2, "one"), (14, "one", 11))
|
2017-10-08 15:17:14 +05:30
|
|
|
|
2019-10-03 21:08:30 +02:00
|
|
|
def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11_start_with_bucket_two(
|
2021-01-31 16:49:12 -05:00
|
|
|
self,
|
2019-10-03 21:08:30 +02:00
|
|
|
):
|
2018-02-20 22:39:48 +08:00
|
|
|
self.assertEqual(measure(7, 11, 2, "two"), (18, "two", 7))
|
2017-10-08 15:17:14 +05:30
|
|
|
|
2019-10-03 21:08:30 +02:00
|
|
|
def test_measure_one_step_using_bucket_one_of_size_1_and_bucket_two_of_size_3_start_with_bucket_two(
|
2021-01-31 16:49:12 -05:00
|
|
|
self,
|
2019-10-03 21:08:30 +02:00
|
|
|
):
|
2018-02-20 22:39:48 +08:00
|
|
|
self.assertEqual(measure(1, 3, 3, "two"), (1, "two", 0))
|
2017-10-08 15:17:14 +05:30
|
|
|
|
2019-10-03 21:08:30 +02:00
|
|
|
def test_measure_using_bucket_one_of_size_2_and_bucket_two_of_size_3_start_with_bucket_one_and_end_with_bucket_two(
|
2021-01-31 16:49:12 -05:00
|
|
|
self,
|
2019-10-03 21:08:30 +02:00
|
|
|
):
|
2018-02-20 22:39:48 +08:00
|
|
|
self.assertEqual(measure(2, 3, 3, "one"), (2, "two", 2))
|
2017-10-08 15:17:14 +05:30
|
|
|
|
2022-02-13 01:11:38 +01:00
|
|
|
def test_not_possible_to_reach_the_goal(self):
|
|
|
|
|
with self.assertRaisesWithMessage(ValueError):
|
|
|
|
|
measure(6, 15, 5, "one")
|
|
|
|
|
|
|
|
|
|
def test_with_the_same_buckets_but_a_different_goal_then_it_is_possible(self):
|
|
|
|
|
self.assertEqual(measure(6, 15, 9, "one"), (10, "two", 0))
|
|
|
|
|
|
|
|
|
|
def test_goal_larger_than_both_buckets_is_impossible(self):
|
|
|
|
|
with self.assertRaisesWithMessage(ValueError):
|
|
|
|
|
measure(5, 7, 8, "one")
|
|
|
|
|
|
|
|
|
|
# Utility functions
|
|
|
|
|
def assertRaisesWithMessage(self, exception):
|
|
|
|
|
return self.assertRaisesRegex(exception, r".+")
|