Create a method named test that accepts a single parameter: an instance of ArrayMax. Each ArrayMax...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Create a method named test that accepts a single parameter: an instance of ArrayMax. Each ArrayMax provides a method max that accepts an IntArray 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, or use require or check.) Here's an example: 1 // ensure that a single-element array is handled properly 2 assert(max.max (intArrayOf (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. Create a method named test that accepts a single parameter: an instance of ArrayMax. Each ArrayMax provides a method max that accepts an IntArray 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, or use require or check.) Here's an example: 1 // ensure that a single-element array is handled properly 2 assert(max.max (intArrayOf (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.
Expert Answer:
Answer rating: 100% (QA)
It seems like there are some typos in your request but Ill try to provide you with a method named te... View the full answer
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Rewrite these sentences to eliminate buzzwords and figures of speech. A. Also, through SCMC and by also gaining a membership in ISM, certification opportunities will be at your fingertips. B. The...
-
A player bounces a 0.43-kg soccer ball off her head, changing the velocity of the ball from v(vector) i = (8.8 m/s)x + ( 2.3 m/s)y to v(vector) f = (5.2 m/s)x + (3.7 m/s)y. If the ball is in contact...
-
It is known that y = e kt is a solution of the differential equation y" - 16y = 0. Find the values of k.
-
The cash flows associated with a project are shown below. The interest rate varies from year to year as shown. Determine an equivalent uniform annual series of cash flows. EOY Cash Flow Interest...
-
In order to meet holiday demand, Pennys Pie Shop requires a production line that is capable of producing 50 pecan pies per week, while operating only 40 hours per week. There are only 4 steps...
-
I am facing a Database connection error (2). Could not connect to MySQL. error. Source codes are: Database Error Error establishing a database connection. Database connection error (2). Could not...
-
Managers often assume a strictly linear relationship between cost and the level of activity. Under what conditions would this be a valid or invalid assumption?
-
Circuits having the form of one shown in Figure 3.55 are termed bridge circuits. iin R R + Vout Figure 3.55 R3 R (a) What resistance does the current source see when nothing is connected to the...
-
Compute the initial purchase pricefor an asset with book value of$ 8 3 2 1 1 and total accumulateddepreciation of $ 4 4 3 0 7 .
-
George is a graduate mechanical engineer, and having passed the FE exam during his senior year in college, he now works as an Engineer in Training (EIT) for a medium-sized engineering firm under the...
-
Examine the pros and cons of using credit cards. A customer is considering a travel and entertainment credit card. What should the customer know before accepting the card?
-
A cost matrix generated through the Dynamic Time Warping algorithm is given below. The warping path is marked by the light blue color of the cells. Compute the costs of this warping path. 7 13. 12 4...
-
can you fix this code for me? "Rico"; int age = 26; double percentage = 60; char grade = 'B'; public void compare() { if (name == "Rico") System.out.println ("Hi There Rico!"); } if (age ==; 26); { ...
-
a. The Philadelphia office of Price Waterhouse Coopers LLP hired five accounting trainees this year. Their monthly starting salaries were: $3173, $3559, $3449, $3128 and S3625. Compute the population...
-
Why is disclosure of depreciation or amortization methods and rates so important?
-
Write a program that produces the following figure (which vaguely resembles the Seattle Space Needle) as its output using nested for loops. Use a class constant to make it possible to change the size...
-
Write a method called countQuarters that takes an int representing a number of cents as a parameter and returns the number of quarter coins represented by that many cents. Dont count any whole...
-
Write a method called isMagicSquare that accepts a two-dimensional array of integers as a parameter and returns true if it is a magic square. A square matrix is a magic square if all of its row,...
-
Mexico has labor laws that specify a daily (rather than hourly) minimum wage. In 2018, the daily minimum wage in Mexico was about 103 pesos per day, and the exchange rate between Mexican pesos and...
-
In 2017, an estimated 7.7 million Mexican-born immigrants were employed in the United States. a. If 60 percent of the Mexican-born immigrants remitted money to family members in Mexico in 2017, and...
-
A mathematical approximation called the rule of 70 tells us how long it will take for something to double in size if it grows at a constant rate. The doubling time is approximately equal to the...
Study smarter with the SolutionInn App