Icy Hot

Links below in comments
https://ideone.com/9fokSG

Comments

public class IcyHot {
 
    //count of test cases
    private int count;
    // test cases which has an error. Either due to bad expected data or wrong or incomplete implemnetation of target function
    private int errs;
 
    public static void main(String[] args) {
 
        IcyHot app = new IcyHot();
        app.icyHotTestCases();
 
    }
 
    /**
     * Target function, this function is the main function to implement. The signature should be same as
     * in your question.
     * Following is simple question, real one will be a little more complex.
     * Remember :
     * copy this template but rename all functions and change parameters per your problem.
     * <p>
     * Question:
     * Given two temperatures, return true if one is less than 0 and the other is greater than 100.
     * <p>
     * icyHot(120, -1) -> true
     * icyHot(-1, 120) -> true
     * icyHot(2, 120) -> false
     * <p>
     */
    public boolean icyHot(int temperature1, int temperature2) {
        return temperature1 < 0;//sample answer, incomplete
    }
 
 
    /**
     * Test helper. This function calls target and checks response - if matches expected.
     * <p>
     * Same parameters as target plus the return type - expected value.
     * expected value has to be accurately calculated by developer.
     * Type and number of parameters can change depending on your question.
     */
    void testIcyHot(int temperature1, int temperature2, boolean expected) {
        boolean actual = false;
        count++;
        try {
            actual = icyHot(temperature1, temperature2);
        } catch (Throwable e) {
            e.printStackTrace();// log it
            System.err.println("Error " + e);
        }
 
        if (actual != expected) {
            System.out.println("Actual :" + actual + ", expected :" + expected + ", for temperature1 :" + temperature1 + ", temperature2 :" + temperature2
                    + ", count :" + count + ".");
            errs++;
        }
    }
 
    /**
     * Different test cases - more the better to adequately test the target function for all
     * requirements per the question.
     * Number of test cases depends on question and number & type of parameters in target.
      * Target should be to have 0 errors. Print the number of test cases and error count as done here
     * In final submisison comment out debugging System.out.println statements only keep the same ones as in this sample - one in test helper and two in test cases
     */
    private void icyHotTestCases() {
        System.out.println("IcyHot test cases run at " + new java.util.Date() );
        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("Icy Hot test cases count " + count + ", Errors :" + errs + ".");
    }
 
}

 

github.com/tgkprog/academic/blob/main/IcyHot.java

/*
Given a string, return true if the number of appearances of "that" anywhere in the string is equal to the number of
appearances of "this" anywhere in the string (case in-sensitive).

sameThatThis("That That This") -> false
sameThatThis("This is not That") -> true
sameThatThis("thisnoisthatxxnotbthatyynotxisi that this forthis") -> true
*/

public boolean sameThatThis(String str) {
//your target function, don't change signature, add to a new class file
}

// IMPORTANT : Follow TDD test driven development
//first do the test helper and write at least 6 different test cases and last implement your target function

}

/*
Add main method ->
testCases (think of edge test cases besides the 3 I have given) ->
test Helper functions, then implement above target function all same class , as in IcyHot

Unit test with tests and test helper in same class. Follow same pattern and order.
*/
/*
First add test cases, then test helper and last try to solve the target function (and its helper)
Copy this to a new Class with appropriate name.
Can copy parts of IcyHot to new class or type everything.

Create a new class, sample and instructions: (IcyHot)

So you will have a new class with 5 methods (including the helper). Please make sure icyHot comments or function names are not there, rename everything to match this question.

Don't use regex. Do use loops and your own logic.
*/

https://sel2in.com/news/code/icyHot
is a sample code of a core java problem solving
i have solved it partly
you dont need to solve it

We have a target method, but we solve this last.

Has test cases, that is in one method that repeatedly calls a test helper

Go thru the test helper, see how its constructed from the target method - the relationship of parameters in the test helper vs the parameters in the target method.

The comments try to explain them. Please read the comments two times slowly.