COIN-OR::LEMON - Graph Library

source: lemon-1.0/test/maps_test.cc @ 103:b68a7e348e00

Last change on this file since 103:b68a7e348e00 was 39:0a01d811071f, checked in by Alpar Juttner <alpar@…>, 12 years ago

Happy New Year (update the copyright headers)

File size: 3.4 KB
Line 
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19#include <deque>
20#include <set>
21
22#include <lemon/concept_check.h>
23#include <lemon/concepts/maps.h>
24#include <lemon/maps.h>
25
26#include "test_tools.h"
27
28using namespace lemon;
29using namespace lemon::concepts;
30
31struct A {};
32inline bool operator<(A, A) { return true; }
33struct B {};
34
35class F {
36public:
37  typedef A argument_type;
38  typedef B result_type;
39
40  B operator()(const A &) const {return B();}
41};
42
43int func(A) {return 3;}
44
45int binc(int, B) {return 4;}
46
47typedef ReadMap<A,double> DoubleMap;
48typedef ReadWriteMap<A, double> WriteDoubleMap;
49
50typedef ReadMap<A,bool> BoolMap;
51typedef ReadWriteMap<A, bool> BoolWriteMap;
52
53int main()
54{ // checking graph components
55 
56  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
57  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
58  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
59  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
60
61  checkConcept<ReadMap<A,double>, AddMap<DoubleMap,DoubleMap> >();
62  checkConcept<ReadMap<A,double>, SubMap<DoubleMap,DoubleMap> >();
63  checkConcept<ReadMap<A,double>, MulMap<DoubleMap,DoubleMap> >();
64  checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >();
65  checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
66  checkConcept<ReadWriteMap<A,double>, NegWriteMap<WriteDoubleMap> >();
67  checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
68  checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
69  checkConcept<ReadWriteMap<A,double>, ShiftWriteMap<WriteDoubleMap> >();
70  checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
71  checkConcept<ReadWriteMap<A,double>, ScaleWriteMap<WriteDoubleMap> >();
72  checkConcept<ReadMap<A,double>, ForkMap<DoubleMap, DoubleMap> >();
73  checkConcept<ReadWriteMap<A,double>,
74    ForkWriteMap<WriteDoubleMap, WriteDoubleMap> >();
75 
76  checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
77
78  checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
79
80  checkConcept<ReadMap<A, bool>, NotMap<BoolMap> >();
81  checkConcept<ReadWriteMap<A, bool>, NotWriteMap<BoolWriteMap> >();
82
83  checkConcept<WriteMap<A, bool>, StoreBoolMap<A*> >();
84  checkConcept<WriteMap<A, bool>, BackInserterBoolMap<std::deque<A> > >();
85  checkConcept<WriteMap<A, bool>, FrontInserterBoolMap<std::deque<A> > >();
86  checkConcept<WriteMap<A, bool>, InserterBoolMap<std::set<A> > >();
87  checkConcept<WriteMap<A, bool>, FillBoolMap<WriteMap<A, B> > >();
88  checkConcept<WriteMap<A, bool>, SettingOrderBoolMap<WriteMap<A, int> > >();
89
90  int a;
91 
92  a=mapFunctor(constMap<A,int>(2))(A());
93  check(a==2,"Something is wrong with mapFunctor");
94
95  B b;
96  b=functorMap(F())[A()];
97
98  a=functorMap(&func)[A()];
99  check(a==3,"Something is wrong with functorMap");
100
101  a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
102  check(a==4,"Something is wrong with combineMap");
103 
104
105  std::cout << __FILE__ ": All tests passed.\n";
106 
107  return 0;
108}
Note: See TracBrowser for help on using the repository browser.