-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from GIScience/feat/more-tests
feat: improve test setup
- Loading branch information
Showing
8 changed files
with
475 additions
and
55 deletions.
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 |
---|---|---|
@@ -1,52 +1,2 @@ | ||
#define BOOST_TEST_MODULE FirstPassHandler Test | ||
#include <boost/test/included/unit_test.hpp> | ||
#include <boost/regex.hpp> | ||
|
||
#include <osmium/osm/tag.hpp> | ||
#include <osmium/memory/buffer.hpp> | ||
#include <osmium/builder/osm_object_builder.hpp> | ||
|
||
#define private public | ||
#include "../firstpass_handler.h" | ||
#include "../location_area_service.h" | ||
|
||
|
||
BOOST_AUTO_TEST_CASE(test_has_no_relevant_tags) | ||
{ | ||
boost::regex remove_tags( | ||
"(.*:)?remove_1(:.*)?|remove_2", | ||
boost::regex::icase | ||
); | ||
osmium::nwr_array<osmium::index::IdSetDense<osmium::unsigned_object_id_type>> valid_ids; | ||
osmium::nwr_array<osmium::index::IdSetSmall<osmium::unsigned_object_id_type>> no_elevation; | ||
FirstPassHandler fph(remove_tags, valid_ids, no_elevation); | ||
|
||
// Create tag list with relevant and irrelevant tags | ||
osmium::memory::Buffer buf1{1024, osmium::memory::Buffer::auto_grow::yes}; | ||
osmium::builder::TagListBuilder tlb(buf1); | ||
tlb.add_tag("landuse","forest"); | ||
tlb.add_tag("railway", "platform"); | ||
osmium::TagList &tags_with_relevant_tags = buf1.get<osmium::TagList>(0); | ||
BOOST_TEST(fph.has_no_relevant_tags(tags_with_relevant_tags) == false); | ||
|
||
// Create tag list with only irrelevant tags | ||
osmium::memory::Buffer buf2{1024, osmium::memory::Buffer::auto_grow::yes}; | ||
osmium::builder::TagListBuilder tlb2(buf2); | ||
tlb2.add_tag("landuse","forest"); | ||
osmium::TagList &tags_without_relevant_tags = buf2.get<osmium::TagList>(0); | ||
BOOST_TEST(fph.has_no_relevant_tags(tags_without_relevant_tags) == true); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_location_area_service) | ||
{ | ||
std::string geo_type("wkt"); | ||
std::string prefix("mapping_"); | ||
LocationAreaService location_area_service(true, 0, 2, geo_type, true, prefix); | ||
location_area_service.load("test/mapping_test.csv"); | ||
|
||
osmium::Location location = osmium::Location(6.306152343750001, 50.05713877598692); | ||
std::vector<std::string> areas = location_area_service.get_area(location); | ||
|
||
BOOST_TEST(areas.size() == 1); | ||
BOOST_TEST(areas[0] == "DEU"); | ||
} | ||
#define BOOST_TEST_MODULE OSM-Transform Test | ||
#include <boost/test/included/unit_test.hpp> |
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,61 @@ | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <boost/regex.hpp> | ||
|
||
#include <osmium/osm/tag.hpp> | ||
#include <osmium/builder/osm_object_builder.hpp> | ||
#include <osmium/memory/buffer.hpp> | ||
#include <osmium/visitor.hpp> | ||
|
||
#define private public | ||
#include "../firstpass_handler.h" | ||
#include "test_utils.h" | ||
|
||
BOOST_AUTO_TEST_SUITE( test_first_pass ) | ||
|
||
BOOST_AUTO_TEST_CASE(test_has_no_relevant_tags) { | ||
boost::regex remove_tags( | ||
"(.*:)?remove_1(:.*)?|remove_2", | ||
boost::regex::icase); | ||
osmium::nwr_array<osmium::index::IdSetDense<osmium::unsigned_object_id_type>> valid_ids; | ||
osmium::nwr_array<osmium::index::IdSetSmall<osmium::unsigned_object_id_type>> no_elevation; | ||
FirstPassHandler handler(remove_tags, valid_ids, no_elevation); | ||
|
||
// Create tag list with relevant and irrelevant tags | ||
osmium::memory::Buffer buf1{1024, osmium::memory::Buffer::auto_grow::yes}; | ||
osmium::builder::TagListBuilder tlb(buf1); | ||
tlb.add_tag("landuse", "forest"); | ||
tlb.add_tag("railway", "platform"); | ||
auto &tags_with_relevant_tags = buf1.get<osmium::TagList>(0); | ||
BOOST_TEST(handler.has_no_relevant_tags(tags_with_relevant_tags) == false); | ||
|
||
// Create tag list with only irrelevant tags | ||
osmium::memory::Buffer buf2{1024, osmium::memory::Buffer::auto_grow::yes}; | ||
osmium::builder::TagListBuilder tlb2(buf2); | ||
tlb2.add_tag("landuse", "forest"); | ||
auto &tags_without_relevant_tags = buf2.get<osmium::TagList>(0); | ||
BOOST_TEST(handler.has_no_relevant_tags(tags_without_relevant_tags) == true); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(bla) { | ||
boost::regex remove_tags("(.*:)?source(:.*)?|(.*:)?note(:.*)?|url|created_by|fixme|wikipedia", boost::regex::icase); | ||
osmium::nwr_array<osmium::index::IdSetDense<osmium::unsigned_object_id_type>> valid_ids; | ||
osmium::nwr_array<osmium::index::IdSetSmall<osmium::unsigned_object_id_type>> no_elevation; | ||
FirstPassHandler handler(remove_tags, valid_ids, no_elevation); | ||
|
||
osmium::memory::Buffer buffer{1024, osmium::memory::Buffer::auto_grow::yes}; | ||
// add_node(buffer, 123, {{"troilo", "rafael"}, {"highway", "yes"}}, 8.6756824, 49.4184793); | ||
// add_node(buffer, 234, {{"troilo", "rafael"}, {"building", "bla"}}, 8.6756824, 49.4184793); | ||
add_way(buffer, 12, {{"highway","yes"}}, {123, 234}); | ||
buffer.commit(); | ||
|
||
osmium::apply(buffer, handler); | ||
BOOST_TEST(valid_ids.nodes().size() == 2); | ||
BOOST_TEST(valid_ids.ways().size() == 1); | ||
BOOST_TEST(valid_ids.nodes().get(123)); | ||
BOOST_TEST(valid_ids.nodes().get(234)); | ||
BOOST_TEST(valid_ids.ways().get(12)); | ||
|
||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
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,33 @@ | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "../location_area_service.h" | ||
|
||
BOOST_AUTO_TEST_SUITE( test_locacion_area ) | ||
BOOST_AUTO_TEST_CASE( test_location_area_service ) | ||
{ | ||
std::string geo_type("wkt"); | ||
std::string prefix("mapping_"); | ||
LocationAreaService location_area_service(true, 0, 2, geo_type, true, prefix); | ||
location_area_service.load("test/mapping_test.csv"); | ||
|
||
{ | ||
const auto areas = location_area_service.get_area(osmium::Location(6.306152343750001, 50.05713877598692)); | ||
BOOST_CHECK_EQUAL(areas.size(), 1); | ||
BOOST_CHECK_EQUAL(areas[0], "DEU"); | ||
} | ||
|
||
{ | ||
const auto areas = location_area_service.get_area(osmium::Location(6.0900938, 50.7225850)); | ||
BOOST_CHECK_EQUAL(areas.size(), 1); | ||
BOOST_CHECK_EQUAL(areas[0], "DEU"); | ||
} | ||
|
||
{ | ||
const auto areas = location_area_service.get_area(osmium::Location(6.0902180, 50.7220057)); | ||
BOOST_CHECK_EQUAL(areas.size(), 1); | ||
BOOST_CHECK_EQUAL(areas[0], "BEL"); | ||
} | ||
|
||
|
||
} | ||
BOOST_AUTO_TEST_SUITE_END() |
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,31 @@ | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "../location_elevation_service.h" | ||
|
||
BOOST_AUTO_TEST_SUITE( test_locacion_elevation ) | ||
BOOST_AUTO_TEST_CASE( test_lookup ) { | ||
|
||
LocationElevationService location_elevation_service(1 << 20, false); | ||
location_elevation_service.load({"files/limburg_an_der_lahn.tif"}); | ||
|
||
double ele = ((int)(location_elevation_service.elevation(osmium::Location(8.0513629, 50.3876977), false)*100))/100.0; | ||
BOOST_CHECK_EQUAL(ele, 163.81); | ||
|
||
} | ||
|
||
BOOST_AUTO_TEST_CASE( test_interpolate ) { | ||
|
||
LocationElevationService location_elevation_service(1 << 20, false); | ||
location_elevation_service.load({"files/limburg_an_der_lahn.tif"}); | ||
|
||
auto interpolated = location_elevation_service.interpolate(osmium::Location(8.0515393,50.3873984), osmium::Location(8.0505023, 50.3868868)); | ||
BOOST_CHECK_EQUAL(interpolated.size(), 14); | ||
for (const auto& le : interpolated) { | ||
auto location = le.location; | ||
auto ele = le.ele; | ||
std::cout << std::setprecision (8) << location.lon() << "," << location.lat() << "," << ele << "\n"; | ||
} | ||
|
||
|
||
} | ||
BOOST_AUTO_TEST_SUITE_END() |
Oops, something went wrong.