COIN-OR::LEMON - Graph Library

source: lemon-0.x/test/maps_test.cc @ 1962:c1c3a0fae8a1

Last change on this file since 1962:c1c3a0fae8a1 was 1956:a055123339d5, checked in by Alpar Juttner, 15 years ago

Unified copyright notices

File size: 2.3 KB
Line 
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
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 <lemon/concept_check.h>
20#include <lemon/concept/maps.h>
21#include <lemon/maps.h>
22
23#include "test_tools.h"
24
25using namespace lemon;
26using namespace lemon::concept;
27
28struct A {};
29struct B {};
30
31class F {
32public:
33  typedef A argument_type;
34  typedef B result_type;
35
36  B operator()(const A &) const {return B();}
37};
38
39int func(A) {return 3;}
40
41int binc(int, B) {return 4;}
42
43typedef ReadMap<A,double> DoubleMap;
44
45int main()
46{ // checking graph components
47 
48  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
49  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
50  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
51  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
52
53  checkConcept<ReadMap<A,double>, AddMap<DoubleMap,DoubleMap> >();
54  checkConcept<ReadMap<A,double>, SubMap<DoubleMap,DoubleMap> >();
55  checkConcept<ReadMap<A,double>, MulMap<DoubleMap,DoubleMap> >();
56  checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >();
57  checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
58  checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
59  checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
60  checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
61 
62  checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
63
64  checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
65
66  int a;
67 
68  a=mapFunctor(constMap<A,int>(2))(A());
69  check(a==2,"Something is wrong with mapFunctor");
70
71  B b;
72  b=functorMap(F())[A()];
73
74  a=functorMap(&func)[A()];
75  check(a==3,"Something is wrong with functorMap");
76
77  a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
78  check(a==4,"Something is wrong with combineMap");
79 
80
81  std::cout << __FILE__ ": All tests passed.\n";
82 
83  return 0;
84}
Note: See TracBrowser for help on using the repository browser.