OKlibrary  0.2.1.6
ParsingResultSequences_Tests.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 3.6.2005 (Swansea)
00002 /* Copyright 2005 - 2007 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00008 #ifndef PARSINGRESULTSEQUENCESTESTS_k324RtG
00009 #define PARSINGRESULTSEQUENCESTESTS_k324RtG
00010 
00011 #include <string>
00012 
00013 #include <OKlib/TestSystem/TestBaseClass.hpp>
00014 #include <OKlib/TestSystem/TestExceptions.hpp>
00015 
00016 #include <OKlib/Programming/Parsing/ParserBase_Tests.hpp>
00017 
00018 #include <OKlib/Experimentation/Competition/SingleResult.hpp>
00019 #include <OKlib/Experimentation/Competition/ParsingSingleResult.hpp>
00020 #include <OKlib/Experimentation/Competition/ParsingResultSequences.hpp>
00021 #include <OKlib/Experimentation/Competition/ParsingSingleResult_Tests.hpp>
00022 
00023 namespace OKlib {
00024   namespace SATCompetition {
00025 
00026     template <class Container>
00027     class Test_Copy_results_fill_from_file : public ::OKlib::TestSystem::Test {
00028       const boost::filesystem::path filename;
00029       Container& C;
00030     public :
00031       typedef Test_Copy_results_fill_from_file test_type;
00032       Test_Copy_results_fill_from_file(const boost::filesystem::path& filename, Container& C) : filename(filename), C(C) {}
00033       typedef typename Container::value_type result_type;
00034     private :
00035       void perform_test_trivial() {
00036         typedef std::back_insert_iterator<Container> OutputIterator;
00037         typedef Copy_results_from_file<ParserResult, OutputIterator, result_type> Copy;
00038         typedef typename Copy::ParseIterator ParseIterator;
00039         OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingResult_Positional<ParseIterator>(Copy()(filename, std::back_inserter(C))));
00040       }
00041     };
00042     template <class Container>
00043     inline Test_Copy_results_fill_from_file<Container> test_Copy_results_fill_from_file(const boost::filesystem::path& filename, Container& C) {
00044       return Test_Copy_results_fill_from_file<Container>(filename, C);
00045     }
00046 
00047     // -----------------------------------------------------------------------------------------------------------------------------
00048     // -----------------------------------------------------------------------------------------------------------------------------
00049 
00050     class Test_Copy_results_ParserResult_Result_positive_cases : public ::OKlib::TestSystem::Test {
00051     public :
00052       typedef Test_Copy_results_ParserResult_Result_positive_cases test_type;
00053     private :
00054       void perform_test_trivial() {
00055         typedef ParserResult<Result> Parser;
00056         typedef std::list<Result> List_output;
00057         List_output output;
00058         typedef std::vector<TupleResult> Vector;
00059         Vector test_vector;
00060         add_positive_result_tuples(test_vector);
00061         std::stringstream input;
00062         std::copy(test_vector.begin(), test_vector.end(), std::ostream_iterator<TupleResult>(input, "\n"));
00063         if (not copy_results<Parser>(input.str().c_str(), std::back_inserter(output)).full)
00064           OKLIB_THROW("Sequence\n" + input.str() + "was not accepted.");
00065         if (output.size() != test_vector.size())
00066           OKLIB_THROW("Sequence size is " + boost::lexical_cast<std::string>(output.size()) + ", and not " + boost::lexical_cast<std::string>(test_vector.size()));
00067         Vector::size_type index = 0;
00068         for (List_output::const_iterator i = output.begin(); i != output.end(); ++i, ++index) {
00069           if (*i != test_vector[index]) {
00070             std::stringstream message;
00071             message << "Result \"" << *i << "\" different from input \"" << test_vector[index] << "\"";
00072             OKLIB_THROW(message.str());
00073           }
00074         }
00075       }
00076     };
00077 
00078     class Test_Copy_results_ParserResult_Result_negative_cases : public ::OKlib::TestSystem::Test {
00079     public :
00080       typedef Test_Copy_results_ParserResult_Result_negative_cases test_type;
00081     private :
00082       void perform_test_trivial() {
00083         typedef ParserResult<Result> Parser;
00084         typedef std::list<Result> List_output;
00085         List_output output;
00086         {
00087           typedef std::vector<std::string> Vector;
00088           Vector test_vector;
00089           
00090           test_vector.push_back("3SAT random/MediumSizeBenches/k3-r4.263-v300 bench1902 solver1 20 7.09 1319");
00091            test_vector.push_back("3SAT random/MediumSizeBenches/k3-r4.263-v300 bench1902 solver1 20 7.09 1319\n3SAT random/MediumSizeBenches/k3-r4.263-v300 bench1902 solver1 20 7.09 1319");
00092           for (Vector::const_iterator i = test_vector.begin(); i != test_vector.end(); ++i)
00093             if (copy_results<Parser>(i -> c_str(), std::back_inserter(output)).full)
00094               OKLIB_THROW("Sequence\n" + *i + "was accepted.");
00095         }
00096       }
00097     };
00098 
00099     const std::string filename_large_industrial = "Data/export-industrial_2005_Round1.txt";
00100     const unsigned int line_count_large_industrial = 17168;
00101 
00102     class Test_Copy_results_ParserResult_Result : public ::OKlib::TestSystem::TestBase {
00103     public :
00104       typedef Test_Copy_results_ParserResult_Result test_type;
00105       Test_Copy_results_ParserResult_Result() {
00106         insert(this);
00107       }
00108     private :
00109       void perform_test_trivial() {
00110         {
00111           OKLIB_TESTTRIVIAL_RETHROW(Test_Copy_results_ParserResult_Result_positive_cases());
00112           OKLIB_TESTTRIVIAL_RETHROW(Test_Copy_results_ParserResult_Result_negative_cases());
00113         }
00114         {
00115           // ToDo: This should belong to the more time-consuming testing.
00116           typedef std::list<Result> List_output;
00117           List_output output;
00118           OKLIB_TESTTRIVIAL_RETHROW(test_Copy_results_fill_from_file(filename_large_industrial, output));
00119           const List_output::size_type output_size = output.size();
00120           OKLIB_TEST_EQUAL(output_size, line_count_large_industrial);
00121         }
00122        }
00123     };
00124 
00125     // -----------------------------------------------------------------------------------------------------------------------------
00126     // -----------------------------------------------------------------------------------------------------------------------------
00127 
00128     class Test_Copy_results_ParserResultRandomSat_ResultRandomSat_positive_cases : public ::OKlib::TestSystem::Test {
00129     public :
00130       typedef Test_Copy_results_ParserResultRandomSat_ResultRandomSat_positive_cases test_type;
00131     private :
00132       void perform_test_trivial() {
00133         typedef ParserResult<ResultRandomSat> Parser;
00134         typedef std::list<ResultRandomSat> List_output;
00135         List_output output;
00136         typedef std::vector<TupleResultRandomSat> Vector;
00137         Vector test_vector;
00138         add_positive_result_tuples(test_vector);
00139         std::stringstream input;
00140         std::copy(test_vector.begin(), test_vector.end(), std::ostream_iterator<TupleResultRandomSat>(input, "\n"));
00141         if (not copy_results<Parser>(input.str().c_str(), std::back_inserter(output)).full)
00142           OKLIB_THROW("Sequence\n" + input.str() + "was not accepted.");
00143         if (output.size() != test_vector.size())
00144           OKLIB_THROW("Sequence size is " + boost::lexical_cast<std::string>(output.size()) + ", and not " + boost::lexical_cast<std::string>(test_vector.size()));
00145         Vector::size_type index = 0;
00146         for (List_output::const_iterator i = output.begin(); i != output.end(); ++i, ++index) {
00147           if (*i != test_vector[index]) {
00148             std::stringstream message;
00149             message << "ResultRandomSat \"" << *i << "\" different from input \"" << test_vector[index] << "\"";
00150             OKLIB_THROW(message.str());
00151           }
00152         }
00153       }
00154     };
00155 
00156     const std::string filename_large_random = "Data/export-random_2005_Round1_corrected.txt";
00157     const unsigned int line_count_large_random = 11700;
00158 
00159     class Test_Copy_results_ParserResultRandomSat_ResultRandomSat : public ::OKlib::TestSystem::TestBase {
00160     public :
00161       typedef Test_Copy_results_ParserResultRandomSat_ResultRandomSat test_type;
00162       Test_Copy_results_ParserResultRandomSat_ResultRandomSat() {
00163         insert(this);
00164       }
00165     private :
00166       void perform_test_trivial() {
00167         OKLIB_TESTTRIVIAL_RETHROW(Test_Copy_results_ParserResultRandomSat_ResultRandomSat_positive_cases());
00168         OKLIB_TESTTRIVIAL_RETHROW(Test_Copy_results_ParserResult_Result_negative_cases());
00169         {
00170           typedef std::list<ResultRandomSat> List_output;
00171           List_output output;
00172           OKLIB_TESTTRIVIAL_RETHROW(test_Copy_results_fill_from_file(filename_large_random, output));
00173           const List_output::size_type output_size = output.size();
00174           OKLIB_TEST_EQUAL(output_size, line_count_large_random);
00175         }
00176       }
00177     };
00178 
00179   }
00180 
00181 }
00182 
00183 #endif