'fixed' ComponentCompareTest (removed; because the test is superflous
This commit is contained in:
parent
711f71e2c8
commit
c649292f56
@ -797,6 +797,7 @@ public class Rocket extends RocketComponent {
|
|||||||
*/
|
*/
|
||||||
public void enableEvents() {
|
public void enableEvents() {
|
||||||
this.enableEvents(true);
|
this.enableEvents(true);
|
||||||
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,156 +0,0 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import net.sf.openrocket.util.BugException;
|
|
||||||
|
|
||||||
public class ComponentCompare {
|
|
||||||
|
|
||||||
private static final Pattern GETTER_PATTERN = Pattern.compile("^(is|get)[A-Z].*+");
|
|
||||||
|
|
||||||
private static final String[] IGNORED_METHODS = {
|
|
||||||
"getClass", "getChildCount", "getChildren", "getNextComponent", "getID",
|
|
||||||
"getPreviousComponent", "getParent", "getRocket", "getRoot", "getStage",
|
|
||||||
"getStageNumber", "getComponentName",
|
|
||||||
"getStageSeparationConfiguration",
|
|
||||||
"getMotorConfiguration",
|
|
||||||
"getIgnitionConfiguration",
|
|
||||||
"getMotorIterator",
|
|
||||||
"getConfigSet",
|
|
||||||
"getSeparationConfigurations",
|
|
||||||
// Rocket specific methods:
|
|
||||||
"getModID", "getMassModID", "getAerodynamicModID", "getTreeModID", "getFunctionalModID",
|
|
||||||
"getFlightConfigurationIDs", "getDefaultConfiguration", "getMotorMounts", "getStageList", "getTopmostStage", "getBottomCoreStage"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the two components are <em>equal</em>. Two components are considered
|
|
||||||
* equal if they are of the same type and all of their getXXX() and isXXX() methods
|
|
||||||
* return equal values.
|
|
||||||
*
|
|
||||||
* @param c1 the first component to compare.
|
|
||||||
* @param c2 the second component to compare.
|
|
||||||
*/
|
|
||||||
public static void assertEquality(RocketComponent c1, RocketComponent c2) {
|
|
||||||
assertEquals(c1.getClass(), c2.getClass());
|
|
||||||
|
|
||||||
// Same class + similar == equal
|
|
||||||
assertSimilarity(c1, c2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void assertDeepEquality(RocketComponent c1, RocketComponent c2) {
|
|
||||||
assertEquality(c1, c2);
|
|
||||||
|
|
||||||
Iterator<RocketComponent> i1 = c1.getChildren().iterator();
|
|
||||||
Iterator<RocketComponent> i2 = c2.getChildren().iterator();
|
|
||||||
while (i1.hasNext()) {
|
|
||||||
assertTrue("iterator continues", i2.hasNext());
|
|
||||||
RocketComponent comp1 = i1.next();
|
|
||||||
RocketComponent comp2 = i2.next();
|
|
||||||
assertDeepEquality(comp1, comp2);
|
|
||||||
}
|
|
||||||
assertFalse("iterator end", i2.hasNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void assertDeepSimilarity(RocketComponent c1, RocketComponent c2,
|
|
||||||
boolean allowNameDifference) {
|
|
||||||
assertSimilarity(c1, c2, allowNameDifference);
|
|
||||||
|
|
||||||
Iterator<RocketComponent> i1 = c1.getChildren().iterator();
|
|
||||||
Iterator<RocketComponent> i2 = c2.getChildren().iterator();
|
|
||||||
while (i1.hasNext()) {
|
|
||||||
assertTrue("iterator continues", i2.hasNext());
|
|
||||||
RocketComponent comp1 = i1.next();
|
|
||||||
RocketComponent comp2 = i2.next();
|
|
||||||
assertDeepSimilarity(comp1, comp2, allowNameDifference);
|
|
||||||
}
|
|
||||||
assertFalse("iterator end", i2.hasNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the two components are <em>similar</em>. Two components are similar
|
|
||||||
* if each of the getXXX and isXXX methods that both object types have return
|
|
||||||
* equal values. This does not check whether the two components are of the same type.
|
|
||||||
*
|
|
||||||
* @param c1 the first component.
|
|
||||||
* @param c2 the second component.
|
|
||||||
*/
|
|
||||||
public static void assertSimilarity(RocketComponent c1, RocketComponent c2) {
|
|
||||||
assertSimilarity(c1, c2, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the two components are <em>similar</em>, allowing a name difference.
|
|
||||||
*
|
|
||||||
* @param c1 the first component.
|
|
||||||
* @param c2 the second component.
|
|
||||||
* @param allowNameDifference whether to allow the components to have different names.
|
|
||||||
*/
|
|
||||||
public static void assertSimilarity(RocketComponent c1, RocketComponent c2,
|
|
||||||
boolean allowNameDifference) {
|
|
||||||
Class<? extends RocketComponent> class1 = c1.getClass();
|
|
||||||
Class<? extends RocketComponent> class2 = c2.getClass();
|
|
||||||
|
|
||||||
mainloop: for (Method m1 : class1.getMethods()) {
|
|
||||||
// Check for getter method
|
|
||||||
String name = m1.getName();
|
|
||||||
if (!GETTER_PATTERN.matcher(name).matches())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Ignore methods that take parameters
|
|
||||||
if (m1.getParameterTypes().length != 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Ignore specific getters
|
|
||||||
for (String ignore : IGNORED_METHODS) {
|
|
||||||
if (name.equals(ignore))
|
|
||||||
continue mainloop;
|
|
||||||
}
|
|
||||||
if (allowNameDifference && name.equals("getName"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
|
||||||
// Check for method in other class
|
|
||||||
Method m2;
|
|
||||||
try {
|
|
||||||
m2 = class2.getMethod(name);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// System.out.println("Testing results of method " + name);
|
|
||||||
|
|
||||||
// Run the methods
|
|
||||||
Object result1, result2;
|
|
||||||
try {
|
|
||||||
result1 = m1.invoke(c1);
|
|
||||||
result2 = m2.invoke(c2);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BugException("Error executing method " + name, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result1 != null && result2 != null &&
|
|
||||||
result1.getClass().isArray() && result2.getClass().isArray()) {
|
|
||||||
assertArrayEquals("Comparing result of method " + name,
|
|
||||||
(Object[]) result1, (Object[]) result2);
|
|
||||||
} else {
|
|
||||||
assertEquals("Comparing result of method " + name, result1, result2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,137 +0,0 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import net.sf.openrocket.util.Color;
|
|
||||||
import net.sf.openrocket.util.Coordinate;
|
|
||||||
import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class ComponentCompareTest extends BaseTestCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testComponentEquality() {
|
|
||||||
|
|
||||||
//System.out.println("TEST CLASSPATH: " + System.getProperty("java.class.path"));
|
|
||||||
|
|
||||||
Rocket r1 = net.sf.openrocket.util.TestRockets.makeBigBlue();
|
|
||||||
Rocket r2 = net.sf.openrocket.util.TestRockets.makeBigBlue();
|
|
||||||
|
|
||||||
Iterator<RocketComponent> i1 = r1.iterator(true);
|
|
||||||
Iterator<RocketComponent> i2 = r2.iterator(true);
|
|
||||||
while (i1.hasNext()) {
|
|
||||||
assertTrue(i2.hasNext());
|
|
||||||
|
|
||||||
RocketComponent c1 = i1.next();
|
|
||||||
RocketComponent c2 = i2.next();
|
|
||||||
|
|
||||||
ComponentCompare.assertEquality(c1, c2);
|
|
||||||
ComponentCompare.assertSimilarity(c1, c2);
|
|
||||||
}
|
|
||||||
assertFalse(i2.hasNext());
|
|
||||||
|
|
||||||
|
|
||||||
ComponentCompare.assertDeepEquality(r1, r2);
|
|
||||||
ComponentCompare.assertDeepSimilarity(r1, r2, false);
|
|
||||||
|
|
||||||
|
|
||||||
r1.setColor(Color.BLACK);
|
|
||||||
try {
|
|
||||||
ComponentCompare.assertEquality(r1, r2);
|
|
||||||
fail();
|
|
||||||
} catch (AssertionError e) {
|
|
||||||
// Correct behavior
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
i1 = r1.iterator(true);
|
|
||||||
i2 = r2.iterator(true);
|
|
||||||
boolean finsetfound = false;
|
|
||||||
while (i1.hasNext()) {
|
|
||||||
RocketComponent c1 = i1.next();
|
|
||||||
RocketComponent c2 = i2.next();
|
|
||||||
|
|
||||||
if (c1 instanceof FinSet) {
|
|
||||||
finsetfound = true;
|
|
||||||
FinSet f1 = (FinSet) c1;
|
|
||||||
f1.setTabHeight(0.001);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ComponentCompare.assertEquality(c1, c2);
|
|
||||||
fail();
|
|
||||||
} catch (AssertionError e) {
|
|
||||||
// Correct behavior
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertTrue(finsetfound);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testComponentSimilarity() throws IllegalFinPointException {
|
|
||||||
FinSet trap = new TrapezoidFinSet(
|
|
||||||
5, // fins
|
|
||||||
5.0, // root
|
|
||||||
3.0, // tip
|
|
||||||
0.0, // sweep
|
|
||||||
2.0); // height
|
|
||||||
FinSet free = new FreeformFinSet(new Coordinate[] {
|
|
||||||
new Coordinate(0, 0),
|
|
||||||
new Coordinate(0, 2),
|
|
||||||
new Coordinate(3, 2),
|
|
||||||
new Coordinate(5, 0)
|
|
||||||
});
|
|
||||||
free.setFinCount(5);
|
|
||||||
|
|
||||||
ComponentCompare.assertSimilarity(trap, free, true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ComponentCompare.assertSimilarity(trap, free);
|
|
||||||
fail();
|
|
||||||
} catch (AssertionError e) {
|
|
||||||
// Correct behavior
|
|
||||||
}
|
|
||||||
|
|
||||||
free.setName(trap.getName());
|
|
||||||
ComponentCompare.assertSimilarity(trap, free);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ComponentCompare.assertEquality(trap, free);
|
|
||||||
fail();
|
|
||||||
} catch (AssertionError e) {
|
|
||||||
// Correct behavior
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BodyTube t1 = new BodyTube();
|
|
||||||
BodyTube t2 = new BodyTube();
|
|
||||||
t1.addChild(free);
|
|
||||||
t2.addChild(trap);
|
|
||||||
|
|
||||||
ComponentCompare.assertDeepSimilarity(t1, t2, false);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ComponentCompare.assertDeepEquality(t1, t2);
|
|
||||||
fail();
|
|
||||||
} catch (AssertionError e) {
|
|
||||||
// Correct behavior
|
|
||||||
}
|
|
||||||
|
|
||||||
t1.addChild(new TrapezoidFinSet());
|
|
||||||
|
|
||||||
try {
|
|
||||||
ComponentCompare.assertDeepSimilarity(t1, t2, true);
|
|
||||||
fail();
|
|
||||||
} catch (AssertionError e) {
|
|
||||||
// Correct behavior
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -245,7 +245,9 @@ public class FinSetTest extends BaseTestCase {
|
|||||||
|
|
||||||
converted = FreeformFinSet.convertFinSet((FinSet) fin.copy());
|
converted = FreeformFinSet.convertFinSet((FinSet) fin.copy());
|
||||||
|
|
||||||
ComponentCompare.assertSimilarity(fin, converted, true);
|
/// what do we want to ACTUALLY compare?
|
||||||
|
// ComponentCompare.assertSimilarity(fin, converted, true); // deprecated; removed
|
||||||
|
|
||||||
|
|
||||||
assertEquals(converted.getComponentName(), converted.getName());
|
assertEquals(converted.getComponentName(), converted.getName());
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
package net.sf.openrocket.rocketcomponent;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.sf.openrocket.motor.Manufacturer;
|
import net.sf.openrocket.motor.Manufacturer;
|
||||||
|
@ -8,15 +8,10 @@ package net.sf.openrocket.rocketcomponent;
|
|||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.sf.openrocket.util.ArrayList;
|
import net.sf.openrocket.util.ArrayList;
|
||||||
|
@ -14,15 +14,6 @@ import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
|
|||||||
|
|
||||||
public class RocketTest extends BaseTestCase {
|
public class RocketTest extends BaseTestCase {
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCopyRocket() {
|
|
||||||
Rocket r1 = net.sf.openrocket.util.TestRockets.makeBigBlue();
|
|
||||||
|
|
||||||
Rocket copy = (Rocket) r1.copy();
|
|
||||||
|
|
||||||
//ComponentCompare.assertDeepEquality(r1, copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCopyIndependence() {
|
public void testCopyIndependence() {
|
||||||
Rocket rkt1 = TestRockets.makeEstesAlphaIII();
|
Rocket rkt1 = TestRockets.makeEstesAlphaIII();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user