VMG is now working and fixed, however, it feels a bit odd #story[1182]

This commit is contained in:
Fan-Wu Yang
2017-09-05 21:03:19 +12:00
parent 7331ad1a20
commit d602c1ec6f
3 changed files with 65 additions and 12 deletions
@@ -25,6 +25,21 @@ public class NewPolarsTest {
public void setUp(){
PolarParser.parseNewPolars("mock/polars/acc_polars.csv");
NewPolars.linearInterpolatePolars();
Method getPolars = null;
try {
getPolars = NewPolars.class.getDeclaredMethod("printOutLinearInterpolated");
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
getPolars.setAccessible(true);
try {
getPolars.invoke(NewPolars.newPolars);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
@Test
@@ -70,9 +85,9 @@ public class NewPolarsTest {
@Test
public void testEdgeSpeeds(){
//just make sure that speeds at certain angles do not throw a null exception and are not negative
double maxTWS = 15;
double maxTWS = 30;
for (double tws = 0; tws < maxTWS; tws += 0.1){
for (double tws = 0; tws < maxTWS; tws += 1){
for (double j = 0; j < 360; j++){
Bearing twa = Bearing.fromDegrees(j);
for (double i = 0; i < 360; i++){
@@ -94,14 +109,31 @@ public class NewPolarsTest {
Method getPolars = NewPolars.class.getDeclaredMethod("getPolars");
getPolars.setAccessible(true);
double maxTWS = 15;
double maxTWS = 30;
//only catches for nulls
for (double tws = 0; tws < maxTWS; tws += 0.1){
for (double tws = 0; tws < maxTWS; tws += 1){
Map<Double, TreeMap<Double, Double>> polars = (Map<Double, TreeMap<Double, Double>>) getPolars.invoke(NewPolars.newPolars);
double speed = (double) getClosest.invoke(NewPolars.newPolars, tws, polars.keySet());
assertTrue(speed >= 0);
}
}
@Test
public void testAutoVSCalculated(){
//test that the auto chosen speed is the same speed that is calculated
double maxTWS = 30;
for (double tws = 0; tws < maxTWS; tws ++){
for (double twa = 0; twa < 360; twa ++){
Bearing TW = Bearing.fromDegrees(twa);
for (double ba = 0; ba < 360; ba ++){
Bearing boatBearing = Bearing.fromDegrees(ba);
VMG autoVMG = NewPolars.setBestVMG(TW, tws, boatBearing);
double speed = NewPolars.calculateSpeed(TW, tws, autoVMG.getBearing());
assertTrue(autoVMG.getSpeed() == speed);
}
}
}
}
}