Skip to content

Commit

Permalink
Restore some comments and add new tests of the function is_number.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoconni committed Feb 9, 2025
1 parent 7c647c6 commit bd6be49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/input_output/string_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ double atof_locale_c(const string& input)
first++;
}

// Skip leading whitespaces
if (!*first) {
InvalidNumber e("Expecting a numeric attribute value, but only got spaces");
cerr << e.what() << endl;
Expand Down
4 changes: 2 additions & 2 deletions src/models/flight_control/FGSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ FGSwitch::FGSwitch(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
current_test->setTestValue(value, Name, PropertyManager, test_element);
current_test->Default = true;
auto output_value = current_test->OutputValue.ptr();
if (delay > 0 && dynamic_cast<FGRealValue*>(output_value)) {
if (delay > 0 && dynamic_cast<FGRealValue*>(output_value)) { // If there is a delay
double v = output_value->GetValue();
for (unsigned int i=0; i<delay-1; i++) { // delay buffer to the default value
for (unsigned int i=0; i<delay-1; i++) { // Initialize the delay buffer to the default value
output_array[i] = v; // for the switch if that value is a number.
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/unit_tests/StringUtilitiesTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ class StringUtilitiesTest : public CxxTest::TestSuite
TS_ASSERT(is_number("-1.0e+1"));
TS_ASSERT(!is_number(empty));
TS_ASSERT(!is_number("125x5#"));
TS_ASSERT(!is_number("x"));
TS_ASSERT(!is_number("1.0.0"));
TS_ASSERT(!is_number("1.0e"));
TS_ASSERT(!is_number("1.0e+"));
TS_ASSERT(!is_number("1.0e1.0"));
TS_ASSERT(!is_number("--1"));
TS_ASSERT(!is_number("++1"));
TS_ASSERT(!is_number("1+"));
TS_ASSERT(!is_number("1-"));
TS_ASSERT(!is_number(""));
TS_ASSERT(!is_number(" "));
TS_ASSERT(!is_number("3.14a"));
TS_ASSERT(!is_number("-.1e-"));
}

void testSplit() {
Expand Down

0 comments on commit bd6be49

Please sign in to comment.