Skip to content

Commit

Permalink
Implemented method to compute military weather category
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankMurmann committed Jan 12, 2025
1 parent 049b045 commit dbd5e80
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.mivek.model;

import java.util.function.BiFunction;

public enum MilitaryWeatherCategory implements WeatherCategory {

RED((v, c) -> c < 200 && v < 0.8),
AMB((v, c) -> c >= 200 && c < 300 && v >= 0.8 && v < 1.6),
YLO((v, c) -> c >= 300 && c < 700 && v >= 1.6 && v < 3.7),
GRN((v, c) -> c >= 700 && c < 1500 && v >= 3.7 && v < 5.0),
WHT((v, c) -> c >= 1500 && c < 2500 && v >= 5.0 && v < 8.0),
BLU((v, c) -> c >= 2500 && v >= 8.0);

private final BiFunction<Double, Integer, Boolean> criteriaFunction;

MilitaryWeatherCategory(BiFunction<Double, Integer, Boolean> criteriaFunction) {
this.criteriaFunction = criteriaFunction;
}

public boolean isCriteriaMet(double visibility, int ceiling) {
return criteriaFunction.apply(visibility, ceiling);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public interface WeatherCategory {

Class<GAFORWeatherCategory> GAFOR = GAFORWeatherCategory.class;

Class<MilitaryWeatherCategory> MILITARY = MilitaryWeatherCategory.class;

boolean isCriteriaMet(double visibility, int ceiling);
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,34 @@ void computeGAFORWeatherCategory(Integer altitude, String mainVisibility, Intege
assertThat(result, is(expected));
}

@DisplayName("should compute military weather category")
@ParameterizedTest
@MethodSource
void computeMilitaryWeatherCategory(Integer altitude, String mainVisibility, Integer ceiling, MilitaryWeatherCategory expected) {
Airport airport = new Airport();
airport.setAltitude(altitude);
Visibility visibility = new Visibility();
visibility.setMainVisibility(mainVisibility);
metar.setAirport(airport);
metar.setVisibility(visibility);
Cloud cloudLow = new Cloud();
cloudLow.setHeight(200);
cloudLow.setQuantity(CloudQuantity.FEW);
Cloud cloudMid = new Cloud();
cloudMid.setHeight(ceiling);
cloudMid.setQuantity(CloudQuantity.BKN);
Cloud cloudHigh = new Cloud();
cloudHigh.setHeight(10000);
cloudHigh.setQuantity(CloudQuantity.SCT);
metar.addCloud(cloudLow);
metar.addCloud(cloudMid);
metar.addCloud(cloudHigh);

MilitaryWeatherCategory result = metar.getWeatherCategory(WeatherCategory.MILITARY);

assertThat(result, is(expected));
}

public static Stream<Arguments> computeFAAWeatherCategory() {
return Stream.of(
Arguments.of(500, "notParsable", 5000, null),
Expand Down Expand Up @@ -208,4 +236,15 @@ public static Stream<Arguments> computeGAFORWeatherCategory() {
Arguments.of(500, "10SM", 3000, GAFORWeatherCategory.O),
Arguments.of(500, "10SM", 6000, GAFORWeatherCategory.C));
}

public static Stream<Arguments> computeMilitaryWeatherCategory() {
return Stream.of(
Arguments.of(500, "notParsable", 5000, null),
Arguments.of(500, "500m", 600, MilitaryWeatherCategory.RED),
Arguments.of(500, "1000m", 750, MilitaryWeatherCategory.AMB),
Arguments.of(500, "2000m", 1000, MilitaryWeatherCategory.YLO),
Arguments.of(500, "4000m", 1300, MilitaryWeatherCategory.GRN),
Arguments.of(500, "6000m", 2300, MilitaryWeatherCategory.WHT),
Arguments.of(500, "10SM", 6000, MilitaryWeatherCategory.BLU));
}
}

0 comments on commit dbd5e80

Please sign in to comment.