Add unit tests for flight configuration copy/clone
This commit is contained in:
parent
e994dc7230
commit
4a0a1255b8
@ -165,4 +165,11 @@ public class BoundingBox {
|
|||||||
min.x, min.y, min.z,
|
min.x, min.y, min.z,
|
||||||
max.x, max.y, max.z );
|
max.x, max.y, max.z );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return other instanceof BoundingBox &&
|
||||||
|
((BoundingBox) other).min.equals(this.min) &&
|
||||||
|
((BoundingBox) other).max.equals(this.max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,19 @@ package net.sf.openrocket.rocketcomponent;
|
|||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
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 java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.openrocket.util.BoundingBox;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.sf.openrocket.util.Coordinate;
|
import net.sf.openrocket.util.Coordinate;
|
||||||
@ -572,6 +579,134 @@ public class FlightConfigurationTest extends BaseTestCase {
|
|||||||
assertThat(components.get(1).getName(), equalTo("Core Stage Body"));
|
assertThat(components.get(1).getName(), equalTo("Core Stage Body"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCopy() throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||||
|
FlightConfiguration original = rocket.getSelectedConfiguration();
|
||||||
|
original.setOnlyStage(0);
|
||||||
|
|
||||||
|
// vvvv Test Target vvvv
|
||||||
|
FlightConfiguration copy = original.copy(null);
|
||||||
|
// ^^^^ Test Target ^^^^
|
||||||
|
|
||||||
|
assertNotEquals(original, copy);
|
||||||
|
assertNotSame(original, copy);
|
||||||
|
assertEquals(original.getName(), copy.getName());
|
||||||
|
assertNotEquals(original.getFlightConfigurationID(), copy.getFlightConfigurationID());
|
||||||
|
|
||||||
|
// Test preloadStageActiveness copy
|
||||||
|
Field preloadStageActivenessField = FlightConfiguration.class.getDeclaredField("preloadStageActiveness");
|
||||||
|
preloadStageActivenessField.setAccessible(true);
|
||||||
|
Map<Integer, Boolean> preloadStageActivenessOriginal = (Map<Integer, Boolean>) preloadStageActivenessField.get(original);
|
||||||
|
Map<Integer, Boolean> preloadStageActivenessCopy = (Map<Integer, Boolean>) preloadStageActivenessField.get(copy);
|
||||||
|
assertEquals(preloadStageActivenessOriginal, preloadStageActivenessCopy);
|
||||||
|
if (preloadStageActivenessOriginal == null) {
|
||||||
|
assertNull(preloadStageActivenessCopy);
|
||||||
|
} else {
|
||||||
|
assertNotSame(preloadStageActivenessOriginal, preloadStageActivenessCopy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test cachedBoundsAerodynamic copy
|
||||||
|
Field cachedBoundsAerodynamicField = FlightConfiguration.class.getDeclaredField("cachedBoundsAerodynamic");
|
||||||
|
cachedBoundsAerodynamicField.setAccessible(true);
|
||||||
|
BoundingBox cachedBoundsAerodynamicOriginal = (BoundingBox) cachedBoundsAerodynamicField.get(original);
|
||||||
|
BoundingBox cachedBoundsAerodynamicCopy = (BoundingBox) cachedBoundsAerodynamicField.get(copy);
|
||||||
|
assertEquals(cachedBoundsAerodynamicOriginal, cachedBoundsAerodynamicCopy);
|
||||||
|
assertNotSame(cachedBoundsAerodynamicOriginal, cachedBoundsAerodynamicCopy);
|
||||||
|
|
||||||
|
// Test cachedBounds copy
|
||||||
|
Field cachedBoundsField = FlightConfiguration.class.getDeclaredField("cachedBounds");
|
||||||
|
cachedBoundsField.setAccessible(true);
|
||||||
|
BoundingBox cachedBoundsOriginal = (BoundingBox) cachedBoundsField.get(original);
|
||||||
|
BoundingBox cachedBoundsCopy = (BoundingBox) cachedBoundsField.get(copy);
|
||||||
|
assertEquals(cachedBoundsOriginal, cachedBoundsCopy);
|
||||||
|
assertNotSame(cachedBoundsOriginal, cachedBoundsCopy);
|
||||||
|
|
||||||
|
// Test modID copy
|
||||||
|
assertEquals(original.getModID(), copy.getModID());
|
||||||
|
|
||||||
|
// Test boundModID
|
||||||
|
Field boundsModIDField = FlightConfiguration.class.getDeclaredField("boundsModID");
|
||||||
|
boundsModIDField.setAccessible(true);
|
||||||
|
int boundsModIDCopy = (int) boundsModIDField.get(copy);
|
||||||
|
assertEquals(-1, boundsModIDCopy);
|
||||||
|
|
||||||
|
// Test refLengthModID
|
||||||
|
Field refLengthModIDField = FlightConfiguration.class.getDeclaredField("refLengthModID");
|
||||||
|
refLengthModIDField.setAccessible(true);
|
||||||
|
int refLengthModIDCopy = (int) refLengthModIDField.get(copy);
|
||||||
|
assertEquals(-1, refLengthModIDCopy);
|
||||||
|
|
||||||
|
// Test stageActiveness copy
|
||||||
|
for (int i = 0; i < original.getStageCount(); i++) {
|
||||||
|
assertEquals(original.isStageActive(i), copy.isStageActive(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClone() throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||||
|
FlightConfiguration original = rocket.getSelectedConfiguration();
|
||||||
|
original.setOnlyStage(0);
|
||||||
|
|
||||||
|
// vvvv Test Target vvvv
|
||||||
|
FlightConfiguration clone = original.clone();
|
||||||
|
// ^^^^ Test Target ^^^^
|
||||||
|
|
||||||
|
assertEquals(original, clone);
|
||||||
|
assertNotSame(original, clone);
|
||||||
|
assertEquals(original.getName(), clone.getName());
|
||||||
|
assertEquals(original.getFlightConfigurationID(), clone.getFlightConfigurationID());
|
||||||
|
|
||||||
|
// Test preloadStageActiveness clone
|
||||||
|
Field preloadStageActivenessField = FlightConfiguration.class.getDeclaredField("preloadStageActiveness");
|
||||||
|
preloadStageActivenessField.setAccessible(true);
|
||||||
|
Map<Integer, Boolean> preloadStageActivenessOriginal = (Map<Integer, Boolean>) preloadStageActivenessField.get(original);
|
||||||
|
Map<Integer, Boolean> preloadStageActivenessClone = (Map<Integer, Boolean>) preloadStageActivenessField.get(clone);
|
||||||
|
assertEquals(preloadStageActivenessOriginal, preloadStageActivenessClone);
|
||||||
|
if (preloadStageActivenessOriginal == null) {
|
||||||
|
assertNull(preloadStageActivenessClone);
|
||||||
|
} else {
|
||||||
|
assertNotSame(preloadStageActivenessOriginal, preloadStageActivenessClone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test cachedBoundsAerodynamic clone
|
||||||
|
Field cachedBoundsAerodynamicField = FlightConfiguration.class.getDeclaredField("cachedBoundsAerodynamic");
|
||||||
|
cachedBoundsAerodynamicField.setAccessible(true);
|
||||||
|
BoundingBox cachedBoundsAerodynamicOriginal = (BoundingBox) cachedBoundsAerodynamicField.get(original);
|
||||||
|
BoundingBox cachedBoundsAerodynamicClone = (BoundingBox) cachedBoundsAerodynamicField.get(clone);
|
||||||
|
assertEquals(cachedBoundsAerodynamicOriginal, cachedBoundsAerodynamicClone);
|
||||||
|
assertNotSame(cachedBoundsAerodynamicOriginal, cachedBoundsAerodynamicClone);
|
||||||
|
|
||||||
|
// Test cachedBounds clone
|
||||||
|
Field cachedBoundsField = FlightConfiguration.class.getDeclaredField("cachedBounds");
|
||||||
|
cachedBoundsField.setAccessible(true);
|
||||||
|
BoundingBox cachedBoundsOriginal = (BoundingBox) cachedBoundsField.get(original);
|
||||||
|
BoundingBox cachedBoundsClone = (BoundingBox) cachedBoundsField.get(clone);
|
||||||
|
assertEquals(cachedBoundsOriginal, cachedBoundsClone);
|
||||||
|
assertNotSame(cachedBoundsOriginal, cachedBoundsClone);
|
||||||
|
|
||||||
|
// Test modID clone
|
||||||
|
assertEquals(original.getModID(), clone.getModID());
|
||||||
|
|
||||||
|
// Test boundModID
|
||||||
|
Field boundsModIDField = FlightConfiguration.class.getDeclaredField("boundsModID");
|
||||||
|
boundsModIDField.setAccessible(true);
|
||||||
|
int boundsModIDClone = (int) boundsModIDField.get(clone);
|
||||||
|
assertEquals(-1, boundsModIDClone);
|
||||||
|
|
||||||
|
// Test refLengthModID
|
||||||
|
Field refLengthModIDField = FlightConfiguration.class.getDeclaredField("refLengthModID");
|
||||||
|
refLengthModIDField.setAccessible(true);
|
||||||
|
int refLengthModIDClone = (int) refLengthModIDField.get(clone);
|
||||||
|
assertEquals(-1, refLengthModIDClone);
|
||||||
|
|
||||||
|
// Test stageActiveness copy
|
||||||
|
for (int i = 0; i < original.getStageCount(); i++) {
|
||||||
|
assertEquals(original.isStageActive(i), clone.isStageActive(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user