fizzbuzz: always order fizzbuzzer output words

master
Bruno BELANYI 3 years ago
parent a48f7877d9
commit f9a9ffaaf5
  1. 2
      fizzbuzz/fizzbuzz.py
  2. 23
      fizzbuzz/test_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:

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

Loading…
Cancel
Save