test/maps_test.cc
author deba
Fri, 24 Feb 2006 11:13:09 +0000
changeset 1984 d4cbd10e1256
parent 1675 fa89ffb27a6d
child 2032 18c08f9129e4
permissions -rw-r--r--
Bug fix
alpar@1956
     1
/* -*- C++ -*-
alpar@1956
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1956
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@1956
     8
 *
alpar@1956
     9
 * Permission to use, modify and distribute this software is granted
alpar@1956
    10
 * provided that this copyright notice appears in all copies. For
alpar@1956
    11
 * precise terms see the accompanying LICENSE file.
alpar@1956
    12
 *
alpar@1956
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1956
    14
 * express or implied, and with no claim as to its suitability for any
alpar@1956
    15
 * purpose.
alpar@1956
    16
 *
alpar@1956
    17
 */
alpar@1956
    18
alpar@1041
    19
#include <lemon/concept_check.h>
alpar@1041
    20
#include <lemon/concept/maps.h>
alpar@1041
    21
#include <lemon/maps.h>
alpar@1041
    22
alpar@1041
    23
#include "test_tools.h"
alpar@1041
    24
alpar@1041
    25
using namespace lemon;
alpar@1041
    26
using namespace lemon::concept;
alpar@1041
    27
alpar@1041
    28
struct A {};
alpar@1041
    29
struct B {};
deba@1675
    30
deba@1675
    31
class F {
alpar@1076
    32
public:
deba@1675
    33
  typedef A argument_type;
deba@1675
    34
  typedef B result_type;
deba@1675
    35
alpar@1375
    36
  B operator()(const A &) const {return B();}
alpar@1076
    37
};
alpar@1076
    38
alpar@1375
    39
int func(A) {return 3;}
alpar@1041
    40
deba@1675
    41
int binc(int, B) {return 4;}
deba@1675
    42
alpar@1041
    43
typedef ReadMap<A,double> DoubleMap;
alpar@1041
    44
alpar@1041
    45
int main()
alpar@1041
    46
{ // checking graph components
alpar@1041
    47
  
alpar@1041
    48
  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
alpar@1041
    49
  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
alpar@1041
    50
  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
alpar@1041
    51
  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
alpar@1041
    52
alpar@1041
    53
  checkConcept<ReadMap<A,double>, AddMap<DoubleMap,DoubleMap> >();
alpar@1041
    54
  checkConcept<ReadMap<A,double>, SubMap<DoubleMap,DoubleMap> >();
alpar@1041
    55
  checkConcept<ReadMap<A,double>, MulMap<DoubleMap,DoubleMap> >();
alpar@1041
    56
  checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >();
alpar@1041
    57
  checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
alpar@1041
    58
  checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
alpar@1070
    59
  checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
alpar@1070
    60
  checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
alpar@1041
    61
  
alpar@1041
    62
  checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
alpar@1041
    63
deba@1675
    64
  checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
alpar@1076
    65
alpar@1076
    66
  int a;
alpar@1076
    67
  
alpar@1076
    68
  a=mapFunctor(constMap<A,int>(2))(A());
alpar@1076
    69
  check(a==2,"Something is wrong with mapFunctor");
alpar@1076
    70
alpar@1076
    71
  B b;
deba@1675
    72
  b=functorMap(F())[A()];
alpar@1076
    73
deba@1675
    74
  a=functorMap(&func)[A()];
alpar@1076
    75
  check(a==3,"Something is wrong with functorMap");
alpar@1076
    76
deba@1675
    77
  a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
deba@1675
    78
  check(a==4,"Something is wrong with combineMap");
deba@1675
    79
  
deba@1675
    80
alpar@1041
    81
  std::cout << __FILE__ ": All tests passed.\n";
alpar@1041
    82
  
alpar@1041
    83
  return 0;
alpar@1041
    84
}