fork(1) download
  1. class IcyHot {
  2.  
  3. //count of test cases
  4. private int count;
  5. // test cases which has an error. Either due to bad expected data or wrong or incomplete implemnetation of target function
  6. private int errs;
  7.  
  8. public static void main(String[] args) {
  9.  
  10. IcyHot app = new IcyHot();
  11. app.icyHotTestCases();
  12.  
  13. }
  14.  
  15. /**
  16.   * Target function, this function is the main function to implement. The signature should be same as
  17.   * in your question.
  18.   * Following is simple question, real one will be a little more complex.
  19.   * Remember :
  20.   * copy this template but rename all functions and change parameters per your problem.
  21.   * <p>
  22.   * Question:
  23.   * Given two temperatures, return true if one is less than 0 and the other is greater than 100.
  24.   * <p>
  25.   * icyHot(120, -1) -> true
  26.   * icyHot(-1, 120) -> true
  27.   * icyHot(2, 120) -> false
  28.   * <p>
  29.   */
  30. public boolean icyHot(int temperature1, int temperature2) {
  31. return temperature1 < 0;//sample answer, incomplete
  32. }
  33.  
  34.  
  35. /**
  36.   * Test helper. This function calls target and checks response - if matches expected.
  37.   * <p>
  38.   * Same parameters as target plus the return type - expected value.
  39.   * expected value has to be accurately calculated by developer.
  40.   * Type and number of parameters can change depending on your question.
  41.   */
  42. void testIcyHot(int temperature1, int temperature2, boolean expected) {
  43. boolean actual = false;
  44. count++;
  45. try {
  46. actual = icyHot(temperature1, temperature2);
  47. if (actual != expected) {
  48. System.out.println("Actual :" + actual + ", expected :" + expected + ", for temperature1 :" + temperature1 + ", temperature2 :" + temperature2
  49. + ", count :" + count + ".");
  50. errs++;
  51. }
  52. } catch (Throwable e) {
  53. errs++;
  54. e.printStackTrace();// log it
  55. System.err.println("Error " + e);
  56. }
  57.  
  58.  
  59. }
  60.  
  61. /**
  62.   * Different test cases - more the better to adequately test the target function for all
  63.   * requirements per the question.
  64.   * Number of test cases depends on question and number & type of parameters in target.
  65.   */
  66. private void icyHotTestCases() {
  67. System.out.println("IcyHot test cases run at " + new java.util.Date() );
  68. testIcyHot(0, 0, false);
  69. testIcyHot(0, 101, false);
  70. testIcyHot(-1, 101, true);
  71. testIcyHot(500, -101, true);
  72. testIcyHot(0, 101, false);
  73. testIcyHot(-100, 1999, true);
  74. System.out.println("Icy Hot test cases count " + count + ", Errors :" + errs + ".");
  75. }
  76.  
  77. }
Success #stdin #stdout 0.23s 59792KB
stdin
Standard input is empty
stdout
IcyHot test cases run at Wed Aug 21 22:18:53 GMT 2024
Actual :false, expected :true, for temperature1 :500, temperature2 :-101, count :4.
Icy Hot test cases count 6, Errors :1.