Skip to content

Commit 69a571f

Browse files
cmccandlessyawpitch
authored andcommitted
isogram: add test template (exercism#1881)
- add canonical_ref() generator macro
1 parent 425d50a commit 69a571f

3 files changed

Lines changed: 41 additions & 11 deletions

File tree

config/generator_macros.j2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
{# Usage: {%- import "generator_macros.j2" as macros -%} #}
2+
{# {{ macros.canonical_ref(version) }} #}
3+
4+
{% macro canonical_ref(version) -%}
5+
# Tests adapted from `problem-specifications//canonical-data.json` @ v{{ version }}
6+
{%- endmacro %}
7+
18
{% macro utility() -%}# Utility functions
29
def setUp(self):
310
try:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{%- import "generator_macros.j2" as macros -%}
2+
{%- macro test_call(case) %}
3+
{{ case["property"] | to_snake }}(
4+
{% for arg in case["input"].values() -%}
5+
"{{ arg }}",
6+
{% endfor %}
7+
)
8+
{% endmacro -%}
9+
import unittest
10+
11+
from {{ exercise | to_snake }} import {% for prop in properties -%}
12+
{{ prop | to_snake }}{% if not loop.last %}, {% endif -%}
13+
{% endfor %}
14+
15+
{{ macros.canonical_ref(version) }}
16+
17+
class {{ exercise | camel_case }}Test(unittest.TestCase):
18+
{# All test cases in this exercise are nested, so use two for loops -#}
19+
{% for case in cases -%}{% for case in case["cases"] -%}
20+
def test_{{ case["description"] | to_snake }}(self):
21+
self.assertIs(
22+
{{- test_call(case) }},
23+
{{ case["expected"] }}
24+
)
25+
{% endfor %}{% endfor %}
26+
27+
28+
if __name__ == '__main__':
29+
unittest.main()

exercises/isogram/isogram_test.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
from isogram import is_isogram
44

5-
65
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.7.0
76

8-
class IsogramTest(unittest.TestCase):
97

8+
class IsogramTest(unittest.TestCase):
109
def test_empty_string(self):
1110
self.assertIs(is_isogram(""), True)
1211

@@ -16,7 +15,7 @@ def test_isogram_with_only_lower_case_characters(self):
1615
def test_word_with_one_duplicated_character(self):
1716
self.assertIs(is_isogram("eleven"), False)
1817

19-
def test_word_with_one_duplicated_character_from_end_of_alphabet(self):
18+
def test_word_with_one_duplicated_character_from_the_end_of_the_alphabet(self):
2019
self.assertIs(is_isogram("zzyzx"), False)
2120

2221
def test_longest_reported_english_isogram(self):
@@ -25,13 +24,13 @@ def test_longest_reported_english_isogram(self):
2524
def test_word_with_duplicated_character_in_mixed_case(self):
2625
self.assertIs(is_isogram("Alphabet"), False)
2726

28-
def test_word_with_duplicated_letter_in_mixed_case_lowercase_first(self):
27+
def test_word_with_duplicated_character_in_mixed_case_lowercase_first(self):
2928
self.assertIs(is_isogram("alphAbet"), False)
3029

3130
def test_hypothetical_isogrammic_word_with_hyphen(self):
3231
self.assertIs(is_isogram("thumbscrew-japingly"), True)
3332

34-
def test_hypothetical_word_with_duplicate_character_following_hyphen(self):
33+
def test_hypothetical_word_with_duplicated_character_following_hyphen(self):
3534
self.assertIs(is_isogram("thumbscrew-jappingly"), False)
3635

3736
def test_isogram_with_duplicated_hyphen(self):
@@ -46,11 +45,6 @@ def test_duplicated_character_in_the_middle(self):
4645
def test_same_first_and_last_characters(self):
4746
self.assertIs(is_isogram("angola"), False)
4847

49-
# Additional tests for this track
50-
51-
def test_isogram_with_duplicated_letter_and_nonletter_character(self):
52-
self.assertIs(is_isogram("Aleph Bot Chap"), False)
53-
5448

55-
if __name__ == '__main__':
49+
if __name__ == "__main__":
5650
unittest.main()

0 commit comments

Comments
 (0)