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", + ], + )