Skip to content

Commit 71e40a0

Browse files
committed
fix: machs are integers in the api
1 parent e48ef5e commit 71e40a0

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/api/FlowMeasureMeasureParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "ECFMP/log/Logger.h"
33
#include "flowmeasure/ConcreteMeasure.h"
44
#include "nlohmann/json.hpp"
5+
#include <string>
56

67
namespace ECFMP::Api {
78

@@ -50,10 +51,11 @@ namespace ECFMP::Api {
5051
// If the type is MaxMach, MachReduction, then the value must be a double
5152
if (type == FlowMeasure::MeasureType::MaxMach || type == FlowMeasure::MeasureType::MachReduction) {
5253

53-
if (!data["value"].is_number_float())
54+
if (!data["value"].is_number_integer())
5455
return nullptr;
5556

56-
return std::make_unique<FlowMeasure::ConcreteMeasure>(type, data["value"].get<double>());
57+
// Machs in the API are stored as integers, so we need to divide by 100
58+
return std::make_unique<FlowMeasure::ConcreteMeasure>(type, data["value"].get<double>() / 100);
5759
}
5860

5961
// If the type is MandatoryRoute, then the value must be a set of strings

test/api/FlowMeasureMeasureParserTest.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ namespace ECFMPTest::Api {
7878
const auto& param = GetParam();
7979
nlohmann::json json;
8080
json["type"] = param.jsonType;
81-
json["value"] = param.jsonValue;
81+
json["value"] = (int) (param.jsonValue * 100);
8282
auto measure = parser.Parse(json);
8383
EXPECT_NE(measure, nullptr);
8484
EXPECT_EQ(measure->Type(), param.expectedType);
@@ -90,9 +90,14 @@ namespace ECFMPTest::Api {
9090
testing::Values(
9191
FlowMeasureMeasureTestCase<double>{
9292
"max_mach", "max_mach", 5.0, ECFMP::FlowMeasure::MeasureType::MaxMach, 5.0},
93+
FlowMeasureMeasureTestCase<double>{
94+
"max_mach_less_than_1", "max_mach", 0.25, ECFMP::FlowMeasure::MeasureType::MaxMach, 0.25},
9395
FlowMeasureMeasureTestCase<double>{
9496
"mach_reduction", "mach_reduction", 5.0, ECFMP::FlowMeasure::MeasureType::MachReduction,
95-
5.0}
97+
5.0},
98+
FlowMeasureMeasureTestCase<double>{
99+
"mach_reduction_less_than_1", "mach_reduction", 0.25,
100+
ECFMP::FlowMeasure::MeasureType::MachReduction, 0.25}
96101
),
97102
[](const testing::TestParamInfo<FlowMeasureMeasureTestCase<double>>& info) {
98103
return info.param.description;

0 commit comments

Comments
 (0)