Skip to content

Commit 6c54611

Browse files
authored
Added testing for the fizzbuzz algorithm. (#833)
1 parent a310940 commit 6c54611

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tests/test_strings.py

+30-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
atbash,
4242
longest_palindrome,
4343
knuth_morris_pratt,
44-
panagram
44+
panagram,
45+
fizzbuzz
4546
)
4647

4748
import unittest
@@ -662,6 +663,33 @@ def test_swedish_panagram(self):
662663
# Assert
663664
self.assertEqual(True, res)
664665

665-
666+
class TestFizzbuzz(unittest.TestCase):
667+
"""[summary]
668+
Tests for the fizzbuzz method in file fizzbuzz.py
669+
"""
670+
671+
def test_fizzbuzz(self):
672+
# Testing that n < 0 returns a Value Error
673+
self.assertRaises(ValueError, fizzbuzz.fizzbuzz, -2)
674+
675+
# Testing that a string returns a Type Error.
676+
self.assertRaises(TypeError, fizzbuzz.fizzbuzz, "hello")
677+
678+
# Testing a base case, n = 3
679+
result = fizzbuzz.fizzbuzz(3)
680+
expected = [1, 2, "Fizz"]
681+
self.assertEqual(result, expected)
682+
683+
# Testing a base case, n = 5
684+
result = fizzbuzz.fizzbuzz(5)
685+
expected = [1, 2, "Fizz", 4, "Buzz"]
686+
self.assertEqual(result, expected)
687+
688+
# Testing a base case, n = 15 i.e. mod 3 and 5
689+
result = fizzbuzz.fizzbuzz(15)
690+
expected = [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11,
691+
"Fizz", 13, 14, "FizzBuzz"]
692+
self.assertEqual(result, expected)
693+
666694
if __name__ == "__main__":
667695
unittest.main()

0 commit comments

Comments
 (0)