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