test/counter_test.cc
changeset 124 ae7785fe8431
child 171 02f4d5d9bfd7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/counter_test.cc	Sat Apr 12 20:38:51 2008 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2008
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#include <lemon/counter.h>
    1.23 +
    1.24 +///\file \brief Test cases for time_measure.h
    1.25 +///
    1.26 +///\todo To be extended
    1.27 +
    1.28 +
    1.29 +int fibonacci(int f) 
    1.30 +{
    1.31 +  static lemon::Counter count("Fibonacci steps: ");
    1.32 +  count++;
    1.33 +  if(f<1) return 0;
    1.34 +  else if(f==1) return 1;
    1.35 +  else return fibonacci(f-1)+fibonacci(f-2);
    1.36 +}
    1.37 +
    1.38 +int main()
    1.39 +{
    1.40 +  fibonacci(10);
    1.41 +  
    1.42 +  {  
    1.43 +    typedef lemon::Counter MyCounter;
    1.44 +    MyCounter c("Main counter: ");
    1.45 +    c++;
    1.46 +    c++;
    1.47 +    MyCounter::SubCounter d(c,"Subcounter: ");
    1.48 +    d++;
    1.49 +    d++;
    1.50 +    MyCounter::SubCounter::SubCounter e(d,"SubSubCounter: ");
    1.51 +    e++;
    1.52 +    e++;
    1.53 +  }
    1.54 +  
    1.55 +  {
    1.56 +    typedef lemon::NoCounter MyCounter;
    1.57 +    MyCounter c("Main counter: ");
    1.58 +    c++;
    1.59 +    c++;
    1.60 +    MyCounter::SubCounter d(c,"Subcounter: ");
    1.61 +    d++;
    1.62 +    d++;
    1.63 +    MyCounter::SubCounter::SubCounter e(d,"SubSubCounter: ");
    1.64 +    e++;
    1.65 +    e++;
    1.66 +  }
    1.67 +
    1.68 +  return 0;
    1.69 +}