wibble 1.1
consumer.test.h
Go to the documentation of this file.
1// -*- C++ -*- (c) 2006 Petr Rockai <me@mornfall.net>
2
3#include <wibble/consumer.h>
4#include <wibble/operators.h>
5#include <list>
6
7namespace {
8
9using namespace wibble::operators;
10using namespace wibble;
11
12struct TestConsumer {
13 Test stlInserterConsumer() {
14 std::list<int> a;
15 a.push_back( 10 );
16 a.push_back( 20 );
17 Range< int > r = range( a.begin(), a.end() );
18 std::list<int> b;
19 assert( a != b );
20 Consumer< int > c = consumer( back_inserter( b ) );
21 std::copy( r.begin(), r.end(), c );
22 assert( a == b );
23 }
24
25 Test stlSetConsumer() {
26 std::set< int > s;
28 c.consume( 1 );
29 assert( *s.begin() == 1 );
30 assert( s.begin() + 1 == s.end() );
31 }
32
33 Test stlVectorConsumer() {
34 std::vector< int > v;
36 c.consume( 2 );
37 c.consume( 1 );
38 assert( *v.begin() == 2 );
39 assert( *(v.begin() + 1) == 1 );
40 assert( (v.begin() + 2) == v.end() );
41 }
42
43};
44
45}
-*- C++ -*-
Definition: operators.h:12
Definition: amorph.h:17
Range< typename In::value_type > range(In b, In e)
Definition: range.h:264
Consumer< typename Out::container_type::value_type > consumer(Out out)
Definition: consumer.h:108
Definition: consumer.h:67
void consume(const T &a)
Definition: consumer.h:78
iterator begin() const
Definition: range.h:70
iterator end() const
Definition: range.h:71
Definition: range.h:155
void Test
Definition: test.h:178
#define assert(x)
Definition: test.h:30