Problem of the Day
A new programming or logic puzzle every Mon-Fri

Testable Fizzbuzz

A lot of developers skip the test making process or never take the time to learn how to create tests. So let's change that real quick and focus on testing for the day. Fizzbuzz is a simple program, you can read about it at http://en.wikipedia.org/wiki/Fizz_buzz#Other_uses. Today's objective is to implement it in the programming language of your choice, then using a testing suite or just plain asserts right some test cases.

To add some more clarification. Your function should take in a lower bound and an upper bound. Print fizz if divisble by 3, 5 for divisible by buzz, fizzbuzz if both, or just the number otherwise. The test suite should try different upper and lower bounds.

Permalink: http://problemotd.com/problem/testable-fizzbuzz/

Comments:

  • Anonymous - 9 years, 11 months ago

    Python

    def fizzbuzz(n1,n2):
    
        displaythis = []
    
        for x in range(n1,n2):
            if x % 3 == 0 and x % 5 == 0:
                displaythis.append('fizzbuzz')
            elif x % 3 == 0:
                displaythis.append('fizz')
            elif x % 5 == 0:
                displaythis.append('buzz')
            else:
                displaythis.append(x)
    
        return (displaythis)
    
    answer = []
    
    lower = int(input('Lower > '))
    
    upper = int(input('Upper > '))
    
    answer = fizzbuzz(lower,upper)
    
    print (answer)
    

    reply permalink

  • David - 9 years ago

    This is fizzbuzz, but it does not include the test element of the Problem presented.

    reply permalink

Content curated by @MaxBurstein