Skip to main content

Quiz 2.5: Assignments with sub-questions

Testing FizzBuzz

Given this class:

public class FizzBuzz {
public String fizzbuzzer(int n) {
if (n % 15 == 0) return "FizzBuzz";
if (n % 3 == 0) return "Fizz";
if (n % 5 == 0) return "Buzz";
return String.valueOf(n);
}
}
Subquestion 1a (2 points)

Which test is useful and working?

Show correct answer

A test that asserts "Fizz" for input 9:

@Test
void nineGivesFizz() {
assertEquals("Fizz", fizzBuzz.fizzbuzzer(9));
}
Subquestion 1b (2 points)

Which inputs are boundary values for the % 15 check?

Show correct answer

15

14

16

Subquestion 1c (1 point)

Which string does fizzbuzzer(5) return?

Show correct answer

Buzz