// (C) Copyright 2008-2009 SDML (www.sdml.info) // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include "test_words.hpp" using namespace std; using namespace gpld; int main(int argc, char **argv) { // Create a test prefix set. prefix_set test; cout << "Testing prefix sets." << endl; // Ensure that the set starts off empty. BOOST_ASSERT(test.empty()); // Insert some test words. typedef pair::iterator, bool> insert_result; for (unsigned int i = 0; i < test::words.size(); ++i) { cout << "Inserting " << test::words[i] << endl; insert_result insert = test.insert(test::words[i]); // Ensure that some insertion occurred. BOOST_ASSERT(insert.second != false); // Also test that finding the entry returns the same iterator // as the insertion. prefix_set::iterator it = test.find(test::words[i]); BOOST_ASSERT(it == insert.first); } // Assert that the size is correct. BOOST_ASSERT(test.size() == test::words.size()); // Try to insert some things that are already known to exist within the // tree. for (unsigned int i = 0; i < test::words.size(); ++i) { insert_result insert = test.insert(test::words[i]); // Ensure that no insertion occurred. BOOST_ASSERT(insert.second == false); } test.write(std::cout); /** @name Testing copies/moves. */ // Make a copy of the set. prefix_set test2 = test; BOOST_ASSERT(test2.size() == test.size()); test2.clear(); // Ensure that test2 is actually empty. BOOST_ASSERT(test2.empty()); BOOST_ASSERT(test2.size() == 0); // Test assignment. unsigned int size = test.size(); test2 = move(test); // And that test2 is test's old size. BOOST_ASSERT(test2.size() == size); /// @todo Curiously, the move assignment operator doesn't seem to be /// getting called. Neither does the move constructor. //BOOST_ASSERT(!test.size()); return 0; }