Question: Writing test case for this code. How would I write test cases for prepareGraph method? /** * If categoryMap is of size zero, throws an
Writing test case for this code.
How would I write test cases for prepareGraph method?
/** * If categoryMap is of size zero, throws an IllegalArgumentException whose message explains what is wrong. * * Else if any of the values in the category map is an empty set, throws an IllegalArgumentException whose message * explains what is wrong. * * Else if any of the numbers in the categoryMap is not positive, throws an IllegalAgumentException whose message * explains what is wrong. * * Else if operation is anything other than SUM, AVG, MAX, or MIN, throws an IllegalArgumentException whose message * explains what is wrong. * * Else, returns a TreeMap * Arizona {21 * California {14, 7, 6, 1} * Nevada {3, 11} * Utah {10, 2, 2} * * * and the operation is SUM. The map that is returned must map like this: * * * Arizona 21 * California 28 * Nevada 14 * Utah 14 *
*/ public static TreeMap
if (operation == MIN) { for (String key : categoryMap.keySet()) { double minval = categoryMap.get(key).get(0); for (double val : categoryMap.get(key)) { if (val < minval) { minval = val; } } summaryMap.put(key, minval); } } if (operation == SUM) { for (String key : categoryMap.keySet()) { double keySum = 0.0; for (double value : categoryMap.get(key)) { keySum = value + keySum; } summaryMap.put(key, keySum); } } if (operation == AVG) { for (String key : categoryMap.keySet()) { double keySum = 0.0; for (double val : categoryMap.get(key)) { keySum = val + keySum; } double avgVal = keySum / categoryMap.get(key).size(); summaryMap.put(key, avgVal); } } return summaryMap; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
