1 package net.sf.openrocket.motor;
3 import static org.junit.Assert.assertEquals;
4 import net.sf.openrocket.util.Coordinate;
5 import net.sf.openrocket.util.Inertia;
9 public class ThrustCurveMotorTest {
11 private final double EPS = 0.000001;
13 private final double radius = 0.025;
14 private final double length = 0.10;
15 private final double longitudinal = Inertia.filledCylinderLongitudinal(radius, length);
16 private final double rotational = Inertia.filledCylinderRotational(radius);
18 private final ThrustCurveMotor motor =
19 new ThrustCurveMotor(Manufacturer.getManufacturer("foo"),
20 "X6", "Description of X6", Motor.Type.RELOAD,
21 new double[] {0, 2, Motor.PLUGGED}, radius*2, length,
22 new double[] {0, 1, 3, 4}, // time
23 new double[] {0, 2, 3, 0}, // thrust
25 new Coordinate(0.02,0,0,0.05),
26 new Coordinate(0.02,0,0,0.05),
27 new Coordinate(0.02,0,0,0.05),
28 new Coordinate(0.03,0,0,0.03)
32 public void testMotorData() {
34 assertEquals("X6", motor.getDesignation());
35 assertEquals("X6-5", motor.getDesignation(5.0));
36 assertEquals("Description of X6", motor.getDescription());
37 assertEquals(Motor.Type.RELOAD, motor.getMotorType());
42 public void testInstance() {
43 MotorInstance instance = motor.getInstance();
45 verify(instance, 0, 0.05, 0.02);
46 instance.step(0.0, 0, null);
47 verify(instance, 0, 0.05, 0.02);
48 instance.step(0.5, 0, null);
49 verify(instance, 0.5, 0.05, 0.02);
50 instance.step(1.5, 0, null);
51 verify(instance, (1.5 + 2.125)/2, 0.05, 0.02);
52 instance.step(2.5, 0, null);
53 verify(instance, (2.125 + 2.875)/2, 0.05, 0.02);
54 instance.step(3.0, 0, null);
55 verify(instance, (2+3.0/4 + 3)/2, 0.05, 0.02);
56 instance.step(3.5, 0, null);
57 verify(instance, (1.5 + 3)/2, 0.045, 0.0225);
58 instance.step(4.5, 0, null);
59 // mass and cg is simply average of the end points
60 verify(instance, 1.5/4, 0.035, 0.0275);
61 instance.step(5.0, 0, null);
62 verify(instance, 0, 0.03, 0.03);
65 private void verify(MotorInstance instance, double thrust, double mass, double cgx) {
66 assertEquals("Testing thrust", thrust, instance.getThrust(), EPS);
67 assertEquals("Testing mass", mass, instance.getCG().weight, EPS);
68 assertEquals("Testing cg x", cgx, instance.getCG().x, EPS);
69 assertEquals("Testing longitudinal inertia", mass*longitudinal, instance.getLongitudinalInertia(), EPS);
70 assertEquals("Testing rotational inertia", mass*rotational, instance.getRotationalInertia(), EPS);