Fizz Buzz Sample Python Code

Code:

def FizzBuzz(value):
    result = ""
    if value <= 0:
        return result

    if value % 3 == 0:
        result += "fizz"
    if value % 5 == 0:
        result += "buzz"
    if not result:
        result += str(value)

    return result

def FizzBuzzExtended(value):
    result = ""
    if value <= 0:
        return result

    if value % 3 == 0 or "3" in str(value):
        result += "fizz"
    if value % 5 == 0 or "5" in str(value):
        result += "buzz"
    if not result:
        result += str(value)

    return result

Test:

class Test_FizzBuzzTests(unittest.TestCase):
    def test_fizzbuzz(self):
        testcases = {}
        testcases[0] = ""
        testcases[1] = "1"
        testcases[2] = "2"
        testcases[3] = "fizz"
        testcases[4] = "4"
        testcases[5] = "buzz"
        testcases[6] = "fizz"
        testcases[10] = "buzz"
        testcases[15] = "fizzbuzz"

        for key, value in testcases.items():
            result = fizzbuzz.FizzBuzz(key)
            self.assertEqual(value, result)
  
    def test_fizzbuzz_extended(self):
        testcases = {}
        testcases[0] = ""
        testcases[1] = "1"
        testcases[2] = "2"
        testcases[3] = "fizz"
        testcases[4] = "4"
        testcases[5] = "buzz"
        testcases[6] = "fizz"
        testcases[10] = "buzz"
        testcases[13] = "fizz"
        testcases[15] = "fizzbuzz"
        testcases[25] = "buzz"
        testcases[35] = "fizzbuzz"
        testcases[52] = "buzz"
        testcases[53] = "fizzbuzz"
        
        for key, value in testcases.items():
            result = fizzbuzz.FizzBuzzExtended(key)
            self.assertEqual(value, result)

if __name__ == '__main__':
    unittest.main()