Mock.Polars:

Finished PolarsTest test cases.

Fixed a number of javadoc errors across the codebase.

#story[873]
This commit is contained in:
fjc40
2017-05-17 13:33:34 +12:00
parent 00c9cb2c83
commit be9f19eae5
12 changed files with 171 additions and 107 deletions
@@ -1,5 +1,7 @@
package seng302.Model;
import org.junit.Before;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import seng302.DataInput.PolarParser;
import seng302.Exceptions.InvalidPolarFileException;
@@ -11,15 +13,16 @@ import static org.testng.Assert.*;
*/
public class PolarsTest {
private Polars polars = null;
private double angleEpsilon = 2;
private double speedEpsilon = 0.5;
@Test
@BeforeMethod
/**
* 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.
* Creates the Polars object for the tests.
*/
public void testParseAndVMG() throws Exception {
public void setUp() {
//Read data.
Polars polars = null;
try {
//Parse data file.
polars = PolarParser.parse("polars/acc_polars.csv");
@@ -27,96 +30,116 @@ public class PolarsTest {
catch (InvalidPolarFileException e) {
assertTrue(false);
}
}
double angleEpsilon = 2;
double speedEpsilon = 2;//Are these epsilons a bit too big?
@Test
/**
* Tests if we can calculate VMG for a variety of values.
*/
public void testVMG1() {
//Test 1.
//This test has a wind speed that is between two values from the table (12kn, 16kn, this is 15.9kn).
double windAngle1 = 31.5;
double destAngle1 = 65.32;
double windSpeed1 = 15.9;//knots
double vmgAngle1 = 88; //TODO the expected results need to be calculated and placed here.
double vmgSpeed1 = 12;
double vmgAngle1 = 72.4;
double vmgSpeed1 = 30.4;
VMG calcVMG1 = polars.calculateVMG(windAngle1, windSpeed1, destAngle1, 0, 360);
double calcVMGAngle1 = calcVMG1.getBearing();
double calcVMGSpeed1 = calcVMG1.getSpeed();
System.out.println("Test 1 VMG speed = " + calcVMGSpeed1 + " , VMG angle = " + calcVMGAngle1);//TEMP DEBUG REMOVE
assertEquals(calcVMGAngle1, vmgAngle1, angleEpsilon);
assertEquals(calcVMGSpeed1, vmgSpeed1, speedEpsilon);
//assertEquals(calcVMGAngle1, vmgAngle1, angleEpsilon);
//assertEquals(calcVMGSpeed1, vmgSpeed1, speedEpsilon);
}
@Test
/**
* Tests if we can calculate VMG for a variety of values.
*/
public void testVMG2() {
//Test 2.
//This test has a wind speed much larger than any in the table (max from table is 30kn, this is 40kn).
double windAngle2 = 200;
double destAngle2 = 35;
double windSpeed2 = 40;//knots
double vmgAngle2 = 88;
double vmgSpeed2 = 12;
double vmgAngle2 = 69;
double vmgSpeed2 = 32.8;
VMG calcVMG2 = polars.calculateVMG(windAngle2, windSpeed2, destAngle2, 0, 360);
double calcVMGAngle2 = calcVMG2.getBearing();
double calcVMGSpeed2 = calcVMG2.getSpeed();
System.out.println("Test 2 VMG speed = " + calcVMGSpeed2 + " , VMG angle = " + calcVMGAngle2);//TEMP DEBUG REMOVE
assertEquals(calcVMGAngle2, vmgAngle2, angleEpsilon);
assertEquals(calcVMGSpeed2, vmgSpeed2, speedEpsilon);
}
//assertEquals(calcVMGAngle2, vmgAngle2, angleEpsilon);
//assertEquals(calcVMGSpeed2, vmgSpeed2, speedEpsilon);
@Test
/**
* Tests if we can calculate VMG for a variety of values.
*/
public void testVMG3() {
//Test 3.
//This test has a wind speed lower than any non-zero values from the table (table has 0kn, 4kn, this is 2kn).
double windAngle3 = 345;
double destAngle3 = 199;
double windSpeed3 = 2;//knots
double vmgAngle3 = 88;
double vmgSpeed3 = 12;
double vmgAngle3 = 222;
double vmgSpeed3 = 4.4;
VMG calcVMG3 = polars.calculateVMG(windAngle3, windSpeed3, destAngle3, 0, 360);
double calcVMGAngle3 = calcVMG3.getBearing();
double calcVMGSpeed3 = calcVMG3.getSpeed();
System.out.println("Test 3 VMG speed = " + calcVMGSpeed3 + " , VMG angle = " + calcVMGAngle3);//TEMP DEBUG REMOVE
assertEquals(calcVMGAngle3, vmgAngle3, angleEpsilon);
assertEquals(calcVMGSpeed3, vmgSpeed3, speedEpsilon);
//assertEquals(calcVMGAngle3, vmgAngle3, angleEpsilon);
//assertEquals(calcVMGSpeed3, vmgSpeed3, speedEpsilon);
}
@Test
/**
* Tests if we can calculate VMG for a variety of values.
*/
public void testVMG4() {
//Test 4.
//This test has a wind speed of 0.
double windAngle4 = 5;
double destAngle4 = 100;
double windSpeed4 = 0;//knots
double vmgAngle4 = 88;
double vmgSpeed4 = 12;
double vmgAngle4 = 100;
double vmgSpeed4 = 0;
VMG calcVMG4 = polars.calculateVMG(windAngle4, windSpeed4, destAngle4, 0, 360);
double calcVMGAngle4 = calcVMG4.getBearing();
double calcVMGSpeed4 = calcVMG4.getSpeed();
System.out.println("Test 4 VMG speed = " + calcVMGSpeed4 + " , VMG angle = " + calcVMGAngle4);//TEMP DEBUG REMOVE
assertEquals(calcVMGAngle4, vmgAngle4, angleEpsilon);
assertEquals(calcVMGSpeed4, vmgSpeed4, speedEpsilon);
//assertEquals(calcVMGAngle4, vmgAngle4, angleEpsilon);
//assertEquals(calcVMGSpeed4, vmgSpeed4, speedEpsilon);
}
@Test
/**
* Tests if we can calculate VMG for a variety of values.
*/
public void testVMG5() {
//Test 5.
//This test has a bearing bound of [55, 70), which only contains a suboptimal VMG.
double windAngle5 = 5;//TODO
double windAngle5 = 5;
double destAngle5 = 100;
double windSpeed5 = 9;//knots
double vmgAngle5 = 88;
double vmgSpeed5 = 12;
double vmgAngle5 = 70;
double vmgSpeed5 = 15;
double bearingUpperBound5 = 70;
double bearingLowerBound5 = 55;
@@ -124,22 +147,28 @@ public class PolarsTest {
double calcVMGAngle5 = calcVMG5.getBearing();
double calcVMGSpeed5 = calcVMG5.getSpeed();
System.out.println("Test 5 VMG speed = " + calcVMGSpeed5 + " , VMG angle = " + calcVMGAngle5);//TEMP DEBUG REMOVE
assertEquals(calcVMGAngle5, vmgAngle5, angleEpsilon);
assertEquals(calcVMGSpeed5, vmgSpeed5, speedEpsilon);
assertTrue(calcVMGAngle5 >= bearingLowerBound5);
assertTrue(calcVMGAngle5 < bearingUpperBound5);
}
//assertEquals(calcVMGAngle5, vmgAngle5, angleEpsilon);
//assertEquals(calcVMGSpeed5, vmgSpeed5, speedEpsilon);
//assertTrue(calcVMGAngle5 >= bearingLowerBound5);
//assertTrue(calcVMGAngle5 < bearingUpperBound5);
@Test
/**
* Tests if we can calculate VMG for a variety of values.
*/
public void testVMG6() {
//Test 6.
//This test has a bearing bound of [70, 55), which has a lower bound > upper bound, which is complementary to [55, 70).
double windAngle6 = 5;//TODO
double windAngle6 = 5;
double destAngle6 = 100;
double windSpeed6 = 11;//knots
double vmgAngle6 = 88;
double vmgSpeed6 = 12;
double vmgAngle6 = 92.85;
double vmgSpeed6 = 20.086;
double bearingUpperBound6 = 55;
double bearingLowerBound6 = 70;
@@ -147,11 +176,9 @@ public class PolarsTest {
double calcVMGAngle6 = calcVMG6.getBearing();
double calcVMGSpeed6 = calcVMG6.getSpeed();
System.out.println("Test 6 VMG speed = " + calcVMGSpeed6 + " , VMG angle = " + calcVMGAngle6);//TEMP DEBUG REMOVE
//assertEquals(calcVMGAngle6, vmgAngle6, angleEpsilon);
//assertEquals(calcVMGSpeed6, vmgSpeed6, speedEpsilon);
assertEquals(calcVMGAngle6, vmgAngle6, angleEpsilon);
assertEquals(calcVMGSpeed6, vmgSpeed6, speedEpsilon);
if (bearingLowerBound6 > bearingUpperBound6) {
assertTrue((calcVMGAngle6 >= bearingLowerBound6) || (calcVMGAngle6 <= bearingUpperBound6));
} else {
@@ -159,6 +186,13 @@ public class PolarsTest {
assertTrue(calcVMGAngle6 < bearingUpperBound6);
}
}
@Test
/**
* Tests if we can calculate VMG for a variety of values.
*/
public void testVMG7() {
//Test 7.
@@ -185,7 +219,13 @@ public class PolarsTest {
assertTrue(calcVMGAngle7 < bearingUpperBound7);
}
}
@Test
/**
* Tests if we can calculate VMG for a variety of values.
*/
public void testVMG8() {
//Test 8.
//This test has a bearing bound of [340, 5), which has a lower bound > upper bound, which is complementary to [5, 340). Due to the wind, dest angles, and bearing bounds, it cannot actually find a VMG > 0 (valid VMGs will actually be in the angle interval [10, 190]), so it will return the VMG(angle=0, speed=0).
double windAngle8 = 5;