Skip to content

Commit

Permalink
two-bucket: Update test generation template (#2916)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhorod authored and BethanyG committed Feb 15, 2022
1 parent 88705fa commit 69485d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion exercises/practice/two-bucket/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"ikhadykin",
"N-Parsons",
"tqa236",
"yawpitch"
"yawpitch",
"mhorod"
],
"files": {
"solution": [
Expand Down
17 changes: 12 additions & 5 deletions exercises/practice/two-bucket/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{%- import "generator_macros.j2" as macros with context -%}
{%- macro test_call(case) -%}
{{ case["property"] }}({{ case["input"]["bucketOne"] }},
{{ case["input"]["bucketTwo"] }},
{{ case["input"]["goal"] }},
"{{ case["input"]["startBucket"] }}")
{%- endmacro -%}
{{ macros.header() }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
{% for case in cases -%}
def test_{{ case["description"] | to_snake }}(self):
self.assertEqual({{ case["property"] }}(
{{ case["input"]["bucketOne"] }},
{{ case["input"]["bucketTwo"] }},
{{ case["input"]["goal"] }},
"{{ case["input"]["startBucket"] }}"),
{%- if case is error_case %}
with self.assertRaisesWithMessage(ValueError):
{{ test_call(case) }}
{%- else %}
self.assertEqual({{ test_call(case) }},
(
{{ case["expected"]["moves"] }},
"{{ case["expected"]["goalBucket"] }}",
{{ case["expected"]["otherBucket"] }}
))
{%- endif %}

{% endfor %}

Expand Down
3 changes: 0 additions & 3 deletions exercises/practice/two-bucket/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ description = "Measure using bucket one of size 2 and bucket two of size 3 - sta

[449be72d-b10a-4f4b-a959-ca741e333b72]
description = "Not possible to reach the goal"
include = false

[aac38b7a-77f4-4d62-9b91-8846d533b054]
description = "With the same buckets but a different goal, then it is possible"
include = false

[74633132-0ccf-49de-8450-af4ab2e3b299]
description = "Goal larger than both buckets is impossible"
include = false
15 changes: 15 additions & 0 deletions exercises/practice/two-bucket/two_bucket_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ def test_measure_using_bucket_one_of_size_2_and_bucket_two_of_size_3_start_with_
):
self.assertEqual(measure(2, 3, 3, "one"), (2, "two", 2))

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".+")


if __name__ == "__main__":
unittest.main()

0 comments on commit 69485d1

Please sign in to comment.