Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA PLS. Create a public class TestArrayMax that provides a single void class method named test. test accepts a single parameter: an instance of

IN JAVA PLS.

Create a public class TestArrayMax that provides a single void class method named test. test accepts a single parameter: an instance of ArrayMax.

Each ArrayMax provides a method max that accepts an int[] and returns the maximum of the values as an int. If the array is null or empty max should throw an IllegalArgumentException.

However, some ArrayMax implementations are broken! Your job is to identify all of them correctly. To do this you should use assert to test various inputs. (Do not throw other kinds of exceptions on failure.)

Here's an example:

1

2

// ensure that a single-element array is handled properly

assert max.max(new int[] {1}) == 1;

Your function does not need to return a value. Instead, if the code is correct no assertion should fail, and if it is incorrect one should.

As you design test inputs, here are two conflicting objectives to keep in mind:

Less is more. The fewer inputs you need to identify all broken cases, the more readable your test suite will be.

Think defensively. At the same time, you want to anticipate all the different mistakes that a programmer might make. You've probably made many of these yourself! Examples include forgetting to check for null, off-by-one errors, not handling special cases properly, etc.

You'll also need to think about how to use try-catch to handle places where the code should throw an exception, how to ensure that it does, and how to make sure it throws the right type.

Good luck and have fun!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions