IcyHot code only
public class IcyHot {
public static void main(String[] args) {
IcyHot app = new IcyHot();
app.icyHotTestCases();
}
/** Running count of test cases executed. */
private int testCaseCount;
/** Running count of test cases that failed (actual != expected). */
private int testCaseErrors;
/**
* Test helper - calls the target function with the given inputs and verifies the result.
*
* Parameters mirror the target function signature plus one trailing expected-value parameter:
* temp1, temp2 → inputs forwarded to icyHot()
* expectedReturn → the value icyHot() must return for this input
*
* Prints a diagnostic line and increments testCaseErrors when actual != expected or exception caught from target.
*/
private void testIcyHot(int temp1, int temp2, boolean expectedReturn) {
boolean actualReturn = false;
testCaseCount++;
try {
actualReturn = icyHot(temp1, temp2);
} catch (Exception e) {
e.printStackTrace();
testCaseErrors++;
System.err.println("Error " + e + ", expected :" + expectedReturn
+ ", for temp1 :" + temp1 + ", temp2 :" + temp2
+ ", count :" + testCaseCount + "." );
return;
}
if (actualReturn != expectedReturn) {
System.out.println("Actual :" + actualReturn + ", expected :" + expectedReturn
+ ", for temp1 :" + temp1 + ", temp2 :" + temp2
+ ", count :" + testCaseCount + ".");
testCaseErrors++;
}
}
private void icyHotTestCases() {
System.out.println("IcyHot Test cases, run at " + new java.util.Date());
// Both temps in normal range - neither condition met
//testIcyHot(0, 0, false);
System.out.println("IcyHot test cases count " + testCaseCount
+ ", Errors (test case expected value wrong or implementation wrong"
+ " or problem understanding wrong):" + testCaseErrors + ".");
}
/**
* Target function - DO NOT change this signature or implementation.
*
* Returns true if temp1 is below 0 AND temp2 is above 100.
* Note: this implementation is intentionally incomplete for the sample. To demo test case failure. It does not
* handle the symmetric case (temp1 > 100 && temp2 < 0).
*/
public boolean icyHot(int temp1, int temp2) {
//just for testing
//if(temp2 == 22228)throw new RuntimeException("Test exception when time2 = " + temp2);
if (temp1 < 0 && temp2 > 100) {
return true;
}
return false;
// dont change this
}
}
- Log in to post comments