[fix][unittest] Fixed RocketTest (required fix to RocketComponent#getInstanceLocations())
This commit is contained in:
parent
bb756decfc
commit
356ec09094
@ -1175,11 +1175,6 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
*/
|
*/
|
||||||
// @Override Me !
|
// @Override Me !
|
||||||
public Coordinate[] getInstanceLocations(){
|
public Coordinate[] getInstanceLocations(){
|
||||||
int instanceCount = getInstanceCount();
|
|
||||||
if( 0 == instanceCount ){
|
|
||||||
return new Coordinate[]{this.position};
|
|
||||||
}
|
|
||||||
|
|
||||||
checkState();
|
checkState();
|
||||||
|
|
||||||
Coordinate center = this.position;
|
Coordinate center = this.position;
|
||||||
|
@ -62,86 +62,80 @@ public class RocketTest extends BaseTestCase {
|
|||||||
|
|
||||||
AxialStage stage= (AxialStage)rocket.getChild(0);
|
AxialStage stage= (AxialStage)rocket.getChild(0);
|
||||||
|
|
||||||
NoseCone nose = (NoseCone)stage.getChild(0);
|
|
||||||
BodyTube body = (BodyTube)stage.getChild(1);
|
|
||||||
FinSet fins = (FinSet)body.getChild(0);
|
|
||||||
LaunchLug lug = (LaunchLug)body.getChild(1);
|
|
||||||
InnerTube mmt = (InnerTube)body.getChild(2);
|
|
||||||
EngineBlock block = (EngineBlock)mmt.getChild(0);
|
|
||||||
Parachute chute = (Parachute)body.getChild(3);
|
|
||||||
CenteringRing center = (CenteringRing)body.getChild(4);
|
|
||||||
|
|
||||||
|
|
||||||
RocketComponent cc;
|
|
||||||
Coordinate expLoc;
|
Coordinate expLoc;
|
||||||
Coordinate actLoc;
|
Coordinate actLoc;
|
||||||
{
|
{
|
||||||
cc = nose;
|
NoseCone nose = (NoseCone)stage.getChild(0);
|
||||||
expLoc = new Coordinate(0,0,0);
|
expLoc = new Coordinate(0,0,0);
|
||||||
actLoc = cc.getLocations()[0];
|
actLoc = nose.getComponentLocations()[0];
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
assertThat(nose.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
||||||
|
|
||||||
cc = body;
|
BodyTube body = (BodyTube)stage.getChild(1);
|
||||||
expLoc = new Coordinate(0.07,0,0);
|
expLoc = new Coordinate(0.07,0,0);
|
||||||
actLoc = cc.getLocations()[0];
|
actLoc = body.getComponentLocations()[0];
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
assertThat(body.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
||||||
|
|
||||||
{
|
{
|
||||||
cc = fins;
|
FinSet fins = (FinSet)body.getChild(0);
|
||||||
expLoc = new Coordinate(0.22,0,0);
|
Coordinate actLocs[] = fins.getComponentLocations();
|
||||||
actLoc = cc.getLocations()[0];
|
assertThat(fins.getName()+" have incorrect count: ", fins.getInstanceCount(), equalTo(3));
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
{ // fin #1
|
||||||
|
expLoc = new Coordinate(0.22,0.012,0);
|
||||||
cc = lug;
|
assertThat(fins.getName()+" not positioned correctly: ", actLocs[0], equalTo(expLoc));
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchLug lugs = (LaunchLug)body.getChild(1);
|
||||||
expLoc = new Coordinate(0.181, 0.015, 0);
|
expLoc = new Coordinate(0.181, 0.015, 0);
|
||||||
actLoc = cc.getLocations()[0];
|
assertThat(lugs.getName()+" have incorrect count: ", lugs.getInstanceCount(), equalTo(1));
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
actLocs = lugs.getComponentLocations();
|
||||||
|
{ // singular instance:
|
||||||
cc = mmt;
|
assertThat(lugs.getName()+" not positioned correctly: ", actLocs[0], equalTo(expLoc));
|
||||||
|
}
|
||||||
|
|
||||||
|
InnerTube mmt = (InnerTube)body.getChild(2);
|
||||||
expLoc = new Coordinate(0.203,0,0);
|
expLoc = new Coordinate(0.203,0,0);
|
||||||
actLoc = cc.getLocations()[0];
|
actLoc = mmt.getComponentLocations()[0];
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
assertThat(mmt.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
||||||
{
|
{
|
||||||
cc = block;
|
EngineBlock block = (EngineBlock)mmt.getChild(0);
|
||||||
expLoc = new Coordinate(0.203,0,0);
|
expLoc = new Coordinate(0.203,0,0);
|
||||||
actLoc = cc.getLocations()[0];
|
actLoc = block.getComponentLocations()[0];
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
assertThat(block.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cc = chute;
|
Parachute chute = (Parachute)body.getChild(3);
|
||||||
expLoc = new Coordinate(0.098,0,0);
|
expLoc = new Coordinate(0.098,0,0);
|
||||||
actLoc = cc.getLocations()[0];
|
actLoc = chute.getComponentLocations()[0];
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
assertThat(chute.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
||||||
|
|
||||||
cc = center;
|
CenteringRing ring = (CenteringRing)body.getChild(4);
|
||||||
assertThat(cc.getName()+" not instanced correctly: ", cc.getInstanceCount(), equalTo(2));
|
assertThat(ring.getName()+" not instanced correctly: ", ring.getInstanceCount(), equalTo(2));
|
||||||
// singleton instances follow different code paths
|
// singleton instances follow different code paths
|
||||||
center.setInstanceCount(1);
|
ring.setInstanceCount(1);
|
||||||
expLoc = new Coordinate(0.21,0,0);
|
expLoc = new Coordinate(0.21,0,0);
|
||||||
actLoc = cc.getLocations()[0];
|
actLoc = ring.getComponentLocations()[0];
|
||||||
assertEquals(" position x fail: ", expLoc.x, actLoc.x, EPSILON);
|
assertEquals(" position x fail: ", expLoc.x, actLoc.x, EPSILON);
|
||||||
assertEquals(" position y fail: ", expLoc.y, actLoc.y, EPSILON);
|
assertEquals(" position y fail: ", expLoc.y, actLoc.y, EPSILON);
|
||||||
assertEquals(" position z fail: ", expLoc.z, actLoc.z, EPSILON);
|
assertEquals(" position z fail: ", expLoc.z, actLoc.z, EPSILON);
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
assertThat(ring.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
||||||
|
|
||||||
cc = center;
|
ring.setInstanceCount(2);
|
||||||
center.setInstanceCount(2);
|
Coordinate actLocs[] = ring.getComponentLocations();
|
||||||
Coordinate actLocs[] = cc.getLocations();
|
|
||||||
{ // first instance
|
{ // first instance
|
||||||
// assertEquals(" position x fail: ", expLoc.x, actLoc.x, EPSILON);
|
// assertEquals(" position x fail: ", expLoc.x, actLoc.x, EPSILON);
|
||||||
// assertEquals(" position y fail: ", expLoc.y, actLoc.y, EPSILON);
|
// assertEquals(" position y fail: ", expLoc.y, actLoc.y, EPSILON);
|
||||||
// assertEquals(" position z fail: ", expLoc.z, actLoc.z, EPSILON);
|
// assertEquals(" position z fail: ", expLoc.z, actLoc.z, EPSILON);
|
||||||
expLoc = new Coordinate(0.21, 0, 0);
|
expLoc = new Coordinate(0.21, 0, 0);
|
||||||
actLoc = actLocs[0];
|
actLoc = actLocs[0];
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
assertThat(ring.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
||||||
}
|
}
|
||||||
{ // second instance
|
{ // second instance
|
||||||
assertThat(cc.getName()+" not instanced correctly: ", cc.getInstanceCount(), equalTo(2));
|
assertThat(ring.getName()+" not instanced correctly: ", ring.getInstanceCount(), equalTo(2));
|
||||||
expLoc = new Coordinate(0.245, 0, 0);
|
expLoc = new Coordinate(0.245, 0, 0);
|
||||||
actLoc = actLocs[1];
|
actLoc = actLocs[1];
|
||||||
assertThat(cc.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
assertThat(ring.getName()+" not positioned correctly: ", actLoc, equalTo(expLoc));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user