00001 #include <boost/test/unit_test.hpp> 00002 #include "InvertedFileWriter.hpp" 00003 #include "ValueTypes.hpp" 00004 #include "Converter.hpp" 00005 #include "Record.hpp" 00006 #include <cstdlib> 00007 00008 using namespace aitools::invertedindex; 00009 00010 typedef InvertedFileWriter<ShortIntFloat> Writer; 00011 00012 BOOST_AUTO_TEST_SUITE(inverted_file_writer); 00013 00014 BOOST_AUTO_TEST_CASE(explicit_ctor) 00015 { 00016 bfs::path path("inverted-file.txt"); 00017 Writer writer(path); // does not throw exception 00018 writer.close(); 00019 bfs::remove(path); 00020 BOOST_CHECK_THROW(Writer("xyz" / path), std::invalid_argument); 00021 } 00022 00023 BOOST_AUTO_TEST_CASE(write) 00024 { 00025 Record<ShortIntFloat> record; 00026 record.value() = ShortIntFloat(1, 2, 3); 00027 bfs::path path("inverted-file.txt"); 00028 Writer writer(path); 00029 for (unsigned i(0); i != 100; ++i) 00030 { 00031 record.key() = Converter::ui32_to_str(std::rand() % 3); 00032 writer.write(record); 00033 } 00034 writer.close(); 00035 bfs::remove(path); 00036 } 00037 00038 BOOST_AUTO_TEST_SUITE_END();