Lumiera  0.pre.03
»edit your freedom«
diff-list-generation-test.cpp
Go to the documentation of this file.
1 /*
2  DiffListGeneration(Test) - demonstrate list diff generation
3 
4  Copyright (C) Lumiera.org
5  2014, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
30 #include "lib/itertools.hpp"
31 #include "lib/util.hpp"
32 
33 #include <string>
34 #include <vector>
35 
36 using lib::append_all;
37 using util::isnil;
38 using std::string;
39 using std::vector;
40 
41 
42 namespace lib {
43 namespace diff{
44 namespace test{
45 
46  namespace {//Test fixture....
47 
48  using DataSeq = vector<string>;
49 
50  #define TOK(id) id(STRINGIFY(id))
51 
52  string TOK(a1), TOK(a2), TOK(a3), TOK(a4), TOK(a5);
53  string TOK(b1), TOK(b2), TOK(b3), TOK(b4);
54 
56  using DiffStep = ListDiffLanguage<string>::DiffStep;
57  using DiffSeq = vector<DiffStep>;
58 
59  DiffStep_CTOR(ins);
60  DiffStep_CTOR(del);
61  DiffStep_CTOR(pick);
62  DiffStep_CTOR(find);
63  DiffStep_CTOR(skip);
64 
65  }//(End)Test fixture
66 
67 
68 
69 
70 
71 
72 
73 
74 
75  /***********************************************************************/
87  class DiffListGeneration_test : public Test
88  {
89 
90  virtual void
91  run (Arg)
92  {
93  DataSeq toObserve({a1,a2,a3,a4,a5});
94  DiffDetector<DataSeq> detector(toObserve);
95 
96  CHECK (!detector.isChanged());
97  toObserve = {b1,a3,a5,b2,b3,a4,b4};
98  CHECK (detector.isChanged());
99 
100  auto changes = detector.pullUpdate();
101  CHECK (!isnil (changes));
102  CHECK (!detector.isChanged()); // pullUpdate() also took a new snapshot
103 
104  DiffSeq generatedDiff;
105  append_all (changes, generatedDiff);
106 
107  CHECK (generatedDiff == DiffSeq({del(a1)
108  , del(a2)
109  , ins(b1)
110  , pick(a3)
111  , find(a5)
112  , ins(b2)
113  , ins(b3)
114  , pick(a4)
115  , ins(b4)
116  , skip(a5)
117  }));
118  }
119  };
120 
121 
123  LAUNCHER (DiffListGeneration_test, "unit common");
124 
125 
126 
127 }}} // namespace lib::diff::test
Interpreter interface to define the operations ("verbs"), which describe differences or changes in a ...
Definition: list-diff.hpp:72
Definition: run.hpp:49
Implementation namespace for support and library code.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Detect and describe changes in a monitored data sequence.
Compare two data sequences to find or describe differences.
Helpers for working with iterators based on the pipeline model.
#define DiffStep_CTOR(_ID_)
shortcut to define tokens of the diff language.