Altered test to hopefully fix occasional indeterministic bug that occurred.

This commit is contained in:
Calum
2017-09-09 13:13:45 +12:00
parent edd52a07a7
commit 08f7127b69
+11 -8
View File
@@ -2,7 +2,10 @@ package seng302.models;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import javafx.util.Pair;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@@ -53,7 +56,7 @@ public class YachtTest {
Double upwind = PolarTable.getOptimalUpwindVMG(windSpeed).keySet().iterator().next(); Double upwind = PolarTable.getOptimalUpwindVMG(windSpeed).keySet().iterator().next();
Double downwind = PolarTable.getOptimalDownwindVMG(windSpeed).keySet().iterator().next(); Double downwind = PolarTable.getOptimalDownwindVMG(windSpeed).keySet().iterator().next();
HashMap<Double, Double> values = new HashMap<>(); List<Pair<Double, Double>> values = new ArrayList<>();
upwind = (double) Math.floorMod(upwind.longValue() + windDirection.longValue(), 360L); upwind = (double) Math.floorMod(upwind.longValue() + windDirection.longValue(), 360L);
Double upwindRight = upwind; Double upwindRight = upwind;
@@ -62,19 +65,19 @@ public class YachtTest {
Double downwindRight = downwind; Double downwindRight = downwind;
Double downwindLeft = 360 - downwindRight; Double downwindLeft = 360 - downwindRight;
values.put(190d, upwindRight); values.add(new Pair<>(190d, upwindRight));
values.put(170d, upwindLeft); values.add(new Pair<>(170d, upwindLeft));
values.put(10d, downwindLeft); values.add(new Pair<>(10d, downwindLeft));
values.put(350d, downwindRight); values.add(new Pair<>(350d, downwindRight));
for (Double begin : values.keySet()) { for (Pair<Double, Double> beginEndPair : values) {
y1.setHeading(begin); y1.setHeading(beginEndPair.getKey());
y1.turnToVMG(); y1.turnToVMG();
for (int i = 0; i < 200; i++) { for (int i = 0; i < 200; i++) {
y1.runAutoPilot(); y1.runAutoPilot();
} }
y1.disableAutoPilot(); y1.disableAutoPilot();
assertEquals(values.get(begin), y1.getHeading(), 5.0); assertEquals(beginEndPair.getValue(), y1.getHeading(), 5.0);
} }
} }