For practicing algorithm questions, I set up my Java code like: ProblemClass.java
public static void main(String[] args) {
Solution solution = new ProblemClass().new Solution();
Utils.isEqual(solution.function("abc"), "def");
}
public class {
public Solution {
public String function(String s) {}
}
}
The Utils.isEqual is basically wrapping a comparison like:
public static void isEqual(Object actual, Object expected) {
if (actual == null && expected == null || actual.equals(expected)) {
System.out.println("Pass.");
} else {
System.out.println("Fail. Expecting: [" + expected + "] Actual result: [" + actual + "]");
}
}
When I run hundred of test cases, all I see on the command prompt is:
Pass.
Pass.
Pass.
Pass.
...
Fail. Expecting: [false] Actual result: [true]
...
I don't know what test case has failed. I want to have some indication of what test has failed. I am open to other suggestions. So far, I thought maybe there is a way to display the parameters passed into function
when calling isEqual
through something like Reflection. I could not find a clear answer on that.
Lastly, I want to keep everything in the main() so all my tests and code is in one place as opposed to have a unit test class that I have to manage.