Skip to content
Snippets Groups Projects
Commit 6f6dc42e authored by d.kilic's avatar d.kilic
Browse files

Resolve "Empty lines in the height file"

- Ignore empty lines in height file
- Ignore empty lines in markerID file
parent 037bccec
No related branches found
No related tags found
1 merge request!208Resolve "Empty lines in the height file"
...@@ -114,6 +114,11 @@ std::variant<std::unordered_map<int, float>, std::string> IO::readHeightFile(con ...@@ -114,6 +114,11 @@ std::variant<std::unordered_map<int, float>, std::string> IO::readHeightFile(con
return "Duplicate entry for markerID = " + std::to_string(markerID) + "."; return "Duplicate entry for markerID = " + std::to_string(markerID) + ".";
} }
} }
else if(splitLine.empty())
{
// just ignore empty lines
continue;
}
else else
{ {
return "Line should contain exactly 2 values: id height. But it contains " + return "Line should contain exactly 2 values: id height. But it contains " +
...@@ -320,6 +325,11 @@ std::variant<std::unordered_map<int, int>, std::string> IO::readMarkerIDFile(con ...@@ -320,6 +325,11 @@ std::variant<std::unordered_map<int, int>, std::string> IO::readMarkerIDFile(con
return "Duplicate entry for personID = " + std::to_string(personID) + "."; return "Duplicate entry for personID = " + std::to_string(personID) + ".";
} }
} }
else if(splitLine.empty())
{
// ignore empty lines
continue;
}
else else
{ {
return "Line should contain exactly 2 values: personID markerID. But it contains " + return "Line should contain exactly 2 values: personID markerID. But it contains " +
......
...@@ -216,6 +216,41 @@ TEST_CASE("src/IO", "[tracking][io]") ...@@ -216,6 +216,41 @@ TEST_CASE("src/IO", "[tracking][io]")
CHECK_THAT(markerHeightsVec, Catch::UnorderedEquals(referenceValuesVec)); CHECK_THAT(markerHeightsVec, Catch::UnorderedEquals(referenceValuesVec));
} }
SECTION("empty line at end of file")
{
std::for_each(
std::begin(referenceValuesMap),
std::end(referenceValuesMap),
[&heightFile](const std::pair<int, float> &element)
{ heightFile << element.first << " " << element.second << std::endl; });
heightFile << std::endl;
heightFile.close();
auto ret = IO::readHeightFile(QString::fromStdString(heigtFileName));
REQUIRE(std::holds_alternative<std::unordered_map<int, float>>(ret));
std::unordered_map<int, float> markerHeights = std::get<std::unordered_map<int, float>>(ret);
std::vector<std::pair<int, float>> markerHeightsVec;
markerHeightsVec.assign(std::begin(markerHeights), std::end(markerHeights));
CHECK_THAT(markerHeightsVec, Catch::UnorderedEquals(referenceValuesVec));
}
SECTION("empty lines throughout the file")
{
std::for_each(
std::begin(referenceValuesMap),
std::end(referenceValuesMap),
[&heightFile](const std::pair<int, float> &element)
{ heightFile << element.first << " " << element.second << "\n\n"; });
heightFile.close();
auto ret = IO::readHeightFile(QString::fromStdString(heigtFileName));
REQUIRE(std::holds_alternative<std::unordered_map<int, float>>(ret));
std::unordered_map<int, float> markerHeights = std::get<std::unordered_map<int, float>>(ret);
std::vector<std::pair<int, float>> markerHeightsVec;
markerHeightsVec.assign(std::begin(markerHeights), std::end(markerHeights));
CHECK_THAT(markerHeightsVec, Catch::UnorderedEquals(referenceValuesVec));
}
SECTION("z-coordinate in cm") SECTION("z-coordinate in cm")
{ {
...@@ -463,6 +498,39 @@ TEST_CASE("src/IO", "[tracking][io]") ...@@ -463,6 +498,39 @@ TEST_CASE("src/IO", "[tracking][io]")
CHECK_THAT(markerHeightsVec, Catch::UnorderedEquals(referenceValuesVec)); CHECK_THAT(markerHeightsVec, Catch::UnorderedEquals(referenceValuesVec));
} }
SECTION("empty line at end of file")
{
for(const auto &[personID, markerID] : referenceValuesMap)
{
markerFile << personID << " " << markerID << std::endl;
}
markerFile << std::endl;
markerFile.close();
auto ret = IO::readMarkerIDFile(QString::fromStdString(markerFileName));
REQUIRE(std::holds_alternative<std::unordered_map<int, int>>(ret));
auto markerIDs = std::get<std::unordered_map<int, int>>(ret);
std::vector<std::pair<int, int>> markerHeightsVec;
markerHeightsVec.assign(std::begin(markerIDs), std::end(markerIDs));
CHECK_THAT(markerHeightsVec, Catch::UnorderedEquals(referenceValuesVec));
}
SECTION("empty lines throughout the file")
{
for(const auto &[personID, markerID] : referenceValuesMap)
{
markerFile << personID << " " << markerID << "\n\n";
}
markerFile.close();
auto ret = IO::readMarkerIDFile(QString::fromStdString(markerFileName));
REQUIRE(std::holds_alternative<std::unordered_map<int, int>>(ret));
auto markerIDs = std::get<std::unordered_map<int, int>>(ret);
std::vector<std::pair<int, int>> markerHeightsVec;
markerHeightsVec.assign(std::begin(markerIDs), std::end(markerIDs));
CHECK_THAT(markerHeightsVec, Catch::UnorderedEquals(referenceValuesVec));
}
SECTION("with comments") SECTION("with comments")
{ {
markerFile << "# this is a comment at the beginning" << std::endl; markerFile << "# this is a comment at the beginning" << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment