OKlibrary  0.2.1.6
Basics_Tests.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 24.5.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 
00031 #ifndef BASICSTESTS_oLzW151
00032 #define BASICSTESTS_oLzW151
00033 
00034 #include <cassert>
00035 
00036 #include <OKlib/TestSystem/TestBaseClass.hpp>
00037 #include <OKlib/TestSystem/TestExceptions.hpp>
00038 
00039 #include <OKlib/Concepts/std_Basics_Tests.hpp>
00040 
00041 namespace OKlib {
00042 
00043   namespace Concepts {
00044 
00050     template <typename T>
00051     struct FullyEqualityComparable_Axiom_equal_vs_unequal : OKlib::TestSystem::Test {
00052       typedef FullyEqualityComparable_Axiom_equal_vs_unequal test_type;
00053       FullyEqualityComparable_Axiom_equal_vs_unequal(const T& a, const T& b) : a(a), b(b) {}
00054     private :
00055       const T& a, b;
00056       void perform_test_trivial() {
00057         const bool a_eq_b = (a == b);
00058         const bool a_neq_b = (a != b);
00059         switch (a_eq_b) {
00060         case true :
00061           if (a_neq_b)
00062             OKLIB_THROW("a == b and a != b");
00063           break;
00064         case false :
00065           if (not a_neq_b)
00066             OKLIB_THROW("not a == b and not a != b");
00067           break;
00068         }
00069       }
00070     };
00071     
00077     template <typename T>
00078     struct FullyEqualityComparable_basic_test_one_object : OKlib::TestSystem::Test {
00079       typedef FullyEqualityComparable_basic_test_one_object test_type;
00080       FullyEqualityComparable_basic_test_one_object(const T& x) : x(x) {}
00081     private :
00082       const T& x;
00083       void perform_test_trivial() {
00084         OKLIB_TESTTRIVIAL_RETHROW(EqualityComparable_basic_test_one_object<T>(x));
00085         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_Axiom_equal_vs_unequal<T>(x, x));
00086       }
00087     };
00088 
00094     template <typename T>
00095     struct FullyEqualityComparable_basic_test_two_objects : OKlib::TestSystem::Test {
00096       typedef FullyEqualityComparable_basic_test_two_objects test_type;
00097       FullyEqualityComparable_basic_test_two_objects(const T& x, const T& y) : x(x), y(y) {}
00098     private :
00099       const T& x, y;
00100       void perform_test_trivial() {
00101         OKLIB_TESTTRIVIAL_RETHROW(EqualityComparable_basic_test_two_objects<T>(x, y));
00102         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_one_object<T>(x));
00103         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_one_object<T>(y));
00104         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_Axiom_equal_vs_unequal<T>(x, y));
00105       }
00106     };
00107 
00113     template <typename T>
00114     struct FullyEqualityComparable_basic_test_three_objects : OKlib::TestSystem::Test {
00115       typedef FullyEqualityComparable_basic_test_three_objects test_type;
00116       FullyEqualityComparable_basic_test_three_objects(const T& x, const T& y, const T& z) : x(x), y(y), z(z) {}
00117     private :
00118       const T& x, y, z;
00119       void perform_test_trivial() {
00120         OKLIB_TESTTRIVIAL_RETHROW(EqualityComparable_basic_test_three_objects<T>(x, y, z));
00121         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_two_objects<T>(x, y));
00122         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_two_objects<T>(x, z));
00123         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_two_objects<T>(y, z));
00124       }
00125     };
00126 
00127     // ############################################################
00128 
00134     template <typename T>
00135     struct ConstructibleCEq_Axiom_copy_eq : OKlib::TestSystem::Test {
00136       typedef ConstructibleCEq_Axiom_copy_eq test_type;
00137       ConstructibleCEq_Axiom_copy_eq(const T& a) : a(a), x(a) {}
00138     private :
00139       const T& a;
00140       const T x;
00141       void perform_test_trivial() {
00142         if (not (a == x))
00143           OKLIB_THROW("not (a == x) after copy construction");
00144       }
00145     };
00146 
00152     template <typename T>
00153     struct ConstructibleCEq_basic_test_one_object : OKlib::TestSystem::Test {
00154       typedef ConstructibleCEq_basic_test_one_object test_type;
00155       ConstructibleCEq_basic_test_one_object(const T& x) : x(x) {}
00156     private :
00157       const T& x;
00158       void perform_test_trivial() {
00159         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_one_object<T>(x));
00160         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCEq_Axiom_copy_eq<T>(x));
00161       }
00162     };
00163 
00169     template <typename T>
00170     struct ConstructibleCEq_basic_test_two_objects : OKlib::TestSystem::Test {
00171       typedef ConstructibleCEq_basic_test_two_objects test_type;
00172       ConstructibleCEq_basic_test_two_objects(const T& x, const T& y) : x(x), y(y) {}
00173     private :
00174       const T& x, y;
00175       void perform_test_trivial() {
00176         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCEq_basic_test_one_object<T>(x));
00177         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCEq_basic_test_one_object<T>(y));
00178         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_two_objects<T>(x, y));
00179       }
00180     };
00181 
00187     template <typename T>
00188     struct ConstructibleCEq_basic_test_three_objects : OKlib::TestSystem::Test {
00189       typedef ConstructibleCEq_basic_test_three_objects test_type;
00190       ConstructibleCEq_basic_test_three_objects(const T& x, const T& y, const T& z) : x(x), y(y), z(z) {}
00191     private :
00192       const T& x, y, z;
00193       void perform_test_trivial() {
00194         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCEq_basic_test_two_objects<T>(x, y));
00195         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCEq_basic_test_two_objects<T>(x, z));
00196         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCEq_basic_test_two_objects<T>(y, z));
00197         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_three_objects<T>(x, y, z));
00198       }
00199     };
00200 
00201     // ----------------------------------------------------------------------------------------------------------------------
00202 
00208     template <typename T>
00209     struct ConstructibleCAEq_Axiom_assign_eq : OKlib::TestSystem::Test {
00210       typedef ConstructibleCAEq_Axiom_assign_eq test_type;
00211       ConstructibleCAEq_Axiom_assign_eq(const T& a, const T& b) : a(a), b(b), x(a) {}
00212     private :
00213       const T& a, b;
00214       const T x;
00215       void perform_test_trivial() {
00216         x = b;
00217         if (not (x == b))
00218           OKLIB_THROW("not (x == b) after assignment x = b");
00219       }
00220     };
00221 
00227     template <typename T>
00228     struct ConstructibleCAEq_basic_test_one_object : OKlib::TestSystem::Test {
00229       typedef ConstructibleCAEq_basic_test_one_object test_type;
00230       ConstructibleCAEq_basic_test_one_object(const T& x) : x(x) {}
00231     private :
00232       const T& x;
00233       void perform_test_trivial() {
00234         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCEq_basic_test_one_object<T>(x));
00235         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_Axiom_assign_eq<T>(x, x));
00236       }
00237     };
00238 
00244     template <typename T>
00245     struct ConstructibleCAEq_basic_test_two_objects : OKlib::TestSystem::Test {
00246       typedef ConstructibleCAEq_basic_test_two_objects test_type;
00247       ConstructibleCAEq_basic_test_two_objects(const T& x, const T& y) : x(x), y(y) {}
00248     private :
00249       const T& x, y;
00250       void perform_test_trivial() {
00251         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCEq_basic_test_two_objects<T>(x, y));
00252         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_basic_test_one_object<T>(x));
00253         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_basic_test_one_object<T>(y));
00254         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_Axiom_assign_eq<T>(x, y));
00255       }
00256     };
00257 
00263     template <typename T>
00264     struct ConstructibleCAEq_basic_test_three_objects : OKlib::TestSystem::Test {
00265       typedef ConstructibleCAEq_basic_test_three_objects test_type;
00266       ConstructibleCAEq_basic_test_three_objects(const T& x, const T& y, const T& z) : x(x), y(y), z(z) {}
00267     private :
00268       const T& x, y, z;
00269       void perform_test_trivial() {
00270         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCEq_basic_test_three_objects<T>(x, y, z));
00271         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_basic_test_two_objects<T>(x, y));
00272         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_basic_test_two_objects<T>(x, z));
00273         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_basic_test_two_objects<T>(y, z));
00274       }
00275     };
00276 
00277     // ----------------------------------------------------------------------------------------------------------------------
00278 
00284     template <typename T>
00285     struct ConstructibleDEq_Axiom_default_eq : OKlib::TestSystem::Test {
00286       typedef ConstructibleDEq_Axiom_default_eq test_type;
00287       ConstructibleDEq_Axiom_default_eq() {}
00288     private :
00289       void perform_test_trivial() {
00290         if (not (T() == T()))
00291           OKLIB_THROW("not (T() == T())");
00292       }
00293     };
00294 
00300     template <typename T>
00301     struct ConstructibleDEq_basic_test_no_object : OKlib::TestSystem::Test {
00302       typedef ConstructibleDEq_basic_test_no_object test_type;
00303       ConstructibleDEq_basic_test_no_object() {}
00304     private :
00305       void perform_test_trivial() {
00306         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleDEq_Axiom_default_eq<T>());
00307       }
00308     };
00309 
00315     template <typename T>
00316     struct ConstructibleDEq_basic_test_one_object : OKlib::TestSystem::Test {
00317       typedef ConstructibleDEq_basic_test_one_object test_type;
00318       ConstructibleDEq_basic_test_one_object(const T& x) : x(x) {}
00319     private :
00320       const T& x;
00321       void perform_test_trivial() {
00322         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleDEq_basic_test_no_object<T>());
00323         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_one_object<T>(x));
00324       }
00325     };
00326 
00332     template <typename T>
00333     struct ConstructibleDEq_basic_test_two_objects : OKlib::TestSystem::Test {
00334       typedef ConstructibleDEq_basic_test_two_objects test_type;
00335       ConstructibleDEq_basic_test_two_objects(const T& x, const T& y) : x(x), y(y) {}
00336     private :
00337       const T& x, y;
00338       void perform_test_trivial() {
00339         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleDEq_basic_test_one_object<T>(x));
00340         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleDEq_basic_test_one_object<T>(y));
00341         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_two_objects<T>(x, y));
00342       }
00343     };
00344 
00350     template <typename T>
00351     struct ConstructibleDEq_basic_test_three_objects : OKlib::TestSystem::Test {
00352       typedef ConstructibleDEq_basic_test_three_objects test_type;
00353       ConstructibleDEq_basic_test_three_objects(const T& x, const T& y, const T& z) : x(x), y(y), z(z) {}
00354     private :
00355       const T& x, y, z;
00356       void perform_test_trivial() {
00357         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleDEq_basic_test_two_objects<T>(x, y));
00358         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleDEq_basic_test_two_objects<T>(x, z));
00359         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleDEq_basic_test_two_objects<T>(y, z));
00360         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_three_objects<T>(x, y, z));
00361       }
00362     };
00363 
00364     // ----------------------------------------------------------------------------------------------------------------------
00365 
00371     template <typename T>
00372     struct FullyConstructibleEq_basic_test_no_object : OKlib::TestSystem::Test {
00373       typedef FullyConstructibleEq_basic_test_no_object test_type;
00374       FullyConstructibleEq_basic_test_no_object() {}
00375     private :
00376       void perform_test_trivial() {
00377         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleDEq_basic_test_no_object<T>());
00378       }
00379     };
00380 
00386     template <typename T>
00387     struct FullyConstructibleEq_basic_test_one_object : OKlib::TestSystem::Test {
00388       typedef FullyConstructibleEq_basic_test_one_object test_type;
00389       FullyConstructibleEq_basic_test_one_object(const T& x) : x(x) {}
00390     private :
00391       const T& x;
00392       void perform_test_trivial() {
00393         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleDEq_basic_test_no_object<T>());
00394         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_basic_test_one_object<T>(x));
00395       }
00396     };
00397 
00403     template <typename T>
00404     struct FullyConstructibleEq_basic_test_two_objects : OKlib::TestSystem::Test {
00405       typedef FullyConstructibleEq_basic_test_two_objects test_type;
00406       FullyConstructibleEq_basic_test_two_objects(const T& x, const T& y) : x(x), y(y) {}
00407     private :
00408       const T& x, y;
00409       void perform_test_trivial() {
00410         OKLIB_TESTTRIVIAL_RETHROW(FullyConstructibleEq_basic_test_one_object<T>(x));
00411         OKLIB_TESTTRIVIAL_RETHROW(FullyConstructibleEq_basic_test_one_object<T>(y));
00412         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_basic_test_two_objects<T>(x, y));
00413       }
00414     };
00415 
00421     template <typename T>
00422     struct FullyConstructibleEq_basic_test_three_objects : OKlib::TestSystem::Test {
00423       typedef FullyConstructibleEq_basic_test_three_objects test_type;
00424       FullyConstructibleEq_basic_test_three_objects(const T& x, const T& y, const T& z) : x(x), y(y), z(z) {}
00425     private :
00426       const T& x, y, z;
00427       void perform_test_trivial() {
00428         OKLIB_TESTTRIVIAL_RETHROW(FullyConstructibleEq_basic_test_two_objects<T>(x, y));
00429         OKLIB_TESTTRIVIAL_RETHROW(FullyConstructibleEq_basic_test_two_objects<T>(x, z));
00430         OKLIB_TESTTRIVIAL_RETHROW(FullyConstructibleEq_basic_test_two_objects<T>(y, z));
00431         OKLIB_TESTTRIVIAL_RETHROW(ConstructibleCAEq_basic_test_three_objects<T>(x, y, z));
00432       }
00433     };
00434 
00435     // ############################################################
00436 
00437     template <typename T>
00438     struct FullyLessThanComparable_Axiom_greater_positive : OKlib::TestSystem::Test {
00439       typedef FullyLessThanComparable_Axiom_greater_positive test_type;
00440       FullyLessThanComparable_Axiom_greater_positive(const T& a, const T& b) : a(a), b(b) {
00441         assert(b < a);
00442       }
00443     private :
00444       const T& a, b;
00445       void perform_test_trivial() {
00446         if (not (a > b))
00447           OKLIB_THROW("not a > b");
00448       }
00449     };
00450 
00451     template <typename T>
00452     struct FullyLessThanComparable_Axiom_greater_negative : OKlib::TestSystem::Test {
00453       typedef FullyLessThanComparable_Axiom_greater_negative test_type;
00454       FullyLessThanComparable_Axiom_greater_negative(const T& a, const T& b) : a(a), b(b) {
00455         assert(a > b);
00456       }
00457     private :
00458       const T& a, b;
00459       void perform_test_trivial() {
00460         if (not (b < a))
00461           OKLIB_THROW("not b < a");
00462       }
00463     };
00464   
00465     template <typename T>
00466     struct FullyLessThanComparable_Axiom_less_equal_positive : OKlib::TestSystem::Test {
00467       typedef FullyLessThanComparable_Axiom_less_equal_positive test_type;
00468       FullyLessThanComparable_Axiom_less_equal_positive(const T& a, const T& b) : a(a), b(b) {
00469         assert(not (a > b));
00470       }
00471     private :
00472       const T& a, b;
00473       void perform_test_trivial() {
00474         if (not (a <= b))
00475           OKLIB_THROW("not a <= b");
00476       }
00477     };
00478 
00479     template <typename T>
00480     struct FullyLessThanComparable_Axiom_less_equal_negative : OKlib::TestSystem::Test {
00481       typedef FullyLessThanComparable_Axiom_less_equal_negative test_type;
00482       FullyLessThanComparable_Axiom_less_equal_negative(const T& a, const T& b) : a(a), b(b) {
00483         assert(a <= b);
00484       }
00485     private :
00486       const T& a, b;
00487       void perform_test_trivial() {
00488         if (a > b)
00489           OKLIB_THROW("not not a > b");
00490       }
00491     };
00492 
00493     template <typename T>
00494     struct FullyLessThanComparable_Axiom_greater_equal_positive : OKlib::TestSystem::Test {
00495       typedef FullyLessThanComparable_Axiom_greater_equal_positive test_type;
00496       FullyLessThanComparable_Axiom_greater_equal_positive(const T& a, const T& b) : a(a), b(b) {
00497         assert(b <= a);
00498       }
00499     private :
00500       const T& a, b;
00501       void perform_test_trivial() {
00502         if (not (a >= b))
00503           OKLIB_THROW("not a >= b");
00504       }
00505     };
00506 
00507     template <typename T>
00508     struct FullyLessThanComparable_Axiom_greater_equal_negative : OKlib::TestSystem::Test {
00509       typedef FullyLessThanComparable_Axiom_greater_equal_negative test_type;
00510       FullyLessThanComparable_Axiom_greater_equal_negative(const T& a, const T& b) : a(a), b(b) {
00511         assert(a >= b);
00512       }
00513     private :
00514       const T& a, b;
00515       void perform_test_trivial() {
00516         if (not (b <= a))
00517           OKLIB_THROW("not b <= a");
00518       }
00519     };
00520 
00521     template <typename T>
00522     struct FullyLessThanComparable_basic_test_one_object : OKlib::TestSystem::Test {
00523       typedef FullyLessThanComparable_basic_test_one_object test_type;
00524       FullyLessThanComparable_basic_test_one_object(const T& x) : x(x) {}
00525     private :
00526       const T& x;
00527       void perform_test_trivial() {
00528         OKLIB_TESTTRIVIAL_RETHROW(FullyLessThanComparable_Axiom_less_equal_positive<T>(x, x));
00529         OKLIB_TESTTRIVIAL_RETHROW(FullyLessThanComparable_Axiom_less_equal_negative<T>(x, x));
00530         OKLIB_TESTTRIVIAL_RETHROW(FullyLessThanComparable_Axiom_greater_equal_positive<T>(x, x));
00531         OKLIB_TESTTRIVIAL_RETHROW(FullyLessThanComparable_Axiom_greater_equal_negative<T>(x, x));
00532       }
00533     };
00534 
00535     // ############################################################
00536 
00537     template <typename T>
00538     struct LinearOrder_Axiom_positive : OKlib::TestSystem::Test {
00539       typedef LinearOrder_Axiom_positive test_type;
00540       LinearOrder_Axiom_positive(const T& a, const T& b) : a(a), b(b) {
00541         assert(not (a < b) and not (b < a));
00542       }
00543     private :
00544       const T& a, b;
00545       void perform_test_trivial() {
00546         if (not (a == b))
00547           OKLIB_THROW("not a == b");
00548       }
00549     };
00550 
00551     template <typename T>
00552     struct LinearOrder_Axiom_negative : OKlib::TestSystem::Test {
00553       typedef LinearOrder_Axiom_negative test_type;
00554       LinearOrder_Axiom_negative(const T& a, const T& b) : a(a), b(b) {
00555         assert(a == b);
00556       }
00557     private :
00558       const T& a, b;
00559       void perform_test_trivial() {
00560         if (a < b or b < a)
00561           OKLIB_THROW("a < b or b < a");
00562       }
00563     };
00564 
00565     template <typename T>
00566     struct LinearOrder_basic_test_one_object : OKlib::TestSystem::Test {
00567       typedef LinearOrder_basic_test_one_object test_type;
00568       LinearOrder_basic_test_one_object(const T& x) : x(x) {}
00569     private :
00570       const T& x;
00571       void perform_test_trivial() {
00572         OKLIB_TESTTRIVIAL_RETHROW(FullyLessThanComparable_basic_test_one_object<T>(x));
00573         OKLIB_TESTTRIVIAL_RETHROW(FullyEqualityComparable_basic_test_one_object<T>(x));
00574         OKLIB_TESTTRIVIAL_RETHROW(LinearOrder_Axiom_negative<T>(x, x));
00575       }
00576     };
00577     
00578   }
00579 
00580 }
00581 
00582 #endif