Skip to content

Commit

Permalink
Tests detection of non monotically increasing rows & columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoconni committed Dec 19, 2021
1 parent 998af3d commit d8f8107
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions tests/unit_tests/FGTableTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,29 @@ class FGTable1DTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(t_2x1.GetElement(1,1), -1.0);
TS_ASSERT_EQUALS(t_2x1.GetElement(2,0), 2.0);
TS_ASSERT_EQUALS(t_2x1.GetElement(2,1), 1.5);

// FGTable expects <table> to be the child of another XML element, hence the
// <dummy> element.
Element_ptr elm2 = readFromXML("<dummy>"
" <table name=\"test2\" type=\"internal\">"
" <tableData>"
" 1.0 1.0\n"
" 2.0 0.5\n"
" 4.0 0.5\n"
" </tableData>"
" </table>"
"</dummy>");
el_table = elm2->FindElement("table");

FGTable t_3x1(pm, el_table);
TS_ASSERT_EQUALS(t_3x1.GetNumRows(), 3);
TS_ASSERT_EQUALS(t_3x1.GetName(), std::string("test2"));
TS_ASSERT_EQUALS(t_3x1.GetElement(1,0), 1.0);
TS_ASSERT_EQUALS(t_3x1.GetElement(1,1), 1.0);
TS_ASSERT_EQUALS(t_3x1.GetElement(2,0), 2.0);
TS_ASSERT_EQUALS(t_3x1.GetElement(2,1), 0.5);
TS_ASSERT_EQUALS(t_3x1.GetElement(3,0), 4.0);
TS_ASSERT_EQUALS(t_3x1.GetElement(3,1), 0.5);
}

void testLoadIndepVarFromXML() {
Expand Down Expand Up @@ -255,6 +278,24 @@ class FGTable1DTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(t_2x1.GetValue(), 0.25);
TS_ASSERT_EQUALS(output->getDoubleValue(), 0.25);
}

void testMonoticallyIncreasingRows() {
auto pm = make_shared<FGPropertyManager>();
// FGTable expects <table> to be the child of another XML element, hence the
// <dummy> element.
Element_ptr elm = readFromXML("<dummy>"
" <table name=\"test2\" type=\"internal\">"
" <tableData>"
" 1.0 1.0\n"
" 1.0 0.5\n"
" 2.0 0.5\n"
" </tableData>"
" </table>"
"</dummy>");
Element *el_table = elm->FindElement("table");

TS_ASSERT_THROWS(FGTable t_3x1(pm, el_table), TableException&);
}
};


Expand Down Expand Up @@ -544,6 +585,35 @@ class FGTable2DTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(t_2x2(2,0), 4.0);
TS_ASSERT_EQUALS(t_2x2(2,1), -1.0);
TS_ASSERT_EQUALS(t_2x2(2,2), 0.5);

// FGTable expects <table> to be the child of another XML element, hence the
// <dummy> element.
Element_ptr elm2 = readFromXML("<dummy>"
" <table name=\"test2\" type=\"internal\">"
" <tableData>"
" 0.0 1.0\n"
" 1.0 1.0 -2.0\n"
" 2.0 1.0 0.5\n"
" 4.0 0.5 0.5\n"
" </tableData>"
" </table>"
"</dummy>");
el_table = elm2->FindElement("table");

FGTable t_3x2(pm, el_table);
TS_ASSERT_EQUALS(t_3x2.GetNumRows(), 3);
TS_ASSERT_EQUALS(t_3x2.GetName(), std::string("test2"));
TS_ASSERT_EQUALS(t_3x2(0,1), 0.0);
TS_ASSERT_EQUALS(t_3x2(0,2), 1.0);
TS_ASSERT_EQUALS(t_3x2(1,0), 1.0);
TS_ASSERT_EQUALS(t_3x2(1,1), 1.0);
TS_ASSERT_EQUALS(t_3x2(1,2), -2.0);
TS_ASSERT_EQUALS(t_3x2(2,0), 2.0);
TS_ASSERT_EQUALS(t_3x2(2,1), 1.0);
TS_ASSERT_EQUALS(t_3x2(2,2), 0.5);
TS_ASSERT_EQUALS(t_3x2(3,0), 4.0);
TS_ASSERT_EQUALS(t_3x2(3,1), 0.5);
TS_ASSERT_EQUALS(t_3x2(3,2), 0.5);
}

void testLoadIndepVarFromXML() {
Expand Down Expand Up @@ -748,6 +818,43 @@ class FGTable2DTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(t_2x2.GetValue(), 0.125);
TS_ASSERT_EQUALS(output->getDoubleValue(), 0.125);
}

void testMonoticallyIncreasingRows() {
auto pm = make_shared<FGPropertyManager>();
// FGTable expects <table> to be the child of another XML element, hence the
// <dummy> element.
Element_ptr elm = readFromXML("<dummy>"
" <table name=\"test\" type=\"internal\">"
" <tableData>"
" 0.0 1.0\n"
" 2.0 3.0 -2.0\n"
" 2.0 2.5 -2.0\n"
" 4.0 -1.0 0.5\n"
" </tableData>"
" </table>"
"</dummy>");
Element* el_table = elm->FindElement("table");

TS_ASSERT_THROWS(FGTable t_3x2(pm, el_table), TableException&);
}

void testMonoticallyIncreasingColumns() {
auto pm = make_shared<FGPropertyManager>();
// FGTable expects <table> to be the child of another XML element, hence the
// <dummy> element.
Element_ptr elm = readFromXML("<dummy>"
" <table name=\"test\" type=\"internal\">"
" <tableData>"
" 0.0 1.0 1.0\n"
" 2.0 3.0 -2.0 1.0\n"
" 4.0 -1.0 0.5 0.75\n"
" </tableData>"
" </table>"
"</dummy>");
Element* el_table = elm->FindElement("table");

TS_ASSERT_THROWS(FGTable t_2x3(pm, el_table), TableException&);
}
};

class FGTable3DTest : public CxxTest::TestSuite
Expand Down

0 comments on commit d8f8107

Please sign in to comment.