For double comparions, hansel creates strange
conditions. For example,
if (x == 0) ...
where x is a double, creates the output
Coverage failure: Branch not completely covered.
Condition '!(x < 0.0 != 0)' is not fulfilled.
at org.hanseltest.TestDoubleClass.comparisons
(TestDoubleClass.java:40)
The reason is that the dcmpl and dcmpg instructions
work by themselves pushing 0, -1, or 1 on the stack,
which is then checked by an if, e.g.
0 dload_1
1 dconst_0
2 dcmpl
3 ifne 17
Here is a test which tests some more cases:
-------------
package org.hanseltest;
import junit.framework.TestCase;
import junit.framework.Test;
import org.hansel.CoverageDecorator;
/**
* Strange conditions for double comparisons
* @author HMMueller
*/
public class TestDouble extends TestCase {
/**
* Create a new Test.
* @param name Name of the test.
*/
public TestDouble(String name) {
super(name);
}
/** Cover the class. */
public void testSomething() {
new TestDoubleClass().comparisons(3);
}
/**
* Returns the coverage test suite.
* @return Test suite.
*/
public static Test suite() {
return new CoverageDecorator(TestDouble.class,
new Class[] {
TestDoubleClass.class });
}
}
class TestDoubleClass {
int comparisons(double x) {
double y = -x;
if (x == 0) {
return 15;
} else if (x < 0) {
return 16;
} else if (x <= 0) {
return 17;
} else if (x <= 2) {
return 18;
} else if (x <= -3) {
return 19;
} else if (x == -3) {
return 20;
} else if (y > 0) {
return 21;
} else if (y >= 0) {
return 22;
} else if (y >= -2) {
return 23;
} else {
return 99;
}
}
}
-------------
Regards
HMMueller
Logged In: YES
user_id=484627
... oops: Of course, this is not a *test*, but just the first
part of it - no asserts there. Niklas - can you add the asserts
(you know what you want the output to be!)