1 package net.sf.openrocket.database;
3 import static org.junit.Assert.*;
5 import java.util.Arrays;
6 import java.util.Collections;
8 import net.sf.openrocket.motor.Manufacturer;
9 import net.sf.openrocket.motor.Motor;
10 import net.sf.openrocket.motor.ThrustCurveMotor;
11 import net.sf.openrocket.util.Coordinate;
13 import org.junit.Test;
15 public class ThrustCurveMotorSetTest {
18 private static final ThrustCurveMotor motor1 = new ThrustCurveMotor(
19 Manufacturer.getManufacturer("A"),
20 "F12X", "Desc", Motor.Type.UNKNOWN, new double[] { },
21 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 1, 0},
22 new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL});
24 private static final ThrustCurveMotor motor2 = new ThrustCurveMotor(
25 Manufacturer.getManufacturer("A"),
26 "F12H", "Desc", Motor.Type.SINGLE, new double[] { 5 },
27 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 1, 0},
28 new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL});
30 private static final ThrustCurveMotor motor3 = new ThrustCurveMotor(
31 Manufacturer.getManufacturer("A"),
32 "F12", "Desc", Motor.Type.UNKNOWN, new double[] { 0, Motor.PLUGGED },
33 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 2, 0},
34 new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL});
36 private static final ThrustCurveMotor motor4 = new ThrustCurveMotor(
37 Manufacturer.getManufacturer("A"),
38 "F12", "Desc", Motor.Type.HYBRID, new double[] { 0 },
39 0.024, 0.07, new double[] { 0, 1, 2 }, new double[] {0, 2, 0},
40 new Coordinate[] {Coordinate.NUL, Coordinate.NUL, Coordinate.NUL});
44 public void testSimplifyDesignation() {
45 assertEquals("J115", ThrustCurveMotorSet.simplifyDesignation("J115"));
46 assertEquals("J115", ThrustCurveMotorSet.simplifyDesignation(" J115 "));
47 assertEquals("H115", ThrustCurveMotorSet.simplifyDesignation("241H115-KS"));
48 assertEquals("J115", ThrustCurveMotorSet.simplifyDesignation("384 J115"));
49 assertEquals("J115", ThrustCurveMotorSet.simplifyDesignation("384-J115"));
50 assertEquals("A2", ThrustCurveMotorSet.simplifyDesignation("A2T"));
51 assertEquals("1/2A2T", ThrustCurveMotorSet.simplifyDesignation("1/2A2T"));
52 assertEquals("Micro Maxx II", ThrustCurveMotorSet.simplifyDesignation("Micro Maxx II"));
56 public void testAdding() {
57 ThrustCurveMotorSet set = new ThrustCurveMotorSet();
60 assertNull(set.getManufacturer());
61 assertEquals(0, set.getMotors().size());
64 assertTrue(set.matches(motor1));
66 assertEquals(motor1.getManufacturer(), set.getManufacturer());
67 assertEquals(motor1.getDesignation(), set.getDesignation());
68 assertEquals(Motor.Type.UNKNOWN, set.getType());
69 assertEquals(motor1.getDiameter(), set.getDiameter(), 0.00001);
70 assertEquals(motor1.getLength(), set.getLength(), 0.00001);
71 assertEquals(1, set.getMotors().size());
72 assertEquals(motor1, set.getMotors().get(0));
73 assertEquals(Collections.emptyList(), set.getDelays());
76 assertTrue(set.matches(motor1));
78 assertEquals(motor1.getManufacturer(), set.getManufacturer());
79 assertEquals(motor1.getDesignation(), set.getDesignation());
80 assertEquals(Motor.Type.UNKNOWN, set.getType());
81 assertEquals(motor1.getDiameter(), set.getDiameter(), 0.00001);
82 assertEquals(motor1.getLength(), set.getLength(), 0.00001);
83 assertEquals(1, set.getMotors().size());
84 assertEquals(motor1, set.getMotors().get(0));
85 assertEquals(Collections.emptyList(), set.getDelays());
88 assertTrue(set.matches(motor2));
90 assertEquals(motor1.getManufacturer(), set.getManufacturer());
91 assertEquals(motor3.getDesignation(), set.getDesignation());
92 assertEquals(Motor.Type.SINGLE, set.getType());
93 assertEquals(motor1.getDiameter(), set.getDiameter(), 0.00001);
94 assertEquals(motor1.getLength(), set.getLength(), 0.00001);
95 assertEquals(2, set.getMotors().size());
96 assertEquals(motor2, set.getMotors().get(0));
97 assertEquals(motor1, set.getMotors().get(1));
98 assertEquals(Arrays.asList(5.0), set.getDelays());
101 assertTrue(set.matches(motor3));
102 set.addMotor(motor3);
103 assertEquals(motor1.getManufacturer(), set.getManufacturer());
104 assertEquals(motor3.getDesignation(), set.getDesignation());
105 assertEquals(Motor.Type.SINGLE, set.getType());
106 assertEquals(motor1.getDiameter(), set.getDiameter(), 0.00001);
107 assertEquals(motor1.getLength(), set.getLength(), 0.00001);
108 assertEquals(3, set.getMotors().size());
109 assertEquals(motor3, set.getMotors().get(0));
110 assertEquals(motor2, set.getMotors().get(1));
111 assertEquals(motor1, set.getMotors().get(2));
112 assertEquals(Arrays.asList(0.0, 5.0, Motor.PLUGGED), set.getDelays());
114 // Test that adding motor4 fails
115 assertFalse(set.matches(motor4));
117 set.addMotor(motor4);
118 fail("Did not throw exception");
119 } catch (IllegalArgumentException e) {