Skip to content
Snippets Groups Projects
Commit f1c98bc4 authored by Goik Martin's avatar Goik Martin
Browse files

Amending error message for multiple arithmetic operations

parent d4adc3ac
No related branches found
No related tags found
No related merge requests found
......@@ -19,13 +19,13 @@ public class B_MaxTest extends ExaminationTestDefaults {
assertMaximum(5.1, 0.1, 5, '+');
assertMaximum(35, 7, 0.2, '/');
assertMaximum(-1.4,-7, 0.2, '*');
assertMaximum(4,2, 2, '+');
assertMaximum(4,2, 2, '+', '*');
}
private static void assertMaximum(final double expected, final double first, final double second, char operation) {
private static void assertMaximum(final double expected, final double first, final double second, char ... operation) {
final StringBuilder errMsg = new StringBuilder("Expected maximum is " + expected + " == " + first + " " +
operation + " ");
final StringBuilder errMsg = new StringBuilder("Expected maximum is ").append(expected).append(" == ").
append(first).append(" ").append(join(operation)).append(" ");
if (second < 0) {
errMsg.append("(" + second + ")");
......@@ -34,4 +34,16 @@ public class B_MaxTest extends ExaminationTestDefaults {
}
Assert.assertEquals(errMsg.toString(), expected, B_Max.getBasicCalculationMax(first, second), PRECISION);
}
private static String join(char[] operations) {
if (1 == operations.length) {
return Character.toString(operations[0]);
} else {
StringBuilder ret = new StringBuilder("{") .append(operations[0]);
for (int i = 1; i < operations.length; i++) {
ret.append(" or ").append(operations[i]);
}
return ret.append('}').toString();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment