forked from varoudis/depthmapX
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visprep #21
Merged
Visprep #21
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7123f3
Factor out grid min/max calculations to helper class + tests. Remove
blsemo 05b5be8
Command line mode to prepare for VGA (grid, fill and connectivity graph)
blsemo 5d92a01
Add parser to registry
blsemo b5da9ae
Rework from pull request review: Fix macro compilation on gcc and clang,
blsemo 730434f
Fix typo in expected exception message in unit test
blsemo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
// Copyright (C) 2017 Christian Sailer | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#include <catch.hpp> | ||
#include "depthmapXcli/visprepparser.h" | ||
#include "argumentholder.h" | ||
#include "selfcleaningfile.h" | ||
|
||
TEST_CASE("VisPrepParserFail", "Error cases") | ||
{ | ||
SECTION("Missing argument to pg") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pg", "-pp", "1.2,1.3"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-pg requires an argument")); | ||
} | ||
SECTION("Missing argument to pp") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pp"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-pp requires an argument")); | ||
} | ||
SECTION("Missing argument to pf") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pf", "-pg", "1.2"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-pf requires an argument")); | ||
} | ||
|
||
SECTION("Non-numeric input to -pg") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pg", "foo"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-pg must be a number >0, got foo")); | ||
} | ||
|
||
SECTION("rubbish input to -pp") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pp", "foo"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Invalid fill point provided (foo). Should only contain digits dots and commas")); | ||
} | ||
|
||
SECTION("Non-existing file provide") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pg", "0.1", "-pf", "foo.csv"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Failed to load file foo.csv, error")); | ||
} | ||
|
||
SECTION("Neiter points nor point file provided") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pg", "0.1"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Either -pp or -pf must be given")); | ||
} | ||
|
||
SECTION("No grid") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pp", "0.1,1"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Use -pg to define grid")); | ||
} | ||
|
||
SECTION("Points and pointfile provided") | ||
{ | ||
VisPrepParser parser; | ||
SelfCleaningFile scf("testpoints.csv"); | ||
{ | ||
std::ofstream f("testpoints.csv"); | ||
f << "x\ty\n1\t2\n" << std::flush; | ||
} | ||
ArgumentHolder ah{"prog", "-pg", "0.1", "-pp", "0.1,5.2", "-pf", "testpoints.csv"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-pf cannot be used together with -pp")); | ||
} | ||
|
||
SECTION("Pointfile and points provided") | ||
{ | ||
VisPrepParser parser; | ||
SelfCleaningFile scf("testpoints.csv"); | ||
{ | ||
std::ofstream f("testpoints.csv"); | ||
f << "x\ty\n1\t2\n" << std::flush; | ||
} | ||
ArgumentHolder ah{"prog", "-pg", "0.1", "-pf", "testpoints.csv", "-pp", "0.1,5.2"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-pp cannot be used together with -pf")); | ||
} | ||
|
||
SECTION("Malformed pointfile") | ||
{ | ||
VisPrepParser parser; | ||
SelfCleaningFile scf("testpoints.csv"); | ||
{ | ||
std::ofstream f("testpoints.csv"); | ||
f << "x\ty\n1\n" << std::flush; | ||
} | ||
ArgumentHolder ah{"prog", "-pg", "0.1", "-pf", "testpoints.csv"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Error parsing line: 1")); | ||
} | ||
|
||
SECTION("Malformed point arg") | ||
{ | ||
VisPrepParser parser; | ||
SelfCleaningFile scf("testpoints.csv"); | ||
{ | ||
std::ofstream f("testpoints.csv"); | ||
f << "x\ty\n1\n" << std::flush; | ||
} | ||
ArgumentHolder ah{"prog", "-pg", "0.1", "-pp", "0.1"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Error parsing line: 0.1")); | ||
} | ||
|
||
SECTION("Nonsensical visiblity restriction") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pr", "foo"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Restricted visibilyt of 'foo' makes no sense, use a positive number or -1 for unrestricted")); | ||
} | ||
|
||
SECTION("Nonsensical visiblity restriction") | ||
{ | ||
VisPrepParser parser; | ||
ArgumentHolder ah{"prog", "-pr", "0.0"}; | ||
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Restricted visibilyt of '0.0' makes no sense, use a positive number or -1 for unrestricted")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: visibilyt -> visibility |
||
} | ||
|
||
} | ||
|
||
TEST_CASE("VisprepParserSuccess", "Read successfully") | ||
{ | ||
VisPrepParser parser; | ||
double x1 = 1.0; | ||
double y1 = 2.0; | ||
double x2 = 1.1; | ||
double y2 = 1.2; | ||
double grid = 0.5; | ||
std::stringstream gstring; | ||
gstring << grid << std::flush; | ||
|
||
SECTION("Read from commandline") | ||
{ | ||
std::stringstream p1; | ||
p1 << x1 << "," << y1 << std::flush; | ||
std::stringstream p2; | ||
p2 << x2 << "," << y2 << std::flush; | ||
|
||
ArgumentHolder ah{"prog", "-pg", gstring.str(), "-pp", p1.str(), "-pp", p2.str(), "-pb", "-pr", "2.1"}; | ||
parser.parse(ah.argc(), ah.argv()); | ||
REQUIRE(parser.getBoundaryGraph()); | ||
REQUIRE(parser.getMaxVisibility() == Approx(2.1)); | ||
} | ||
|
||
SECTION("Read from file") | ||
{ | ||
SelfCleaningFile scf("testpoints.csv"); | ||
{ | ||
std::ofstream f(scf.Filename().c_str()); | ||
f << "x\ty\n" << x1 << "\t" << y1 << "\n" | ||
<< x2 << "\t" << y2 << "\n" << std::flush; | ||
} | ||
ArgumentHolder ah{"prog", "-pg", gstring.str(), "-pf", scf.Filename()}; | ||
parser.parse(ah.argc(), ah.argv() ); | ||
REQUIRE_FALSE(parser.getBoundaryGraph()); | ||
REQUIRE(parser.getMaxVisibility() == Approx(-1.0)); | ||
} | ||
|
||
REQUIRE(parser.getGrid() == Approx(grid)); | ||
auto points = parser.getFillPoints(); | ||
REQUIRE(points.size() == 2); | ||
REQUIRE(points[0].x == Approx(x1)); | ||
REQUIRE(points[0].y == Approx(y1)); | ||
REQUIRE(points[1].x == Approx(x2)); | ||
REQUIRE(points[1].y == Approx(y2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: visibilyt -> visibility