• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

mixin.test.h

Go to the documentation of this file.
00001 // -*- C++ -*- (c) 2007 Petr Rockai <me@mornfall.net>
00002 
00003 #include <wibble/test.h>
00004 #include <wibble/mixin.h>
00005 #include <vector>
00006 
00007 namespace {
00008 
00009 using namespace std;
00010 
00011 class Integer : public wibble::mixin::Comparable<Integer>
00012 {
00013     int val;
00014 public:
00015     Integer(int val) : val(val) {}
00016     bool operator<=( const Integer& o ) const { return val <= o.val; }
00017 };
00018 
00019 class Discard : public wibble::mixin::OutputIterator<Discard>
00020 {
00021 public:
00022     Discard& operator=(const int&)
00023     {
00024         return *this;
00025     }
00026 };
00027 
00028 struct TestMixin {
00029 
00030 // Test Comparable mixin
00031     Test comparable() {
00032         Integer i10(10);
00033         Integer i10a(10);
00034         Integer i20(20);
00035 
00036 // Test the base method first
00037         assert(i10 <= i10a);
00038         assert(i10a <= i10);
00039         assert(i10 <= i20);
00040         assert(! (i20 <= i10));
00041         
00042 // Test the other methods
00043         assert(i10 != i20);
00044         assert(!(i10 != i10a));
00045         
00046         assert(i10 == i10a);
00047         assert(!(i10 == i20));
00048         
00049         assert(i10 < i20);
00050         assert(!(i20 < i10));
00051         assert(!(i10 < i10a));
00052         
00053         assert(i20 > i10);
00054         assert(!(i10 > i20));
00055         assert(!(i10 > i10a));
00056         
00057         assert(i10 >= i10a);
00058         assert(i10a >= i10);
00059         assert(i20 >= i10);
00060         assert(! (i10 >= i20));
00061     }
00062     
00063     Test output() {
00064         vector<int> data;
00065         data.push_back(1);
00066         data.push_back(2);
00067         data.push_back(3);
00068         
00069         std::copy(data.begin(), data.end(), Discard());
00070     }
00071 
00072 };
00073 
00074 }

Generated on Sun Feb 17 2013 02:35:44 for wibble by  doxygen 1.7.1