I need to build Junit test cases for the following code and I am trying to have one of the tests test that the assert s1 != null : "Violation of: s1 is not null";
, assert s2 != null : "Violation of: s2 is not null";
, and assert s1.length() >= 1 : "|s1| >= 1";
statements gives an error when a null sequence is passed or when s1
's length is >= 1.
I don't know the exact way of going about doing this.
A couple forums suggested using "Try Catch" but I don't know exactly how that works.
Any help would be appreciated!
public static void itersmooth(Sequence<Integer> s1, Sequence<Integer>
s2){
assert s1 != null : "Violation of: s1 is not null";
assert s2 != null : "Violation of: s2 is not null";
assert s1.length() >= 1 : "|s1| >= 1";
s2.clear();
if (s1.length() > 1){
int inp1 = 1;
for (int inp2 = 0; inp2 < (s1.length() - 1); inp2++){
int valone = s1.remove(inp2);
int valtwo = s1.remove(inp1 - 1);
int valoneT = valone / 2;
int valtwoT = valtwo / 2;
int valtemp = valoneT + valtwoT;
if ((valone % 2 != 0 || valtwo % 2 != 0) && (valone > 0 && valtwo > 0)) {
valtemp++;
}
if ((valone % 2 != 0 || valtwo % 2 != 0) && (valone < 0 && valtwo < 0)){
valtemp--;
}
s2.add(inp2, valtemp);
s1.add(inp2, valone);
s1.add(inp1, valtwo);
inp1++;
}
}
}