Back to home

Test fileFizzBuzzRunning tests
Python Fizzbuzz main image

Python Fizzbuzz

Test file

Create file fizz_buzz_test.py:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 import unittest import fizz_buzz class FizzBuzzTest(unittest.TestCase): def test_capitalise_sentence(self): assess = [ { "input": 2, "expectation": 2 }, { "input": 3, "expectation": "Fizz" }, { "input": 5, "expectation": "Buzz" }, { "input": 15, "expectation": "FizzBuzz" }, ] for test in assess: self.assertEqual(fizz_buzz.run( test["input"]), test["expectation"]) if __name__ == '__main__': unittest.main()

FizzBuzz

Create file fizz_buzz.py.

1 2 3 4 5 6 7 8 9 def run(arg): if arg % 5 == 0 and arg % 3 == 0: return "FizzBuzz" elif arg % 3 == 0: return "Fizz" elif arg % 5 == 0: return "Buzz" else: return arg

Running tests

Change into directory and run python3 -m pytest -v fizz_buzz_test.py.

Dennis O'Keeffe

@dennisokeeffe92
  • Melbourne, Australia

Hi, I am a professional Software Engineer. Formerly of Culture Amp, UsabilityHub, Present Company and NightGuru.
I am currently working on workingoutloud.dev, Den Dribbles and LandPad .

Related articles


1,200+ PEOPLE ALREADY JOINED ❤️️

Get fresh posts + news direct to your inbox.

No spam. We only send you relevant content.