00001 #include <boost/test/unit_test.hpp> 00002 #include "InvertedFileReader.hpp" 00003 #include "InvertedFileWriter.hpp" 00004 #include "ValueTypes.hpp" 00005 #include "Converter.hpp" 00006 #include "Record.hpp" 00007 #include <cstdlib> 00008 00009 using namespace aitools::invertedindex; 00010 00011 typedef InvertedFileReader<ShortIntFloat> Reader; 00012 typedef InvertedFileWriter<ShortIntFloat> Writer; 00013 00014 BOOST_AUTO_TEST_SUITE(inverted_file_reader); 00015 00016 BOOST_AUTO_TEST_CASE(explicit_ctor) 00017 { 00018 bfs::path path("inverted-file.txt"); 00019 Writer writer(path); 00020 writer.close(); 00021 Reader reader(path); // does not throw exception 00022 bfs::remove(path); 00023 // BOOST_CHECK_THROW(Reader("xyz" / path), std::ifstream::failure); // problem 00024 } 00025 00026 BOOST_AUTO_TEST_CASE(read) 00027 { 00028 ShortIntFloat value(1, 2, 3); 00029 Record<ShortIntFloat> record; 00030 record.value() = value; 00031 bfs::path path("inverted-file.txt"); 00032 Writer writer(path); 00033 for (unsigned i(0); i != 100; ++i) 00034 { 00035 record.key() = Converter::ui32_to_str(i); 00036 writer.write(record); 00037 } 00038 writer.close(); 00039 Reader reader(path); 00040 for (unsigned i(0); i != 100; ++i) 00041 { 00042 BOOST_CHECK(reader.next(record)); 00043 BOOST_CHECK_EQUAL(record.key(), Converter::ui32_to_str(i)); 00044 BOOST_CHECK_EQUAL(record.value(), value); 00045 } 00046 reader.close(); 00047 bfs::remove(path); 00048 } 00049 00050 BOOST_AUTO_TEST_SUITE_END();