fizzbuzz: always order fizzbuzzer output words
This commit is contained in:
parent
a48f7877d9
commit
f9a9ffaaf5
|
@ -6,7 +6,7 @@ def fizzbuzzer(words: Dict[int, str]) -> Callable[[int], None]:
|
||||||
def _fun(max: int) -> None:
|
def _fun(max: int) -> None:
|
||||||
for i in range(1, max + 1):
|
for i in range(1, max + 1):
|
||||||
out = []
|
out = []
|
||||||
for div, word in words.items():
|
for div, word in sorted(words.items()):
|
||||||
if i % div == 0:
|
if i % div == 0:
|
||||||
out.append(word)
|
out.append(word)
|
||||||
if len(out) > 0:
|
if len(out) > 0:
|
||||||
|
|
|
@ -68,3 +68,26 @@ def test_can_foobarbazz_customization(capsys):
|
||||||
"foobarbazz",
|
"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…
Reference in a new issue