Files
python/exercises/go-counting/.meta/template.j2
Michael Morehouse 7a42fb71e2 various: comma fixes (#2150)
* forth: reinstate seperate classes

The template removed seperate classes per major case, resulting in
several tests with duplicate names and therefore an incomplete test
suite.

This reinstates the distinct classes.

Fixes #2148

* forth: minor black issue

Was accidentally running on a later version of Black than the one
specified in our requirements-generator.txt.

* various: fixes trailing comma issues

An upcoming change in Black revealed that we were adding unnecessary
trailing commas. These will _not_ be trimmed by Black in future builds.

Co-authored-by: Corey McCandless <cmccandless@users.noreply.github.com>
2019-12-24 21:28:38 -05:00

36 lines
1.2 KiB
Django/Jinja

{%- extends "master_template.j2" -%}
{% set imports = ["Board", "WHITE", "BLACK", "NONE"] %}
{% macro tuplify(territory_list) -%}
{%- if territory_list %}
{
{%- for v in territory_list %}
({{ v | join(', ') }}){{ "," if not loop.last }}
{%- endfor %}
}
{%- else %}
set()
{%- endif %}
{%- endmacro %}
{% macro test_case(case) -%}
def test_{{ case["description"] | to_snake }}(self):
board = Board({{ case["input"]["board"] }})
{%- if case is error_case %}
with self.assertRaisesWithMessage(ValueError):
board.territory(x={{ case["input"]["x"] }}, y={{ case["input"]["y"] }})
{%- else %}
{%- if "owner" in case["expected"] %}
stone, territory = board.territory(x={{ case["input"]["x"] }}, y={{ case["input"]["y"] }})
self.assertEqual(stone, {{ case["expected"]["owner"] }})
self.assertSetEqual(territory, {{ tuplify(case["expected"]["territory"]) }})
{%- else %}
territories = board.territories()
{%- for (k, v) in case["expected"].items() %}
self.assertSetEqual(territories[{{k.replace("territory", "") | upper }}], {{tuplify(v)}})
{%- endfor %}
{%- endif %}
{%- endif %}
{%- endmacro %}