Mock.PolarParser. Fixed a bug where it would only parse the first half of each row.

Mock.Polars. addEstimate also builds up a unique list of angles from the data file, instead of dynamically generating that when calculating a VMG.
addEstimate also adds estimates with negative angles (e.g., 45deg+windSpeed+boatSpeed, and -45deg+windSpeed+boatSpeed).
calculateVMG now accepts an upper and lower bounds to the allowed VMG bearing it returns - this way you can get VMGs only within a certain angle interval (e.g., [16, 99] degrees).
Also fixed some bugs in calculateVMG where it wasn't actually using the angles and such correctly.
Improved the test case slightly, but still need to calculate correct values by hand.

#story[873]
This commit is contained in:
fjc40
2017-05-13 17:10:06 +12:00
parent 04fdeaf2e2
commit 6f9249e238
3 changed files with 120 additions and 38 deletions
@@ -11,6 +11,7 @@ import static org.testng.Assert.*;
*/
public class PolarsTest {
@Test
/**
* Tests if we can parse a polar data file (stored in a string), create a polar table, and calculate VMG for a variety of values.
@@ -18,7 +19,7 @@ public class PolarsTest {
public void testParseAndVMG() throws Exception {
//Read data.
Polars polars;
Polars polars = null;
try {
//Parse data file.
polars = PolarParser.parse("polars/acc_polars.csv");
@@ -27,20 +28,45 @@ public class PolarsTest {
assertTrue(false);
}
double angleEpsilon = 2;
double speedEpsilon = 2;//Are these epsilons a bit too big?
//Test 1.
//TODO make these tests actually do something when the calculateVMG function is added.
double windAngle1 = 31.5;
double destAngle1 = 65.32;
double windSpeed1 = 15;//knots
//double vmgAngle1 = TODO;
//double vmgSpeed1 = TODO;
double vmgAngle1 = 88;
double vmgSpeed1 = 12;
//VMG calcVMG1 = Polars.calculateVMG(windAngle1, destAngle1, windSpeed1);
//double calcVMGAngle1 = calcVMG1.getKey();
//double calcVMGSpeed1 = calcVMG1.getValue();
VMG calcVMG1 = polars.calculateVMG(windAngle1, windSpeed1, destAngle1, 0, 360);
double calcVMGAngle1 = calcVMG1.getBearing();
double calcVMGSpeed1 = calcVMG1.getSpeed();
//assertEquals(vmgAngle1, calcVMGAngle1, 0.1);
//assertEquals(vmgSpeed1, calcVMGSpeed1, 0.1);
System.out.println("VMG speed = " + calcVMGSpeed1 + " , VMG angle = " + calcVMGAngle1);//TEMP DEBUG REMOVE
//assertEquals(calcVMGAngle1, vmgAngle1, angleEpsilon);
//assertEquals(calcVMGSpeed1, vmgSpeed1, speedEpsilon);
//Test 2.
double windAngle2 = 200;
double destAngle2 = 35;
double windSpeed2 = 20;//knots
double vmgAngle2 = 88;
double vmgSpeed2 = 12;
VMG calcVMG2 = polars.calculateVMG(windAngle2, windSpeed2, destAngle2, 0, 360);
double calcVMGAngle2 = calcVMG2.getBearing();
double calcVMGSpeed2 = calcVMG2.getSpeed();
System.out.println("VMG speed = " + calcVMGSpeed2 + " , VMG angle = " + calcVMGAngle2);//TEMP DEBUG REMOVE
//assertEquals(calcVMGAngle2, vmgAngle2, angleEpsilon);
//assertEquals(calcVMGSpeed2, vmgSpeed2, speedEpsilon);
}