2019-11-30 12:04:57 +01:00
|
|
|
from fizzbuzz import fizzbuzz, fizzbuzzer
|
2019-11-30 11:36:58 +01:00
|
|
|
|
|
|
|
|
2019-11-30 12:04:57 +01:00
|
|
|
def list_output(max, capsys, expected_list, function):
|
|
|
|
function(max)
|
2019-11-30 11:36:58 +01:00
|
|
|
out, __ = capsys.readouterr()
|
2019-11-30 11:53:54 +01:00
|
|
|
assert out == "\n".join(map(lambda x: str(x), expected_list)) + "\n"
|
|
|
|
|
|
|
|
|
2019-11-30 12:04:57 +01:00
|
|
|
def list_fizzbuzz_output(max, capsys, expected_list):
|
|
|
|
list_output(max, capsys, expected_list, fizzbuzz)
|
|
|
|
|
|
|
|
|
2019-11-30 11:53:54 +01:00
|
|
|
def test_fizzbuzz_counts_to_two(capsys):
|
2019-11-30 12:04:57 +01:00
|
|
|
list_fizzbuzz_output(2, capsys, [1, 2])
|
2019-11-30 11:53:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_fizzbuzz_shows_fizz_on_three(capsys):
|
2019-11-30 12:04:57 +01:00
|
|
|
list_fizzbuzz_output(3, capsys, [1, 2, "fizz"])
|
2019-11-30 11:53:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_fizzbuzz_shows_buzz_on_five(capsys):
|
2019-11-30 12:04:57 +01:00
|
|
|
list_fizzbuzz_output(5, capsys, [1, 2, "fizz", 4, "buzz"])
|
2019-11-30 11:53:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_fizzbuzz_shows_fizzbuzz_on_fifteen(capsys):
|
2019-11-30 12:04:57 +01:00
|
|
|
list_fizzbuzz_output(
|
2019-11-30 11:53:54 +01:00
|
|
|
15,
|
|
|
|
capsys,
|
|
|
|
[
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
"fizz",
|
|
|
|
4,
|
|
|
|
"buzz",
|
|
|
|
"fizz",
|
|
|
|
7,
|
|
|
|
8,
|
|
|
|
"fizz",
|
|
|
|
"buzz",
|
|
|
|
11,
|
|
|
|
"fizz",
|
|
|
|
13,
|
|
|
|
14,
|
|
|
|
"fizzbuzz",
|
|
|
|
],
|
|
|
|
)
|
2019-11-30 12:04:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_can_foobarbazz_customization(capsys):
|
|
|
|
foobarbazz = fizzbuzzer({2: "foo", 3: "bar", 4: "bazz"})
|
|
|
|
list_output(
|
|
|
|
function=foobarbazz,
|
|
|
|
max=12,
|
|
|
|
capsys=capsys,
|
|
|
|
expected_list=[
|
|
|
|
1,
|
|
|
|
"foo",
|
|
|
|
"bar",
|
|
|
|
"foobazz",
|
|
|
|
5,
|
|
|
|
"foobar",
|
|
|
|
7,
|
|
|
|
"foobazz",
|
|
|
|
"bar",
|
|
|
|
"foo",
|
|
|
|
11,
|
|
|
|
"foobarbazz",
|
|
|
|
],
|
|
|
|
)
|
2019-11-30 12:08:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
],
|
|
|
|
)
|