OKlibrary  0.2.1.6
ParsingSingleResult_Tests.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 13.5.2005 (Swansea)
00002 /* Copyright 2005 - 2007, 2009 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 PARSINGSINGLERESULTTESTS_k33wQQl
00009 #define PARSINGSINGLERESULTTESTS_k33wQQl
00010 
00011 #include <sstream>
00012 #include <string>
00013 #include <vector>
00014 #include <utility>
00015 #include <algorithm>
00016 #include <iterator>
00017 #include <list>
00018 #include <fstream>
00019 
00020 #include <boost/spirit/include/classic_core.hpp>
00021 #include <boost/lexical_cast.hpp>
00022 #include <boost/tuple/tuple.hpp>
00023 #include <boost/spirit/include/classic_file_iterator.hpp>
00024 #include <boost/spirit/include/classic_position_iterator.hpp>
00025 #include <boost/filesystem/path.hpp>
00026 
00027 #include <OKlib/TestSystem/TestBaseClass.hpp>
00028 #include <OKlib/TestSystem/TestExceptions.hpp>
00029 
00030 #include <OKlib/Programming/Parsing/ParserBase_Tests.hpp>
00031 
00032 #include <OKlib/Experimentation/Competition/SingleResult.hpp>
00033 #include <OKlib/Experimentation/Competition/ParsingSingleResult.hpp>
00034 
00035 namespace OKlib {
00036   namespace SATCompetition {
00037 
00038     template <class SuperSeries>
00039     class Test_ParserResultElement_SuperSeries_positive_cases : public ::OKlib::TestSystem::Test {
00040       // ToDo: Also the parser should be a template (template) parameter
00041     public :
00042       typedef Test_ParserResultElement_SuperSeries_positive_cases test_type;
00043     private :
00044       void perform_test_trivial() {
00045         SuperSeries s;
00046         typedef ParserResultElement<SuperSeries> Parser;
00047         Parser p(s);
00048         {
00049           const std::string test = "abc123ABC";
00050           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00051           if(s.name() != test)
00052             OKLIB_THROW("Resulting name is " + s.name() + ", and not " + test);
00053         }
00054       }
00055     };
00056     template <class SuperSeries>
00057     class Test_ParserResultElement_SuperSeries_negative_cases : public ::OKlib::TestSystem::Test {
00058     public :
00059       typedef Test_ParserResultElement_SuperSeries_negative_cases test_type;
00060     private :
00061       void perform_test_trivial() {
00062         SuperSeries s;
00063         typedef ParserResultElement<SuperSeries> Parser;
00064         Parser p(s);
00065         {
00066           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "   123ABC456", ::OKlib::Parser::match_not_full));
00067           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "468xyz1i   ", ::OKlib::Parser::match_not_full));
00068           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "", ::OKlib::Parser::match_not_full));
00069           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "a%b", ::OKlib::Parser::match_not_full));
00070         }
00071        }
00072     };
00073 
00074     template <class SuperSeries>
00075     class Test_ParserResultElement_SuperSeries : public ::OKlib::TestSystem::TestBase {
00076     public :
00077       typedef Test_ParserResultElement_SuperSeries test_type;
00078       Test_ParserResultElement_SuperSeries() {
00079         insert(this);
00080       }
00081     private :
00082       void perform_test_trivial() {
00083         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_SuperSeries_positive_cases<SuperSeries>());
00084         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_SuperSeries_negative_cases<SuperSeries>());
00085        }
00086     };
00087 
00088     // -----------------------------------------------------------------------------------------------------------------------------
00089 
00090     template <class RandomKSat>
00091     class Test_ParserResultElement_RandomKSat_positive_cases : public ::OKlib::TestSystem::Test {
00092     public :
00093       typedef Test_ParserResultElement_RandomKSat_positive_cases test_type;
00094     private :
00095       void perform_test_trivial() {
00096         RandomKSat s;
00097         typedef ParserResultElement<RandomKSat> Parser;
00098         Parser p(s);
00099         {
00100           typedef typename RandomKSat::natural_number_type natural_number_type;
00101           typedef std::vector<natural_number_type> Test_vector;
00102           Test_vector tv;
00103           tv.push_back(3); tv.push_back(10);
00104           for (typename Test_vector::const_iterator i = tv.begin(); i != tv.end(); ++i) {
00105             const natural_number_type k = *i;
00106             const std::string k_string(boost::lexical_cast<std::string>(k));
00107             const std::string test = k_string + "SAT";
00108             OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00109             if(s.name() != test)
00110               OKLIB_THROW("Resulting name is " + s.name() + ", and not " + test);
00111             if (s.clause_length() != k)
00112               OKLIB_THROW("Clause length is " + boost::lexical_cast<std::string>(s.clause_length()) + ", and not " + k_string);
00113           }
00114         }
00115       }
00116     };
00117     template <class RandomKSat>
00118     class Test_ParserResultElement_RandomKSat_negative_cases : public ::OKlib::TestSystem::Test {
00119     public :
00120       typedef Test_ParserResultElement_RandomKSat_negative_cases test_type;
00121     private :
00122       void perform_test_trivial() {
00123         RandomKSat s;
00124         typedef ParserResultElement<RandomKSat> Parser;
00125         Parser p(s);
00126         {
00127           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "SAT", ::OKlib::Parser::match_not_full));
00128           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "123SAT", ::OKlib::Parser::match_not_full));
00129           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "12SA", ::OKlib::Parser::match_not_full));
00130         }
00131       }
00132     };
00133 
00134     template <class RandomKSat>
00135     class Test_ParserResultElement_RandomKSat : public ::OKlib::TestSystem::TestBase {
00136     public :
00137       typedef Test_ParserResultElement_RandomKSat test_type;
00138       Test_ParserResultElement_RandomKSat() {
00139         insert(this);
00140       }
00141     private :
00142       void perform_test_trivial() {
00143         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_SuperSeries_negative_cases<RandomKSat>());
00144         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_RandomKSat_positive_cases<RandomKSat>());
00145         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_RandomKSat_negative_cases<RandomKSat>());
00146       }
00147     };
00148 
00149     // -----------------------------------------------------------------------------------------------------------------------------
00150 
00151     template <class Series>
00152     class Test_ParserResultElement_Series_positive_cases : public ::OKlib::TestSystem::Test {
00153     public :
00154       typedef Test_ParserResultElement_Series_positive_cases test_type;
00155     private :
00156       void perform_test_trivial() {
00157         Series s;
00158         typedef ParserResultElement<Series> Parser;
00159         Parser p(s);
00160         {
00161           const std::string test = "09/y-i/A/xXyY1";
00162           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00163           if(s.name() != test)
00164             OKLIB_THROW("Resulting name is " + s.name() + ", and not " + test);
00165         }
00166       }
00167     };
00168     template <class Series>
00169     class Test_ParserResultElement_Series_negative_cases : public ::OKlib::TestSystem::Test {
00170     public :
00171       typedef Test_ParserResultElement_Series_negative_cases test_type;
00172     private :
00173       void perform_test_trivial() {
00174         Series s;
00175         typedef ParserResultElement<Series> Parser;
00176         Parser p(s);
00177         {
00178           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "   A/B", ::OKlib::Parser::match_not_full));
00179           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "x", ::OKlib::Parser::match_not_full));
00180           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "x/", ::OKlib::Parser::match_not_full));
00181           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "", ::OKlib::Parser::match_not_full));
00182           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "a%/b", ::OKlib::Parser::match_not_full));
00183           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "a/b ", ::OKlib::Parser::match_not_full));
00184         }
00185        }
00186     };
00187 
00188     template <class Series>
00189     class Test_ParserResultElement_Series : public ::OKlib::TestSystem::TestBase {
00190     public :
00191       typedef Test_ParserResultElement_Series test_type;
00192       Test_ParserResultElement_Series() {
00193         insert(this);
00194       }
00195     private :
00196       void perform_test_trivial() {
00197         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_Series_positive_cases<Series>());
00198         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_Series_negative_cases<Series>());
00199        }
00200     };
00201 
00202     // -----------------------------------------------------------------------------------------------------------------------------
00203 
00204     template <class RandomKSat_n>
00205     class Test_ParserResultElement_RandomKSat_n_positive_cases : public ::OKlib::TestSystem::Test {
00206     public :
00207       typedef Test_ParserResultElement_RandomKSat_n_positive_cases test_type;
00208     private :
00209       void perform_test_trivial() {
00210         RandomKSat_n s;
00211         typedef ParserResultElement<RandomKSat_n> Parser;
00212         Parser p(s);
00213         {
00214           typedef typename RandomKSat_n::natural_number_type natural_number_type;
00215           typedef std::pair<std::string, natural_number_type> Pair;
00216           typedef std::vector<Pair> Vector;
00217           Vector test_vector;
00218           test_vector.push_back(Pair("random/MediumSizeBenches/k3-r4.263-v", 300));
00219           test_vector.push_back(Pair("random/MediumSizeBenches/k3-v7-r4.263-v", 20));
00220           test_vector.push_back(Pair("random/MediumSizeBenches/k3-v7-r4.263---v", 20));
00221           for (typename Vector::const_iterator i = test_vector.begin(); i != test_vector.end(); ++i) {
00222             const natural_number_type n = i -> second;
00223             const std::string test_n =  boost::lexical_cast<std::string>(n);
00224             const std::string test = i -> first + test_n;
00225             OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00226             if(s.name() != test)
00227               OKLIB_THROW("Resulting name is " + s.name() + ", and not " + test);
00228             if (s.count_variables() != n)
00229               OKLIB_THROW("Variables count is " + boost::lexical_cast<std::string>(s.count_variables()) + ", and not " + test_n);
00230           }
00231         }
00232       }
00233     };
00234     template <class RandomKSat_n>
00235     class Test_ParserResultElement_RandomKSat_n_negative_cases : public ::OKlib::TestSystem::Test {
00236     public :
00237       typedef Test_ParserResultElement_RandomKSat_n_negative_cases test_type;
00238     private :
00239       void perform_test_trivial() {
00240         RandomKSat_n s;
00241         typedef ParserResultElement<RandomKSat_n> Parser;
00242         Parser p(s);
00243         {
00244           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "A/B", ::OKlib::Parser::match_not_full));
00245           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "A/Bv", ::OKlib::Parser::match_not_full));
00246           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "X/-7", ::OKlib::Parser::match_not_full));
00247           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "hh0/-v", ::OKlib::Parser::match_not_full));
00248           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "a/b-vy", ::OKlib::Parser::match_not_full));
00249           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "a/b-v100 ", ::OKlib::Parser::match_not_full));
00250           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "random/MediumSizeBenches/k3-v7-r4.263--v300", ::OKlib::Parser::match_not_full));
00251           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "random/MediumSizeBenches/-v100-v300", ::OKlib::Parser::match_not_full));
00252         }
00253        }
00254     };
00255 
00256     template <class RandomKSat_n>
00257     class Test_ParserResultElement_RandomKSat_n : public ::OKlib::TestSystem::TestBase {
00258     public :
00259       typedef Test_ParserResultElement_RandomKSat_n test_type;
00260       Test_ParserResultElement_RandomKSat_n() {
00261         insert(this);
00262       }
00263     private :
00264       void perform_test_trivial() {
00265         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_RandomKSat_n_positive_cases<RandomKSat_n>());
00266         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_Series_negative_cases<RandomKSat_n>());
00267         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_RandomKSat_n_negative_cases<RandomKSat_n>());
00268        }
00269     };
00270 
00271     // -----------------------------------------------------------------------------------------------------------------------------
00272 
00273     template <class Benchmark>
00274     class Test_ParserResultElement_Benchmark_positive_cases : public ::OKlib::TestSystem::Test {
00275     public :
00276       typedef Test_ParserResultElement_Benchmark_positive_cases test_type;
00277     private :
00278       void perform_test_trivial() {
00279         Benchmark s;
00280         typedef ParserResultElement<Benchmark> Parser;
00281         Parser p(s);
00282         {
00283           const std::string test = "bench123";
00284           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00285           if(s.name() != test)
00286             OKLIB_THROW("Resulting name is " + s.name() + ", and not " + test);
00287         }
00288       }
00289     };
00290     template <class Benchmark>
00291     class Test_ParserResultElement_Benchmark_negative_cases : public ::OKlib::TestSystem::Test {
00292     public :
00293       typedef Test_ParserResultElement_Benchmark_negative_cases test_type;
00294     private :
00295       void perform_test_trivial() {
00296         Benchmark s;
00297         typedef ParserResultElement<Benchmark> Parser;
00298         Parser p(s);
00299         {
00300           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "   bench123", ::OKlib::Parser::match_not_full));
00301           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "bench123   ", ::OKlib::Parser::match_not_full));
00302           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "", ::OKlib::Parser::match_not_full));
00303           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "bench123l", ::OKlib::Parser::match_not_full));
00304         }
00305        }
00306     };
00307 
00308     template <class Benchmark>
00309     class Test_ParserResultElement_Benchmark : public ::OKlib::TestSystem::TestBase {
00310     public :
00311       typedef Test_ParserResultElement_Benchmark test_type;
00312       Test_ParserResultElement_Benchmark() {
00313         insert(this);
00314       }
00315     private :
00316       void perform_test_trivial() {
00317         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_Benchmark_positive_cases<Benchmark>());
00318         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_Benchmark_negative_cases<Benchmark>());
00319        }
00320     };
00321 
00322     // -----------------------------------------------------------------------------------------------------------------------------
00323 
00324     template <class Solver>
00325     class Test_ParserResultElement_Solver_positive_cases : public ::OKlib::TestSystem::Test {
00326     public :
00327       typedef Test_ParserResultElement_Solver_positive_cases test_type;
00328     private :
00329       void perform_test_trivial() {
00330         Solver s;
00331         typedef ParserResultElement<Solver> Parser;
00332         Parser p(s);
00333         {
00334           const std::string test = "solver123";
00335           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00336           if(s.name() != test)
00337             OKLIB_THROW("Resulting name is " + s.name() + ", and not " + test);
00338         }
00339       }
00340     };
00341     template <class Solver>
00342     class Test_ParserResultElement_Solver_negative_cases : public ::OKlib::TestSystem::Test {
00343     public :
00344       typedef Test_ParserResultElement_Solver_negative_cases test_type;
00345     private :
00346       void perform_test_trivial() {
00347         Solver s;
00348         typedef ParserResultElement<Solver> Parser;
00349         Parser p(s);
00350         {
00351           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "   solver123", ::OKlib::Parser::match_not_full));
00352           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "solver123   ", ::OKlib::Parser::match_not_full));
00353           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "", ::OKlib::Parser::match_not_full));
00354           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "solver123l", ::OKlib::Parser::match_not_full));
00355         }
00356        }
00357     };
00358 
00359     template <class Solver>
00360     class Test_ParserResultElement_Solver : public ::OKlib::TestSystem::TestBase {
00361     public :
00362       typedef Test_ParserResultElement_Solver test_type;
00363       Test_ParserResultElement_Solver() {
00364         insert(this);
00365       }
00366     private :
00367       void perform_test_trivial() {
00368         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_Solver_positive_cases<Solver>());
00369         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_Solver_negative_cases<Solver>());
00370        }
00371     };
00372 
00373     // -----------------------------------------------------------------------------------------------------------------------------
00374 
00375     template <class SATStatus>
00376     class Test_ParserResultElement_SATStatus_positive_cases : public ::OKlib::TestSystem::Test {
00377     public :
00378       typedef Test_ParserResultElement_SATStatus_positive_cases test_type;
00379     private :
00380       void perform_test_trivial() {
00381         SATStatus s;
00382         typedef ParserResultElement<SATStatus> Parser;
00383         Parser p(s);
00384         {
00385           typedef std::pair<std::string, SolverResult> Pair;
00386           typedef std::vector<Pair> Vector;
00387           Vector test_vector;
00388           test_vector.push_back(Pair("0", unknown));
00389           test_vector.push_back(Pair("10", sat));
00390           test_vector.push_back(Pair("20", unsat));
00391            test_vector.push_back(Pair("1", error));
00392           for (Vector::const_iterator i = test_vector.begin(); i != test_vector.end(); ++i) {
00393             
00394             const std::string test = i -> first;
00395             const SolverResult result = i -> second;
00396             OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00397             OKLIB_TEST_EQUAL(s.result(), result);
00398           }
00399         }
00400       }
00401     };
00402     template <class SATStatus>
00403     class Test_ParserResultElement_SATStatus_negative_cases : public ::OKlib::TestSystem::Test {
00404     public :
00405       typedef Test_ParserResultElement_SATStatus_negative_cases test_type;
00406     private :
00407       void perform_test_trivial() {
00408         SATStatus s;
00409         typedef ParserResultElement<SATStatus> Parser;
00410         Parser p(s);
00411         {
00412           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "   0", ::OKlib::Parser::match_not_full));
00413           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "10   ", ::OKlib::Parser::match_not_full));
00414           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "", ::OKlib::Parser::match_not_full));
00415           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "x", ::OKlib::Parser::match_not_full));
00416         }
00417        }
00418     };
00419 
00420     template <class SATStatus>
00421     class Test_ParserResultElement_SATStatus : public ::OKlib::TestSystem::TestBase {
00422     public :
00423       typedef Test_ParserResultElement_SATStatus test_type;
00424       Test_ParserResultElement_SATStatus() {
00425         insert(this);
00426       }
00427     private :
00428       void perform_test_trivial() {
00429         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_SATStatus_positive_cases<SATStatus>());
00430         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_SATStatus_negative_cases<SATStatus>());
00431        }
00432     };
00433 
00434     // -----------------------------------------------------------------------------------------------------------------------------
00435 
00436     template <class AverageTime>
00437     class Test_ParserResultElement_AverageTime_positive_cases : public ::OKlib::TestSystem::Test {
00438     public :
00439       typedef Test_ParserResultElement_AverageTime_positive_cases test_type;
00440     private :
00441       void perform_test_trivial() {
00442         AverageTime s;
00443         typedef ParserResultElement<AverageTime> Parser;
00444         Parser p(s);
00445         {
00446           typedef std::vector<std::string> Vector;
00447           Vector test_vector;
00448           test_vector.push_back("0.0");
00449           test_vector.push_back("0.1");
00450           test_vector.push_back("20.2");
00451           test_vector.push_back("10E3");
00452           test_vector.push_back("100");
00453           for (Vector::const_iterator i = test_vector.begin(); i != test_vector.end(); ++i) {
00454             const std::string test = *i;
00455             typedef typename AverageTime::floating_point_type floating_point_type;
00456             const floating_point_type average = boost::lexical_cast<floating_point_type>(test);
00457             OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00458             if(s.average() != average)
00459               OKLIB_THROW("Average is " + boost::lexical_cast<std::string>(s.average()) + ", and not " + boost::lexical_cast<std::string>(average));
00460           }
00461         }
00462       }
00463     };
00464     template <class AverageTime>
00465     class Test_ParserResultElement_AverageTime_negative_cases : public ::OKlib::TestSystem::Test {
00466     public :
00467       typedef Test_ParserResultElement_AverageTime_negative_cases test_type;
00468     private :
00469       void perform_test_trivial() {
00470         AverageTime s;
00471         typedef ParserResultElement<AverageTime> Parser;
00472         Parser p(s);
00473         {
00474           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "   0.1", ::OKlib::Parser::match_not_full));
00475           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "10.0   ", ::OKlib::Parser::match_not_full));
00476           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "", ::OKlib::Parser::match_not_full));
00477           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "x", ::OKlib::Parser::match_not_full));
00478           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "+11.1", ::OKlib::Parser::match_not_full));
00479         }
00480        }
00481     };
00482 
00483     template <class AverageTime>
00484     class Test_ParserResultElement_AverageTime : public ::OKlib::TestSystem::TestBase {
00485     public :
00486       typedef Test_ParserResultElement_AverageTime test_type;
00487       Test_ParserResultElement_AverageTime() {
00488         insert(this);
00489       }
00490     private :
00491       void perform_test_trivial() {
00492         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_AverageTime_positive_cases<AverageTime>());
00493         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_AverageTime_negative_cases<AverageTime>());
00494        }
00495     };
00496 
00497     // -----------------------------------------------------------------------------------------------------------------------------
00498 
00499     template <class TimeOut>
00500     class Test_ParserResultElement_TimeOut_positive_cases : public ::OKlib::TestSystem::Test {
00501     public :
00502       typedef Test_ParserResultElement_TimeOut_positive_cases test_type;
00503     private :
00504       void perform_test_trivial() {
00505         TimeOut s;
00506         typedef ParserResultElement<TimeOut> Parser;
00507         Parser p(s);
00508         {
00509           typedef std::vector<std::string> Vector;
00510           Vector test_vector;
00511           test_vector.push_back("0");
00512           test_vector.push_back("1");
00513           test_vector.push_back("1200");
00514           for (Vector::const_iterator i = test_vector.begin(); i != test_vector.end(); ++i) {
00515             const std::string test = *i;
00516             typedef typename TimeOut::natural_number_type natural_number_type;
00517             const natural_number_type time_out = boost::lexical_cast<natural_number_type>(test);
00518             OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00519             if(s.time_out() != time_out)
00520               OKLIB_THROW("Time_Out is " + boost::lexical_cast<std::string>(s.time_out()) + ", and not " + boost::lexical_cast<std::string>(time_out));
00521           }
00522         }
00523       }
00524     };
00525     template <class TimeOut>
00526     class Test_ParserResultElement_TimeOut_negative_cases : public ::OKlib::TestSystem::Test {
00527     public :
00528       typedef Test_ParserResultElement_TimeOut_negative_cases test_type;
00529     private :
00530       void perform_test_trivial() {
00531         TimeOut s;
00532         typedef ParserResultElement<TimeOut> Parser;
00533         Parser p(s);
00534         {
00535           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "   0", ::OKlib::Parser::match_not_full));
00536           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "10   ", ::OKlib::Parser::match_not_full));
00537           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "", ::OKlib::Parser::match_not_full));
00538           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "x", ::OKlib::Parser::match_not_full));
00539           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "+11", ::OKlib::Parser::match_not_full));
00540           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "100.0", ::OKlib::Parser::match_not_full));
00541         }
00542        }
00543     };
00544 
00545     template <class TimeOut>
00546     class Test_ParserResultElement_TimeOut : public ::OKlib::TestSystem::TestBase {
00547     public :
00548       typedef Test_ParserResultElement_TimeOut test_type;
00549       Test_ParserResultElement_TimeOut() {
00550         insert(this);
00551       }
00552     private :
00553       void perform_test_trivial() {
00554         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_TimeOut_positive_cases<TimeOut>());
00555         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResultElement_TimeOut_negative_cases<TimeOut>());
00556        }
00557     };
00558 
00559     // -----------------------------------------------------------------------------------------------------------------------------
00560     // -----------------------------------------------------------------------------------------------------------------------------
00561 
00562     template <class Container, class TupleType>
00563     struct Add_positive_result_tuples;
00564 
00565     template <class Container>
00566     struct Add_positive_result_tuples<Container, TupleResult> {
00567       void operator() (Container& C) {
00568         typedef ResultElement::floating_point_type floating_point_type;
00569         typedef ResultElement::natural_number_type natural_number_type;
00570         C.push_back(TupleResult(std::string("SAT04"), std::string("crafted/sat04/gomes03"), std::string("bench432"), std::string("solver1"), unknown, floating_point_type(1200), natural_number_type(1200)));
00571         C.push_back(TupleResult(std::string("zarpas-s"), std::string("industrial/zarpas05/01"), std::string("bench1353"), std::string("solver34"), sat, floating_point_type(409.69), natural_number_type(1200)));
00572         C.push_back(TupleResult(std::string("3SAT"), std::string("random/MediumSizeBenches/k3-r4.263-v300"), std::string("bench1902"), std::string("solver1"), unsat, floating_point_type(6.65), natural_number_type(1200)));
00573         C.push_back(TupleResult(std::string("3SAT"), std::string("random/MediumSizeBenches/k3-r4.263-v300"), std::string("bench1903"), std::string("solver5"), unsat, floating_point_type(7), natural_number_type(1300)));
00574       }
00575     };
00576 
00577     template <class Container>
00578     struct Add_positive_result_tuples<Container, TupleResultRandomSat> {
00579       void operator() (Container& C) {
00580         typedef ResultElement::floating_point_type floating_point_type;
00581         typedef ResultElement::natural_number_type natural_number_type;
00582         C.push_back(TupleResultRandomSat(RandomKSat("3SAT", 3), RandomKSat_n("random/MediumSizeBenches/k3-r4.263-v300", 300), std::string("bench1902"), std::string("solver1"), unsat, floating_point_type(6.65), natural_number_type(1200)));
00583       C.push_back(TupleResultRandomSat(RandomKSat("7SAT", 7), RandomKSat_n("random/LargeSizeBenches/k7-r85-v160", 160), std::string("bench1603"), std::string("solver16"), unknown, floating_point_type(1196.88), natural_number_type(1200)));
00584       C.push_back(TupleResultRandomSat(RandomKSat("99SAT", 99), RandomKSat_n("crafted/sat04/gomes03/x-v11", 11), std::string("bench432"), std::string("solver1"), unknown, floating_point_type(1200), natural_number_type(1200)));
00585       C.push_back(TupleResultRandomSat(RandomKSat("3SAT", 3), RandomKSat_n("random/MediumSizeBenches/k3-r4.263-v300", 300), std::string("bench1902"), std::string("solver1"), unsat, floating_point_type(6.65), natural_number_type(1200)));
00586       }
00587     };
00588 
00589     template <class Container>
00590     inline void add_positive_result_tuples(Container& C) {
00591       Add_positive_result_tuples<Container, typename Container::value_type>()(C);
00592     }
00593 
00594     // -----------------------------------------------------------------------------------------------------------------------------
00595     // -----------------------------------------------------------------------------------------------------------------------------
00596 
00597     template <class Result>
00598     class Test_ParserResult_Result_positive_cases : public ::OKlib::TestSystem::Test {
00599     public :
00600       typedef Test_ParserResult_Result_positive_cases test_type;
00601     private :
00602       void perform_test_trivial() {
00603         Result s;
00604         typedef ParserResult<Result> Parser;
00605         Parser p(s);
00606         {
00607           typedef std::vector<TupleResult> Vector;
00608           Vector test_vector;
00609           add_positive_result_tuples(test_vector);
00610            for (Vector::const_iterator i = test_vector.begin(); i != test_vector.end(); ++i) {
00611             std::stringstream test_stream;
00612             test_stream << *i;
00613             const std::string test(test_stream.str());
00614             OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00615             if (s.super_series().name() != i -> get<0>().name()) {
00616               std::stringstream out;
00617               out << "Super Series is " << s.super_series() << ", and not " << i -> get<0>();
00618               OKLIB_THROW(out.str());
00619             }
00620             if (s.series().name() != i -> get<1>().name()) {
00621               std::stringstream out;
00622               out << "Series is " << s.series() << ", and not " << i -> get<1>();
00623               OKLIB_THROW(out.str());
00624             }
00625             if (s.benchmark().name() != i -> get<2>().name()) {
00626               std::stringstream out;
00627               out << "Benchmark is " << s.benchmark() << ", and not " << i -> get<2>();
00628               OKLIB_THROW(out.str());
00629             }
00630             if (s.solver().name() != i -> get<3>().name()) {
00631               std::stringstream out;
00632               out << "Solver is " << s.solver() << ", and not " << i -> get<3>();
00633               OKLIB_THROW(out.str());
00634             }
00635             if (s.sat_status().result() != i -> get<4>().result()) {
00636               std::stringstream out;
00637               out << "Sat_Status is " << s.sat_status() << ", and not " << i -> get<4>();
00638               OKLIB_THROW(out.str());
00639             }
00640             if (s.average().average() != i -> get<5>().average()) {
00641               std::stringstream out;
00642               out << "Average is " << s.average() << ", and not " << i -> get<5>();
00643               OKLIB_THROW(out.str());
00644             }
00645             if (s.time_out().time_out() != i -> get<6>().time_out()) {
00646               std::stringstream out;
00647               out << "Time_Out is " << s.time_out() << ", and not " << i -> get<6>();
00648               OKLIB_THROW(out.str());
00649             }
00650             if (s != *i) {
00651               std::stringstream out;
00652               out << "Result is \"" << s <<"\", and not \"" << *i << "\"";
00653               OKLIB_THROW(out.str());
00654             }
00655           }
00656         }
00657       }
00658     };
00659     template <class Result>
00660     class Test_ParserResult_Result_negative_cases : public ::OKlib::TestSystem::Test {
00661     public :
00662       typedef Test_ParserResult_Result_negative_cases test_type;
00663     private :
00664       void perform_test_trivial() {
00665         Result s;
00666         typedef ParserResult<Result> Parser;
00667         Parser p(s);
00668         {
00669           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, " 3SAT random/MediumSizeBenches/k3-r4.263-v300 bench1903 solver5 0 1200 1200", ::OKlib::Parser::match_not_full));
00670           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "3SAT random/MediumSizeBenches/k3-r4.263-v300 bench1903 solver5 0 1200 1200 ", ::OKlib::Parser::match_not_full));
00671           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "3SAT random/MediumSizeBenches/k3-r4.263-v300 bench1903 solver5 0 1200", ::OKlib::Parser::match_not_full));
00672           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "random/MediumSizeBenches/k3-r4.263-v300 bench1903 solver5 0 1200 1200", ::OKlib::Parser::match_not_full));
00673           OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, "3SAT random/MediumSizeBenches/k3-r4.263-v300 bench1903 0 1200 1200+11", ::OKlib::Parser::match_not_full));
00674         }
00675        }
00676     };
00677 
00678     template <class Result>
00679     class Test_ParserResult_Result : public ::OKlib::TestSystem::TestBase {
00680     public :
00681       typedef Test_ParserResult_Result test_type;
00682       Test_ParserResult_Result() {
00683         insert(this);
00684       }
00685     private :
00686       void perform_test_trivial() {
00687         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResult_Result_positive_cases<Result>());
00688         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResult_Result_negative_cases<Result>());
00689        }
00690     };
00691 
00692     // -----------------------------------------------------------------------------------------------------------------------------
00693 
00694     template <class ResultRandomSat>
00695     class Test_ParserResult_ResultRandomSat_positive_cases : public ::OKlib::TestSystem::Test {
00696     public :
00697       typedef Test_ParserResult_ResultRandomSat_positive_cases test_type;
00698     private :
00699       void perform_test_trivial() {
00700         ResultRandomSat s;
00701         typedef ParserResult<ResultRandomSat> Parser;
00702         Parser p(s);
00703         {
00704           typedef std::vector<TupleResultRandomSat> Vector;
00705           Vector test_vector;
00706           add_positive_result_tuples(test_vector);
00707           for (Vector::const_iterator i = test_vector.begin(); i != test_vector.end(); ++i) {
00708             std::stringstream test_stream;
00709             test_stream << *i;
00710             const std::string test(test_stream.str());
00711             OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
00712             if (s.super_series().name() != i -> get<0>().name()) {
00713               std::stringstream out;
00714               out << "Super Series is " << s.super_series() << ", and not " << i -> get<0>();
00715               OKLIB_THROW(out.str());
00716             }
00717             if (s.super_series_random().clause_length() != i -> get<0>().clause_length()) {
00718               std::stringstream out;
00719               out << "Super Series Random is " << s.super_series_random() << " with clause-length " << s.super_series_random().clause_length() << ", and not " << i -> get<0>() << " with clause-length " << i -> get<0>().clause_length();
00720               OKLIB_THROW(out.str());
00721             }
00722             if (s.series().name() != i -> get<1>().name()) {
00723               std::stringstream out;
00724               out << "Series is " << s.series() << ", and not " << i -> get<1>();
00725               OKLIB_THROW(out.str());
00726             }
00727             if (s.series_random().count_variables() != i -> get<1>().count_variables()) {
00728               std::stringstream out;
00729               out << "Series Random is " << s.series_random() << " with variables count " << s.series_random().count_variables() << ", and not " << i -> get<1>() << " with variables count " << i -> get<1>().count_variables();
00730               OKLIB_THROW(out.str());
00731             }
00732             if (s.benchmark().name() != i -> get<2>().name()) {
00733               std::stringstream out;
00734               out << "Benchmark is " << s.benchmark() << ", and not " << i -> get<2>();
00735               OKLIB_THROW(out.str());
00736             }
00737             if (s.solver().name() != i -> get<3>().name()) {
00738               std::stringstream out;
00739               out << "Solver is " << s.solver() << ", and not " << i -> get<3>();
00740               OKLIB_THROW(out.str());
00741             }
00742             if (s.sat_status().result() != i -> get<4>().result()) {
00743               std::stringstream out;
00744               out << "Sat_Status is " << s.sat_status() << ", and not " << i -> get<4>();
00745               OKLIB_THROW(out.str());
00746             }
00747             if (s.average().average() != i -> get<5>().average()) {
00748               std::stringstream out;
00749               out << "Average is " << s.average() << ", and not " << i -> get<5>();
00750               OKLIB_THROW(out.str());
00751             }
00752             if (s.time_out().time_out() != i -> get<6>().time_out()) {
00753               std::stringstream out;
00754               out << "Time_Out is " << s.time_out() << ", and not " << i -> get<6>();
00755               OKLIB_THROW(out.str());
00756             }
00757           }
00758         }
00759       }
00760     };
00761 
00762     template <class ResultRandomSat>
00763     class Test_ParserResult_ResultRandomSat : public ::OKlib::TestSystem::TestBase {
00764     public :
00765       typedef Test_ParserResult_ResultRandomSat test_type;
00766       Test_ParserResult_ResultRandomSat() {
00767         insert(this);
00768       }
00769     private :
00770       void perform_test_trivial() {
00771         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResult_ResultRandomSat_positive_cases<ResultRandomSat>());
00772         OKLIB_TESTTRIVIAL_RETHROW(Test_ParserResult_Result_negative_cases<ResultRandomSat>());
00773        }
00774     };
00775 
00776     // ToDo: All generic and based on concepts!!
00777 
00778   }
00779 
00780 }
00781 
00782 #endif