libmoost
|
00001 /* vim:set ts=3 sw=3 sts=3 et: */ 00028 #include <boost/test/unit_test.hpp> 00029 #include <boost/test/test_tools.hpp> 00030 00031 #include <vector> 00032 #include "../../include/moost/container/geo_map.hpp" 00033 00034 using namespace moost::container; 00035 00036 BOOST_AUTO_TEST_SUITE( geo_map_test ) 00037 00038 struct Fixture 00039 { 00040 geo_map<int> table; 00041 geo_map<int>::location query1; 00042 geo_map<int>::location query2; 00043 std::vector< geo_map<int>::value_type > results; 00044 00045 Fixture() 00046 : query1(-20.3F, 40.9F), 00047 query2(-19.9F, 48.4F) 00048 { 00049 // add some test data 00050 table.insert(geo_map<int>::value_type(geo_map<int>::location(-20.1F, 45.3F), 1)); 00051 table.insert(geo_map<int>::value_type(geo_map<int>::location(-20.1F, 48.3F), 2)); 00052 table.insert(geo_map<int>::value_type(geo_map<int>::location(13.3F, -12.0F), 3)); 00053 00054 geo_map<int>::const_iterator it = table.begin(); 00055 BOOST_CHECK(it != table.end()); 00056 } 00057 }; 00058 00059 // what happens when we search something empty? 00060 BOOST_FIXTURE_TEST_CASE( test_empty, Fixture ) 00061 { 00062 table.clear(); 00063 table.find(query1, 100.0F, std::back_inserter(results)); 00064 00065 BOOST_CHECK(results.empty()); 00066 } 00067 00068 // find nothing! 00069 BOOST_FIXTURE_TEST_CASE( test_not_found, Fixture ) 00070 { 00071 table.find(query1, 100.0F, std::back_inserter(results)); 00072 00073 BOOST_CHECK(results.empty()); 00074 } 00075 00076 // find something! 00077 BOOST_FIXTURE_TEST_CASE( test_found, Fixture ) 00078 { 00079 table.find(query1, 460.0F, std::back_inserter(results)); 00080 00081 BOOST_REQUIRE_EQUAL(results.size(), 1); 00082 BOOST_CHECK(results[0].second == 1); 00083 } 00084 00085 // find nothing! (bounds search) 00086 BOOST_FIXTURE_TEST_CASE( test_not_found_bounding, Fixture ) 00087 { 00088 table.find(query1, query1, std::back_inserter(results)); 00089 00090 BOOST_CHECK(results.empty()); 00091 } 00092 00093 // find something! (bounds search) 00094 BOOST_FIXTURE_TEST_CASE( test_found_bounding, Fixture ) 00095 { 00096 table.find(query1, query2, std::back_inserter(results)); 00097 00098 BOOST_REQUIRE_EQUAL(results.size(), 2); 00099 BOOST_CHECK(results[0].second == 1); 00100 BOOST_CHECK(results[1].second == 2); 00101 } 00102 00103 BOOST_AUTO_TEST_SUITE_END()