diff --git a/src/main/java/com/team44/runwayredeclarationapp/controller/RecalculationController.java b/src/main/java/com/team44/runwayredeclarationapp/controller/RecalculationController.java index 6746e54..62798cd 100644 --- a/src/main/java/com/team44/runwayredeclarationapp/controller/RecalculationController.java +++ b/src/main/java/com/team44/runwayredeclarationapp/controller/RecalculationController.java @@ -1,6 +1,8 @@ package com.team44.runwayredeclarationapp.controller; import com.team44.runwayredeclarationapp.event.RecalculatedRunwayListener; +import com.team44.runwayredeclarationapp.model.Obstacle; +import com.team44.runwayredeclarationapp.model.PRunway; import com.team44.runwayredeclarationapp.model.Runway; import com.team44.runwayredeclarationapp.model.RunwayObstacle; import java.util.HashMap; @@ -25,7 +27,8 @@ public class RecalculationController { * @param blastProtection the blast protection value * @return the new TORA value */ - public HashMap recalculateTORA(Runway runway, String logicID, RunwayObstacle rwObst, + public HashMap recalculateTORA(Runway runway, String logicID, + RunwayObstacle rwObst, double blastProtection) { // Create hashmap to store all the parameters necessary for the calculations var valueMap = new HashMap(); @@ -102,7 +105,8 @@ public HashMap recalculateTORA(Runway runway, String logicID, Ru * @param tora the recalculated tora value * @return the new ASDA value */ - public HashMap recalculateASDA(Runway runway, String logicID, RunwayObstacle rwObst, + public HashMap recalculateASDA(Runway runway, String logicID, + RunwayObstacle rwObst, double tora) { // Create hashmap to store all the parameters necessary for the calculations var valueMap = new HashMap(); @@ -148,7 +152,8 @@ public HashMap recalculateASDA(Runway runway, String logicID, Ru * @return the new TODA value */ - public HashMap recalculateTODA(Runway runway, String logicID, RunwayObstacle rwObst, double tora) { + public HashMap recalculateTODA(Runway runway, String logicID, + RunwayObstacle rwObst, double tora) { // Create hashmap to store all the parameters necessary for the calculations var valueMap = new HashMap(); @@ -191,7 +196,8 @@ public HashMap recalculateTODA(Runway runway, String logicID, Ru * @param rwObst the obstacle on the runway * @return the new LDA value */ - public HashMap recalculateLDA(Runway runway, String logicID, RunwayObstacle rwObst) { + public HashMap recalculateLDA(Runway runway, String logicID, + RunwayObstacle rwObst) { // Create hashmap to store all the parameters necessary for the calculations var valueMap = new HashMap(); @@ -319,4 +325,34 @@ public Runway recalculateRunway(RunwayObstacle rwObst, double blastProtection) { return recalculatedRunway; } + + public static void main(String[] args) { + PRunway runway09L27R = new PRunway(9, 27, 'L', 'R', new double[]{ + 3902,//runwayL + 100,//runwayW + 60,//stripL + 100,//stripW + 100,//clearwayW + 240, //resaL + 3902,//tora1 + 3902,//toda1 + 3902,//asda1 + 3595,//lda1 + 3884,//tora2 + 3962,//toda2 + 3884,//asda2 + 3884,//lda2 + 0,//disThresh1 + 306//disThresh2 + }); + Obstacle obstacle1 = new Obstacle("Obstacle Name", 12); + RunwayObstacle runwayObstacle1 = new RunwayObstacle(obstacle1, runway09L27R, -50.0, 3646.0, + 0.0); + + var ok = new RecalculationController(); + System.out.println(ok.recalculateTORA(runway09L27R, "09L", runwayObstacle1, 300)); + System.out.println(ok.recalculateTODA(runway09L27R, "09L", runwayObstacle1, 300)); + System.out.println(ok.recalculateASDA(runway09L27R, "09L", runwayObstacle1, 300)); + System.out.println(ok.recalculateLDA(runway09L27R, "09L", runwayObstacle1)); + } } diff --git a/src/main/tests/com/team44/runwayredeclarationapp/controller/RecalculationControllerTest.java b/src/main/tests/com/team44/runwayredeclarationapp/controller/RecalculationControllerTest.java index a47fb12..bc3825d 100644 --- a/src/main/tests/com/team44/runwayredeclarationapp/controller/RecalculationControllerTest.java +++ b/src/main/tests/com/team44/runwayredeclarationapp/controller/RecalculationControllerTest.java @@ -2,20 +2,26 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.team44.runwayredeclarationapp.model.Obstacle; import com.team44.runwayredeclarationapp.model.PRunway; import com.team44.runwayredeclarationapp.model.RunwayObstacle; +import java.util.HashMap; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; /** * Test to see if the recalculated values are correct */ +@TestMethodOrder(OrderAnnotation.class) class RecalculationControllerTest { private static final Logger logger = LogManager.getLogger(RecalculationController.class); @@ -108,6 +114,7 @@ void tearDown() { logger.info("Test done"); } + @Order(1) @Test @DisplayName("Recalculate scenario 1") void recalculateRunwayScenario1() { @@ -116,6 +123,7 @@ void recalculateRunwayScenario1() { 2986, 2986, 2986, 3346); } + @Order(2) @Test @DisplayName("Recalculate scenario 2") void recalculateRunwayScenario2() { @@ -124,6 +132,7 @@ void recalculateRunwayScenario2() { 2860, 2860, 2860, 1850); } + @Order(3) @Test @DisplayName("Recalculate scenario 3") void recalculateRunwayScenario3() { @@ -132,6 +141,7 @@ void recalculateRunwayScenario3() { 2393, 2393, 2393, 2903); } + @Order(4) @Test @DisplayName("Recalculate scenario 4") void recalculateRunwayScenario4() { @@ -140,6 +150,134 @@ void recalculateRunwayScenario4() { 3534, 3612, 3534, 2774); } + @Order(5) + @Test + @DisplayName("Calculation breakdown TORA (Logical Runway 1)") + void tora1CalculationBreakdown() { + var expected = new HashMap(); + expected.put("displacedThreshold", 306.0); + expected.put("distanceFromThreshold", -50.0); + expected.put("blastProtection", 300.0); + expected.put("recalTORA", 3346.0); + expected.put("ogTORA", 3902.0); + + assertTrue(testRecalculatedHashmaps(expected, + recalculationController.recalculateTORA(runway09L27R, "09L", runwayObstacle1, 300))); + } + + @Order(6) + @Test + @DisplayName("Calculation breakdown TORA (Logical Runway 2)") + void tora2CalculationBreakdown() { + var expected = new HashMap(); + expected.put("distanceFromThreshold", 3646.0); + expected.put("slopeCalculation", 600.0); + expected.put("stripEnd", 60.0); + expected.put("recalTORA", 2986.0); + + assertTrue(testRecalculatedHashmaps(expected, + recalculationController.recalculateTORA(runway09L27R, "27R", runwayObstacle1, 300))); + } + + @Order(7) + @Test + @DisplayName("Calculation breakdown TODA (Logical Runway 1)") + void toda1CalculationBreakdown() { + var expected = new HashMap(); + expected.put("clearway", 0.0); + expected.put("recalTODA", 300.0); + expected.put("tora", 300.0); + + assertTrue(testRecalculatedHashmaps(expected, + recalculationController.recalculateTODA(runway09L27R, "09L", runwayObstacle1, 300))); + } + + @Order(8) + @Test + @DisplayName("Calculation breakdown TODA (Logical Runway 2)") + void toda2CalculationBreakdown() { + var expected = new HashMap(); + expected.put("recalTODA", 300.0); + expected.put("tora", 300.0); + + assertTrue(testRecalculatedHashmaps(expected, + recalculationController.recalculateTODA(runway09L27R, "27R", runwayObstacle1, 300))); + } + + @Order(9) + @Test + @DisplayName("Calculation breakdown ASDA (Logical Runway 1)") + void asda1CalculationBreakdown() { + var expected = new HashMap(); + expected.put("stopway", 0.0); + expected.put("recalASDA", 300.0); + expected.put("tora", 300.0); + + assertTrue(testRecalculatedHashmaps(expected, + recalculationController.recalculateASDA(runway09L27R, "09L", runwayObstacle1, 300))); + } + + @Order(10) + @Test + @DisplayName("Calculation breakdown ASDA (Logical Runway 2)") + void asda2CalculationBreakdown() { + var expected = new HashMap(); + expected.put("recalASDA", 300.0); + expected.put("tora", 300.0); + + assertTrue(testRecalculatedHashmaps(expected, + recalculationController.recalculateASDA(runway09L27R, "27R", runwayObstacle1, 300))); + } + + @Order(111) + @Test + @DisplayName("Calculation breakdown LDA (Logical Runway 1)") + void lda1CalculationBreakdown() { + var expected = new HashMap(); + expected.put("distanceFromThreshold", -50.0); + expected.put("slopeCalculation", 600.0); + expected.put("recalLDA", 2985.0); + expected.put("ogLDA", 3595.0); + expected.put("stripEnd", 60.0); + + assertTrue(testRecalculatedHashmaps(expected, + recalculationController.recalculateLDA(runway09L27R, "09L", runwayObstacle1))); + } + + @Order(12) + @Test + @DisplayName("Calculation breakdown LDA (Logical Runway 2)") + void lda2CalculationBreakdown() { + var expected = new HashMap(); + expected.put("distanceFromThreshold", 3646.0); + expected.put("resa", 240.0); + expected.put("recalLDA", 3346.0); + expected.put("stripEnd", 60.0); + + assertTrue(testRecalculatedHashmaps(expected, + recalculationController.recalculateLDA(runway09L27R, "27R", runwayObstacle1))); + } + + /** + * Compare a hashmap with another hashmap, disregarding the order + * + * @param expected the expected outcome + * @param actual the actual outcome + * @return whether the hashmaps are equal + */ + private Boolean testRecalculatedHashmaps(HashMap expected, + HashMap actual) { + // Check if they're the same size + if (actual.size() != expected.size()) { + return false; + } + + // Iterate through each outcome and compare with expected + return actual.entrySet().stream().allMatch(stringDoubleEntry -> { + return stringDoubleEntry.getValue().equals(expected.get(stringDoubleEntry.getKey())); + }); + } + /** * Test that the recalculated parameters of a parallel runway is correct *