From f9a9ffaaf504359dd31fc7b9201edb22b62f59b1 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 30 Nov 2019 12:08:18 +0100 Subject: [PATCH] fizzbuzz: always order fizzbuzzer output words --- fizzbuzz/fizzbuzz.py | 2 +- fizzbuzz/test_fizzbuzz.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fizzbuzz/fizzbuzz.py b/fizzbuzz/fizzbuzz.py index 4c01487..16cc30c 100755 --- a/fizzbuzz/fizzbuzz.py +++ b/fizzbuzz/fizzbuzz.py @@ -6,7 +6,7 @@ def fizzbuzzer(words: Dict[int, str]) -> Callable[[int], None]: def _fun(max: int) -> None: for i in range(1, max + 1): out = [] - for div, word in words.items(): + for div, word in sorted(words.items()): if i % div == 0: out.append(word) if len(out) > 0: diff --git a/fizzbuzz/test_fizzbuzz.py b/fizzbuzz/test_fizzbuzz.py index c4b2c9c..195f081 100644 --- a/fizzbuzz/test_fizzbuzz.py +++ b/fizzbuzz/test_fizzbuzz.py @@ -68,3 +68,26 @@ def test_can_foobarbazz_customization(capsys): "foobarbazz", ], ) + + +def test_can_foobarbazz_customization_regardless_of_dict_order(capsys): + foobarbazz = fizzbuzzer({4: "bazz", 3: "bar", 2: "foo"}) + list_output( + function=foobarbazz, + max=12, + capsys=capsys, + expected_list=[ + 1, + "foo", + "bar", + "foobazz", + 5, + "foobar", + 7, + "foobazz", + "bar", + "foo", + 11, + "foobarbazz", + ], + )