Icy Hot Review

 
package  com.ms.shares.sell.ai;
 
 
/**
 *
 * Made a class with a main method, the target method , test helper and test cases function
 
 *
 
 *
 * I have not used J Unit style, but single class with solution and unit test cases with main method.
 *
 * Main method calls Test cases function
 *
 * Test cases function calls test helper function repeatedly with different test data and expected value
 *
 * test helper calls target function and compares actual return with expected
 *
 * Target function and, unit test cases and test helper
 *  
 *
 */
public class IcyHot {
 
public static void main(String[] args) {
IcyHot app = new IcyHot();
app.icyHotTestCases();
}
 
private int count;
private int errs;
 
/**
* Test helper. This function calls target and checks response - if matches expected.
*
* Same parameters as target function. Plus the last parameter is the return type of the target function (expected valueo of that test case).
 
* Expected value has been accurately calculated by me.
*/
void testIcyHot(int temp1, int temp2, boolean expectedReturn) {
boolean actualReturn = false;
count++;
try {
actualReturn = icyHot(temp1, temp2);
} catch (Throwable e) {
e.printStackTrace();// log it
System.err.println("Error " + e);
}
 
if (actualReturn != expectedReturn) {
System.out.println("Actual :" + actualReturn + ", expected :" + expectedReturn + ", for temp1 :" + temp1 + ", temp2 :" + temp2
+ ", count :" + count + ".");
errs++;
}
}
 
/**
* Different test cases. To adequately test the target function for all
* requirements per the question.
* Few edge cases done.
 
*/
private void icyHotTestCases() {
/*
* besides date here,
* only use Java map if told too, most problems only Java lang package classes
*/
System.out.println("IcyHot Test cases, run at " + new java.util.Date());// copy to your test cases and change text IcyHot ...
 
testIcyHot(0, 0, false);
testIcyHot(0, 101, false);
testIcyHot(-1, 101, true);
testIcyHot(500, -101, true);
testIcyHot(0, 101, false);
testIcyHot(-100, 1999, true);
System.out.println("IcyHot test cases count " + count
+ ", Errors (test case expected value wrong or implmentaion wrong or problem understanding wrong):" + errs + ".");
}
 
/**
* Target function, this function is the problem function to implement. 
*
*
* Given two temperatures, return true if one is less than 0 and the other is greater than 100.
*
* icyHot(120, -1) : true
* icyHot(-1, 120) : true
* icyHot(2, 120) : false
*
*
*/
public boolean icyHot(int temp1, int temp2) {
if (temp1 < 0 && temp2 > 100 || (temp1 > 100 && temp2 < 0)) {
return true;
}
return false;
}
 
}