Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
avibn committed Mar 23, 2023
1 parent cc6e57c commit 04a8a33
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,7 +27,8 @@ public class RecalculationController {
* @param blastProtection the blast protection value
* @return the new TORA value
*/
public HashMap<String, Double> recalculateTORA(Runway runway, String logicID, RunwayObstacle rwObst,
public HashMap<String, Double> recalculateTORA(Runway runway, String logicID,
RunwayObstacle rwObst,
double blastProtection) {
// Create hashmap to store all the parameters necessary for the calculations
var valueMap = new HashMap<String, Double>();
Expand Down Expand Up @@ -102,7 +105,8 @@ public HashMap<String, Double> recalculateTORA(Runway runway, String logicID, Ru
* @param tora the recalculated tora value
* @return the new ASDA value
*/
public HashMap<String, Double> recalculateASDA(Runway runway, String logicID, RunwayObstacle rwObst,
public HashMap<String, Double> recalculateASDA(Runway runway, String logicID,
RunwayObstacle rwObst,
double tora) {
// Create hashmap to store all the parameters necessary for the calculations
var valueMap = new HashMap<String, Double>();
Expand Down Expand Up @@ -148,7 +152,8 @@ public HashMap<String, Double> recalculateASDA(Runway runway, String logicID, Ru
* @return the new TODA value
*/

public HashMap<String, Double> recalculateTODA(Runway runway, String logicID, RunwayObstacle rwObst, double tora) {
public HashMap<String, Double> recalculateTODA(Runway runway, String logicID,
RunwayObstacle rwObst, double tora) {

// Create hashmap to store all the parameters necessary for the calculations
var valueMap = new HashMap<String, Double>();
Expand Down Expand Up @@ -191,7 +196,8 @@ public HashMap<String, Double> recalculateTODA(Runway runway, String logicID, Ru
* @param rwObst the obstacle on the runway
* @return the new LDA value
*/
public HashMap<String, Double> recalculateLDA(Runway runway, String logicID, RunwayObstacle rwObst) {
public HashMap<String, Double> recalculateLDA(Runway runway, String logicID,
RunwayObstacle rwObst) {
// Create hashmap to store all the parameters necessary for the calculations
var valueMap = new HashMap<String, Double>();

Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -108,6 +114,7 @@ void tearDown() {
logger.info("Test done");
}

@Order(1)
@Test
@DisplayName("Recalculate scenario 1")
void recalculateRunwayScenario1() {
Expand All @@ -116,6 +123,7 @@ void recalculateRunwayScenario1() {
2986, 2986, 2986, 3346);
}

@Order(2)
@Test
@DisplayName("Recalculate scenario 2")
void recalculateRunwayScenario2() {
Expand All @@ -124,6 +132,7 @@ void recalculateRunwayScenario2() {
2860, 2860, 2860, 1850);
}

@Order(3)
@Test
@DisplayName("Recalculate scenario 3")
void recalculateRunwayScenario3() {
Expand All @@ -132,6 +141,7 @@ void recalculateRunwayScenario3() {
2393, 2393, 2393, 2903);
}

@Order(4)
@Test
@DisplayName("Recalculate scenario 4")
void recalculateRunwayScenario4() {
Expand All @@ -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<String, Double>();
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<String, Double>();
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<String, Double>();
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<String, Double>();
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<String, Double>();
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<String, Double>();
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<String, Double>();
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<String, Double>();
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<String, Double> expected,
HashMap<String, Double> 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
*
Expand Down

0 comments on commit 04a8a33

Please sign in to comment.