Question: Encounter exception test issues when solving fizzbuzz problem. It is a different version of the original fizzbuzz problem. The inputs are two integers, consider a

Encounter exception test issues when solving fizzbuzz problem.

It is a different version of the original fizzbuzz problem. The inputs are two integers, consider a series of numbers between these two integers (start inclusive, end exclusive). The function will return a new array containing the string from these numbers, except some number are converted to "fizz" "buzz" "fizzbuzz" (as fizzbuzz problem rule). I wrote the following code for solution.

Encounter exception test issues when solving fizzbuzz problem. It is a different

But I cannot pass the following two exception tests:

version of the original fizzbuzz problem. The inputs are two integers, consider

The error says "Expected :java.lang.IllegalArgumentException. Actual:java.lang.NegativeArraySizeException".

public static String[] getFizzBuzz(int start, int end) { // TODO: Please implement the method // end) throw new IllegalArgumentException(); for(int i = start; i @Test void should_throw_if_inputs_are_negative() { assertThrows (IllegalArgumentException.class, () -> FizzBuzz.getFizzBuzz(-2, -1)); } @Test void should throw_if_start_is_greater_than_end() { assertThrows (IllegalArgumentException.class, () -> FizzBuzz.getFizzBuzz(10, 1)); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!