OKlibrary  0.2.1.6
VanderWaerden_Tests.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 15.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 VANDERWAERDENHYPERGRAPHTESTS_oppQyyr8838
00009 #define VANDERWAERDENHYPERGRAPHTESTS_oppQyyr8838
00010 
00011 #include <iterator>
00012 #include <string>
00013 
00014 #include <boost/lexical_cast.hpp>
00015  
00016 #include <OKlib/TestSystem/TestBaseClass.hpp>
00017 #include <OKlib/TestSystem/TestExceptions.hpp>
00018 
00019 #include <OKlib/Concepts/Iterators.hpp>
00020 #include <OKlib/Concepts/LibraryBasics.hpp>
00021 
00022 #include <OKlib/Combinatorics/Hypergraphs/Generators/VanderWaerden.hpp>
00023 
00024 namespace OKlib {
00025   namespace Van_der_Waerden_hypergraph {
00026 
00027     template <class Iterator_arithmetic_progression>
00028     class Test_Iterator_arithmetic_progression : public ::OKlib::TestSystem::Test {
00029     public :
00030       typedef Test_Iterator_arithmetic_progression test_type;
00031     private :
00032       void perform_test_trivial() {
00033         // ToDo: Define (general) tests for InputIterator and MultiPass_InputIterator, and apply it here.
00034         // ToDo: Define concept "IteratorArithmeticProgression" and check it here.
00035         OKLIB_MODELS_CONCEPT_REQUIRES(Iterator_arithmetic_progression, ::OKlib::Concepts::MultiPassInputIterator);
00036         OKLIB_MODELS_CONCEPT_TAG(Iterator_arithmetic_progression, ::OKlib::Concepts::MultiPassInputIterator);
00037         typedef typename std::iterator_traits<Iterator_arithmetic_progression>::value_type value_type;
00038         {
00039           Iterator_arithmetic_progression end(11,0);
00040           value_type count = 0;
00041           for (Iterator_arithmetic_progression begin(2,3); begin != end; ++begin, ++count) ;
00042           const value_type steps =  (11 - 2) / 3;
00043           if (count != steps)
00044             OKLIB_THROW("Count is " + boost::lexical_cast<std::string>(count) + ", and not " + boost::lexical_cast<std::string>(steps));
00045         }
00046         {
00047           // ToDo: to be completed.
00048         }
00049       }
00050     };
00051 
00052     template <template <typename Integer> class Iterator_arithmetic_progression>
00053     class Test_Iterator_arithmetic_progression_Integer : public ::OKlib::TestSystem::TestBase {
00054     public :
00055       typedef Test_Iterator_arithmetic_progression_Integer test_type;
00056       Test_Iterator_arithmetic_progression_Integer() {
00057         insert(this);
00058       }
00059     public :
00060       void perform_test_trivial() {
00061         OKLIB_TESTTRIVIAL_RETHROW(Test_Iterator_arithmetic_progression<Iterator_arithmetic_progression<unsigned int> >());
00062         OKLIB_TESTTRIVIAL_RETHROW(Test_Iterator_arithmetic_progression<Iterator_arithmetic_progression<int> >());
00063         OKLIB_TESTTRIVIAL_RETHROW(Test_Iterator_arithmetic_progression<Iterator_arithmetic_progression<long unsigned int> >());
00064         OKLIB_TESTTRIVIAL_RETHROW(Test_Iterator_arithmetic_progression<Iterator_arithmetic_progression<long int> >());
00065       }
00066     };
00067 
00068     // ------------------------------------------------------------------------------------------------------------------------
00069 
00070     template <class Arithmetic_progression>
00071     class Test_Arithmetic_progression : public ::OKlib::TestSystem::Test {
00072     public :
00073       typedef Test_Arithmetic_progression test_type;
00074     private :
00075       typedef typename Arithmetic_progression::value_type value_type;
00076       typedef typename Arithmetic_progression::iterator iterator;
00077       void perform_test_trivial() {
00078         // ToDo: Conceptual check
00079         {
00080           const value_type start = 3;
00081           const value_type length = 3;
00082           const value_type slope = 2;
00083           const Arithmetic_progression ap(start,length,slope);
00084           if (ap.start() != start)
00085             throw ::OKlib::TestSystem::TestException("Start is " + boost::lexical_cast<std::string>(ap.start()) + ", and not " + boost::lexical_cast<std::string>(start)).add(OKLIB_TESTDESCRIPTION);
00086           if (ap.size() != length)
00087             throw ::OKlib::TestSystem::TestException("Size is " + boost::lexical_cast<std::string>(ap.size()) + ", and not " + boost::lexical_cast<std::string>(length)).add(OKLIB_TESTDESCRIPTION);
00088           if (ap.slope() != slope)
00089             throw ::OKlib::TestSystem::TestException("Slope is " + boost::lexical_cast<std::string>(ap.slope()) + ", and not " + boost::lexical_cast<std::string>(slope)).add(OKLIB_TESTDESCRIPTION);
00090           value_type steps = 0;
00091           for (iterator i = ap.begin(); i != ap.end(); ++i, ++steps) {
00092             value_type element = start + steps * slope;
00093             if (*i != element)
00094               throw ::OKlib::TestSystem::TestException("Element is " + boost::lexical_cast<std::string>(*i) + ", and not " + boost::lexical_cast<std::string>(element)).add(OKLIB_TESTDESCRIPTION);
00095           }
00096           if (steps != length)
00097             throw ::OKlib::TestSystem::TestException("Step count is " + boost::lexical_cast<std::string>(steps) + ", and not " + boost::lexical_cast<std::string>(length)).add(OKLIB_TESTDESCRIPTION);
00098         }
00099         {
00100           // ToDo: To be completed.
00101         }
00102       }
00103     };
00104 
00105     template <template <typename Integer> class Arithmetic_progression>
00106     class Test_Arithmetic_progression_Integer : public ::OKlib::TestSystem::TestBase {
00107     public :
00108       typedef Test_Arithmetic_progression_Integer test_type;
00109       Test_Arithmetic_progression_Integer() {
00110         insert(this);
00111       }
00112     public :
00113       void perform_test_trivial() {
00114         OKLIB_TESTTRIVIAL_RETHROW(Test_Arithmetic_progression<Arithmetic_progression<unsigned int> >());
00115         OKLIB_TESTTRIVIAL_RETHROW(Test_Arithmetic_progression<Arithmetic_progression<int> >());
00116         OKLIB_TESTTRIVIAL_RETHROW(Test_Arithmetic_progression<Arithmetic_progression<long unsigned int> >());
00117         OKLIB_TESTTRIVIAL_RETHROW(Test_Arithmetic_progression<Arithmetic_progression<long int> >());
00118       }
00119     };
00120 
00121     // ------------------------------------------------------------------------------------------------------------------------
00122 
00123     }
00124 }
00125 
00126 #endif