VMG now works however some little bug in the interpolation in some quadrant that is making the speed all the same in the quadrant #story[1182]

This commit is contained in:
Fan-Wu Yang
2017-09-05 19:26:06 +12:00
parent 7aaa880f40
commit 7331ad1a20
5 changed files with 148 additions and 17 deletions
@@ -0,0 +1,107 @@
package mock.model;
import mock.dataInput.PolarParser;
import org.junit.Before;
import org.junit.Test;
import shared.model.Bearing;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
/**
* Created by fwy13 on 5/09/17.
*/
public class NewPolarsTest {
@Before
public void setUp(){
PolarParser.parseNewPolars("mock/polars/acc_polars.csv");
NewPolars.linearInterpolatePolars();
}
@Test
public void testQuads() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
//reflection for private class
Class[] parameterTypes = new Class[1];
parameterTypes[0] = Double.TYPE;
Method getQuads = NewPolars.class.getDeclaredMethod("getQuadrant", parameterTypes);
getQuads.setAccessible(true);
//start invoking
Object[] paras1 = new Object[1];
paras1[0] = (new Double(0)).doubleValue();
int q1 = (int) getQuads.invoke(NewPolars.newPolars, paras1);
assertEquals(q1, 1);
//start invoking
Object[] paras2 = new Object[1];
paras2[0] = (new Double(90)).doubleValue();
int q2 = (int) getQuads.invoke(NewPolars.newPolars, paras2);
assertEquals(q2, 2);
//start invoking
Object[] paras3 = new Object[1];
paras3[0] = (new Double(180)).doubleValue();
int q3 = (int) getQuads.invoke(NewPolars.newPolars, paras3);
assertEquals(q3, 3);
//start invoking
Object[] paras4 = new Object[1];
paras4[0] = (new Double(270)).doubleValue();
int q4 = (int) getQuads.invoke(NewPolars.newPolars, paras4);
assertEquals(q4, 4);
//start invoking
Object[] paras5 = new Object[1];
paras5[0] = (new Double(360)).doubleValue();
int q5 = (int) getQuads.invoke(NewPolars.newPolars, paras5);
assertEquals(q5, 1);
}
@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;
for (double tws = 0; tws < maxTWS; tws += 0.1){
for (double j = 0; j < 360; j++){
Bearing twa = Bearing.fromDegrees(j);
for (double i = 0; i < 360; i++){
Bearing boatBearing = Bearing.fromDegrees(i);
double speed = NewPolars.calculateSpeed(twa, tws, boatBearing);
assertTrue(speed >= 0);
}
}
}
}
@Test
public void testClosestSpeeds() throws NoSuchMethodException, NoSuchFieldException, InvocationTargetException, IllegalAccessException {
//reflection for private class
Method getClosest = NewPolars.class.getDeclaredMethod("getClosest", double.class, Set.class);
getClosest.setAccessible(true);
Method getPolars = NewPolars.class.getDeclaredMethod("getPolars");
getPolars.setAccessible(true);
double maxTWS = 15;
//only catches for nulls
for (double tws = 0; tws < maxTWS; tws += 0.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);
}
}
}