Lumiera  0.pre.03
»edit your freedom«
util-floorwrap-test.cpp
Go to the documentation of this file.
1 /*
2  UtilFloorwrap(Test) - verify integer scale remainder wrapping
3 
4  Copyright (C)
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/test/test-helper.hpp"
21 #include "lib/format-string.hpp"
22 #include "lib/format-cout.hpp"
23 #include "lib/util-quant.hpp"
24 
25 #include <cmath>
26 #include <boost/lexical_cast.hpp>
27 
28 using ::Test;
29 using boost::lexical_cast;
30 using util::typeStr;
31 using util::floorwrap;
32 
33 
34 namespace util {
35 namespace test {
36 
37 
38 
39 
40 
41  /***********************************************************************/
52  class UtilFloorwrap_test : public Test
53  {
54 
55  virtual void
56  run (Arg arg)
57  {
58  int range = 0 < arg.size()? lexical_cast<int> (arg[0]) : 12;
59  int scale = 1 < arg.size()? lexical_cast<int> (arg[1]) : 4;
60 
61  checkWrap (range, scale);
62  checkWrap (range, -scale);
63  checkWrap<long> (range, scale);
64  checkWrap<long> (range, -scale);
65  }
66 
67 
68  template<typename I>
69  void
70  checkWrap (I range, I scale)
71  {
72  cout << "--------"<< typeStr<I>()
73  << "--------"<< range<<"/"<<scale<<endl;
74  for (I i=range; i >=-range; --i)
75  showWrap (i, scale);
76  }
77 
78  template<typename I>
79  void
80  showWrap (I val, I scale)
81  {
82  IDiv<I> wrap = floorwrap(val,scale);
83  cout << _Fmt ("% 3d /% 1d =% 1d %% =% d floor=% 4.1f wrap = (%2d,%2d)\n")
84  % val % scale % (val/scale)
85  % (val%scale) % floor(double(val)/scale)
86  % wrap.quot % wrap.rem;
87  }
88  };
89 
90 
91 
92 
93  LAUNCHER (UtilFloorwrap_test, "unit common");
94 
95 
96 }} // namespace util::test
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
helper to treat int or long division uniformly
Definition: util-quant.hpp:42
Front-end for printf-style string template interpolation.
IDiv< I > floorwrap(I num, I den)
scale wrapping operation.
Definition: util-quant.hpp:119
A front-end for using printf-style formatting.
Simplistic test class runner.
Utilities for quantisation (grid alignment) and comparisons.
A collection of frequently used helper functions to support unit testing.