update unit tests to match new motor code (also fixed a couple bugs the
unittests turned up!)
This commit is contained in:
parent
a17f6d9b1a
commit
3d0396bc00
@ -221,7 +221,7 @@ public class ThrustCurveMotorSet implements Comparable<ThrustCurveMotorSet> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!designation.equalsIgnoreCase(m.getDesignation()))
|
if (!commonName.equalsIgnoreCase(m.getCommonName()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (caseInfo != null && !caseInfo.equalsIgnoreCase(m.getCaseInfo()))
|
if (caseInfo != null && !caseInfo.equalsIgnoreCase(m.getCaseInfo()))
|
||||||
@ -348,11 +348,12 @@ public class ThrustCurveMotorSet implements Comparable<ThrustCurveMotorSet> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(ThrustCurveMotor o1, ThrustCurveMotor o2) {
|
public int compare(ThrustCurveMotor o1, ThrustCurveMotor o2) {
|
||||||
|
|
||||||
// 1. Designation
|
// 1. Designation
|
||||||
if (!o1.getDesignation().equals(o2.getDesignation())) {
|
if (!o1.getDesignation().equals(o2.getDesignation())) {
|
||||||
return o1.getDesignation().compareTo(o2.getDesignation());
|
return o1.getDesignation().compareTo(o2.getDesignation());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Number of data points (more is better)
|
// 2. Number of data points (more is better)
|
||||||
if (o1.getSampleSize() != o2.getSampleSize()) {
|
if (o1.getSampleSize() != o2.getSampleSize()) {
|
||||||
return o2.getSampleSize() - o1.getSampleSize();
|
return o2.getSampleSize() - o1.getSampleSize();
|
||||||
|
@ -90,4 +90,4 @@ public class DesignationComparator implements Comparator<String> {
|
|||||||
return COLLATOR.compare(o1, o2);
|
return COLLATOR.compare(o1, o2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
|
|||||||
* @return the simplified designation, or the string itself if the format was not detected
|
* @return the simplified designation, or the string itself if the format was not detected
|
||||||
*/
|
*/
|
||||||
private static final Pattern SIMPLIFY_PATTERN = Pattern.compile("^[0-9]*[ -]*([A-Z][0-9]+).*");
|
private static final Pattern SIMPLIFY_PATTERN = Pattern.compile("^[0-9]*[ -]*([A-Z][0-9]+).*");
|
||||||
static String simplifyDesignation(String str) {
|
public static String simplifyDesignation(String str) {
|
||||||
str = str.trim();
|
str = str.trim();
|
||||||
Matcher m = SIMPLIFY_PATTERN.matcher(str);
|
Matcher m = SIMPLIFY_PATTERN.matcher(str);
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
@ -244,7 +244,7 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
|
|||||||
// If I don't have a motor common name (will be the case if I read the thrustcurve from a flle)
|
// If I don't have a motor common name (will be the case if I read the thrustcurve from a flle)
|
||||||
// apply the motor code simplification heuristics to generate a common name
|
// apply the motor code simplification heuristics to generate a common name
|
||||||
if (motor.commonName.equals("")) {
|
if (motor.commonName.equals("")) {
|
||||||
motor.commonName = motor.designation;
|
motor.commonName = simplifyDesignation(motor.designation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ public class ThrustCurveMotorSetTest {
|
|||||||
|
|
||||||
private static final ThrustCurveMotor motor1 = new ThrustCurveMotor.Builder()
|
private static final ThrustCurveMotor motor1 = new ThrustCurveMotor.Builder()
|
||||||
.setManufacturer(Manufacturer.getManufacturer("A"))
|
.setManufacturer(Manufacturer.getManufacturer("A"))
|
||||||
|
.setCommonName("F12")
|
||||||
.setDesignation("F12X")
|
.setDesignation("F12X")
|
||||||
.setDescription("Desc")
|
.setDescription("Desc")
|
||||||
.setMotorType(Motor.Type.UNKNOWN)
|
.setMotorType(Motor.Type.UNKNOWN)
|
||||||
@ -36,6 +37,7 @@ public class ThrustCurveMotorSetTest {
|
|||||||
|
|
||||||
private static final ThrustCurveMotor motor2 = new ThrustCurveMotor.Builder()
|
private static final ThrustCurveMotor motor2 = new ThrustCurveMotor.Builder()
|
||||||
.setManufacturer(Manufacturer.getManufacturer("A"))
|
.setManufacturer(Manufacturer.getManufacturer("A"))
|
||||||
|
.setCommonName("F12")
|
||||||
.setDesignation("F12H")
|
.setDesignation("F12H")
|
||||||
.setDescription("Desc")
|
.setDescription("Desc")
|
||||||
.setMotorType(Motor.Type.SINGLE)
|
.setMotorType(Motor.Type.SINGLE)
|
||||||
@ -50,7 +52,7 @@ public class ThrustCurveMotorSetTest {
|
|||||||
|
|
||||||
private static final ThrustCurveMotor motor3 = new ThrustCurveMotor.Builder()
|
private static final ThrustCurveMotor motor3 = new ThrustCurveMotor.Builder()
|
||||||
.setManufacturer(Manufacturer.getManufacturer("A"))
|
.setManufacturer(Manufacturer.getManufacturer("A"))
|
||||||
.setDesignation("F12")
|
.setCode("F12")
|
||||||
.setDescription("Desc")
|
.setDescription("Desc")
|
||||||
.setMotorType(Motor.Type.UNKNOWN)
|
.setMotorType(Motor.Type.UNKNOWN)
|
||||||
.setStandardDelays(new double[] { 0, Motor.PLUGGED_DELAY })
|
.setStandardDelays(new double[] { 0, Motor.PLUGGED_DELAY })
|
||||||
@ -65,7 +67,7 @@ public class ThrustCurveMotorSetTest {
|
|||||||
private static final ThrustCurveMotor motor4 = new ThrustCurveMotor.Builder()
|
private static final ThrustCurveMotor motor4 = new ThrustCurveMotor.Builder()
|
||||||
.setManufacturer(Manufacturer.getManufacturer("A"))
|
.setManufacturer(Manufacturer.getManufacturer("A"))
|
||||||
.setDesignation("F12")
|
.setDesignation("F12")
|
||||||
.setDesignation("Desc")
|
.setDescription("Desc")
|
||||||
.setMotorType(Motor.Type.HYBRID)
|
.setMotorType(Motor.Type.HYBRID)
|
||||||
.setStandardDelays(new double[] { 0 })
|
.setStandardDelays(new double[] { 0 })
|
||||||
.setDiameter(0.024)
|
.setDiameter(0.024)
|
||||||
@ -75,20 +77,7 @@ public class ThrustCurveMotorSetTest {
|
|||||||
.setCGPoints(new Coordinate[] { Coordinate.NUL, Coordinate.NUL, Coordinate.NUL })
|
.setCGPoints(new Coordinate[] { Coordinate.NUL, Coordinate.NUL, Coordinate.NUL })
|
||||||
.setDigest("digestD")
|
.setDigest("digestD")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSimplifyDesignation() {
|
|
||||||
assertEquals("J115", ThrustCurveMotorSet.simplifyDesignation("J115"));
|
|
||||||
assertEquals("J115", ThrustCurveMotorSet.simplifyDesignation(" J115 "));
|
|
||||||
assertEquals("H115", ThrustCurveMotorSet.simplifyDesignation("241H115-KS"));
|
|
||||||
assertEquals("J115", ThrustCurveMotorSet.simplifyDesignation("384 J115"));
|
|
||||||
assertEquals("J115", ThrustCurveMotorSet.simplifyDesignation("384-J115"));
|
|
||||||
assertEquals("A2", ThrustCurveMotorSet.simplifyDesignation("A2T"));
|
|
||||||
assertEquals("1/2A2T", ThrustCurveMotorSet.simplifyDesignation("1/2A2T"));
|
|
||||||
assertEquals("MicroMaxxII", ThrustCurveMotorSet.simplifyDesignation("Micro Maxx II"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdding() {
|
public void testAdding() {
|
||||||
ThrustCurveMotorSet set = new ThrustCurveMotorSet();
|
ThrustCurveMotorSet set = new ThrustCurveMotorSet();
|
||||||
@ -108,7 +97,7 @@ public class ThrustCurveMotorSetTest {
|
|||||||
assertEquals(1, set.getMotors().size());
|
assertEquals(1, set.getMotors().size());
|
||||||
assertEquals(motor1, set.getMotors().get(0));
|
assertEquals(motor1, set.getMotors().get(0));
|
||||||
assertEquals(Collections.emptyList(), set.getDelays());
|
assertEquals(Collections.emptyList(), set.getDelays());
|
||||||
|
|
||||||
// Add motor1 again
|
// Add motor1 again
|
||||||
assertTrue(set.matches(motor1));
|
assertTrue(set.matches(motor1));
|
||||||
set.addMotor(motor1);
|
set.addMotor(motor1);
|
||||||
@ -120,12 +109,12 @@ public class ThrustCurveMotorSetTest {
|
|||||||
assertEquals(1, set.getMotors().size());
|
assertEquals(1, set.getMotors().size());
|
||||||
assertEquals(motor1, set.getMotors().get(0));
|
assertEquals(motor1, set.getMotors().get(0));
|
||||||
assertEquals(Collections.emptyList(), set.getDelays());
|
assertEquals(Collections.emptyList(), set.getDelays());
|
||||||
|
|
||||||
// Add motor2
|
// Add motor2
|
||||||
assertTrue(set.matches(motor2));
|
assertTrue(set.matches(motor2));
|
||||||
set.addMotor(motor2);
|
set.addMotor(motor2);
|
||||||
assertEquals(motor1.getManufacturer(), set.getManufacturer());
|
assertEquals(motor1.getManufacturer(), set.getManufacturer());
|
||||||
assertEquals(motor3.getDesignation(), set.getDesignation());
|
assertEquals(motor3.getCommonName(), set.getCommonName());
|
||||||
assertEquals(Motor.Type.SINGLE, set.getType());
|
assertEquals(Motor.Type.SINGLE, set.getType());
|
||||||
assertEquals(motor1.getDiameter(), set.getDiameter(), 0.00001);
|
assertEquals(motor1.getDiameter(), set.getDiameter(), 0.00001);
|
||||||
assertEquals(motor1.getLength(), set.getLength(), 0.00001);
|
assertEquals(motor1.getLength(), set.getLength(), 0.00001);
|
||||||
@ -133,21 +122,26 @@ public class ThrustCurveMotorSetTest {
|
|||||||
assertEquals(motor2, set.getMotors().get(0));
|
assertEquals(motor2, set.getMotors().get(0));
|
||||||
assertEquals(motor1, set.getMotors().get(1));
|
assertEquals(motor1, set.getMotors().get(1));
|
||||||
assertEquals(Arrays.asList(5.0), set.getDelays());
|
assertEquals(Arrays.asList(5.0), set.getDelays());
|
||||||
|
|
||||||
// Add motor3
|
// Add motor3
|
||||||
assertTrue(set.matches(motor3));
|
assertTrue(set.matches(motor3));
|
||||||
set.addMotor(motor3);
|
set.addMotor(motor3);
|
||||||
assertEquals(motor1.getManufacturer(), set.getManufacturer());
|
assertEquals(motor1.getManufacturer(), set.getManufacturer());
|
||||||
assertEquals(motor3.getDesignation(), set.getDesignation());
|
assertEquals(motor3.getCommonName(), set.getCommonName());
|
||||||
assertEquals(Motor.Type.SINGLE, set.getType());
|
assertEquals(Motor.Type.SINGLE, set.getType());
|
||||||
assertEquals(motor1.getDiameter(), set.getDiameter(), 0.00001);
|
assertEquals(motor1.getDiameter(), set.getDiameter(), 0.00001);
|
||||||
assertEquals(motor1.getLength(), set.getLength(), 0.00001);
|
assertEquals(motor1.getLength(), set.getLength(), 0.00001);
|
||||||
assertEquals(3, set.getMotors().size());
|
assertEquals(3, set.getMotors().size());
|
||||||
|
System.out.println("motor set");
|
||||||
|
System.out.println(set.getMotors());
|
||||||
|
System.out.println(motor3);
|
||||||
|
System.out.println(motor2);
|
||||||
|
System.out.println(motor1);
|
||||||
assertEquals(motor3, set.getMotors().get(0));
|
assertEquals(motor3, set.getMotors().get(0));
|
||||||
assertEquals(motor2, set.getMotors().get(1));
|
assertEquals(motor2, set.getMotors().get(1));
|
||||||
assertEquals(motor1, set.getMotors().get(2));
|
assertEquals(motor1, set.getMotors().get(2));
|
||||||
assertEquals(Arrays.asList(0.0, 5.0, Motor.PLUGGED_DELAY), set.getDelays());
|
assertEquals(Arrays.asList(0.0, 5.0, Motor.PLUGGED_DELAY), set.getDelays());
|
||||||
|
|
||||||
// Test that adding motor4 fails
|
// Test that adding motor4 fails
|
||||||
assertFalse(set.matches(motor4));
|
assertFalse(set.matches(motor4));
|
||||||
try {
|
try {
|
||||||
|
@ -186,4 +186,16 @@ public class ThrustCurveMotorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSimplifyDesignation() {
|
||||||
|
assertEquals("J115", ThrustCurveMotor.Builder.simplifyDesignation("J115"));
|
||||||
|
assertEquals("J115", ThrustCurveMotor.Builder.simplifyDesignation(" J115 "));
|
||||||
|
assertEquals("H115", ThrustCurveMotor.Builder.simplifyDesignation("241H115-KS"));
|
||||||
|
assertEquals("J115", ThrustCurveMotor.Builder.simplifyDesignation("384 J115"));
|
||||||
|
assertEquals("J115", ThrustCurveMotor.Builder.simplifyDesignation("384-J115"));
|
||||||
|
assertEquals("A2", ThrustCurveMotor.Builder.simplifyDesignation("A2T"));
|
||||||
|
assertEquals("1/2A2T", ThrustCurveMotor.Builder.simplifyDesignation("1/2A2T"));
|
||||||
|
assertEquals("MicroMaxxII", ThrustCurveMotor.Builder.simplifyDesignation("Micro Maxx II"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user