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)
5  2014, 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"
21 #include "lib/itertools.hpp"
22 #include "lib/util.hpp"
23 
24 #include <string>
25 #include <vector>
26 
27 using lib::append_all;
28 using util::isnil;
29 using std::string;
30 using std::vector;
31 
32 
33 namespace lib {
34 namespace diff{
35 namespace test{
36 
37  namespace {//Test fixture....
38 
39  using DataSeq = vector<string>;
40 
41  #define TOK(id) id(STRINGIFY(id))
42 
43  string TOK(a1), TOK(a2), TOK(a3), TOK(a4), TOK(a5);
44  string TOK(b1), TOK(b2), TOK(b3), TOK(b4);
45 
47  using DiffStep = ListDiffLanguage<string>::DiffStep;
48  using DiffSeq = vector<DiffStep>;
49 
50  DiffStep_CTOR(ins);
51  DiffStep_CTOR(del);
52  DiffStep_CTOR(pick);
53  DiffStep_CTOR(find);
54  DiffStep_CTOR(skip);
55 
56  }//(End)Test fixture
57 
58 
59 
60 
61 
62 
63 
64 
65 
66  /***********************************************************************/
78  class DiffListGeneration_test : public Test
79  {
80 
81  virtual void
82  run (Arg)
83  {
84  DataSeq toObserve({a1,a2,a3,a4,a5});
85  DiffDetector<DataSeq> detector(toObserve);
86 
87  CHECK (!detector.isChanged());
88  toObserve = {b1,a3,a5,b2,b3,a4,b4};
89  CHECK (detector.isChanged());
90 
91  auto changes = detector.pullUpdate();
92  CHECK (!isnil (changes));
93  CHECK (!detector.isChanged()); // pullUpdate() also took a new snapshot
94 
95  DiffSeq generatedDiff;
96  append_all (changes, generatedDiff);
97 
98  CHECK (generatedDiff == DiffSeq({del(a1)
99  , del(a2)
100  , ins(b1)
101  , pick(a3)
102  , find(a5)
103  , ins(b2)
104  , ins(b3)
105  , pick(a4)
106  , ins(b4)
107  , skip(a5)
108  }));
109  }
110  };
111 
112 
114  LAUNCHER (DiffListGeneration_test, "unit common");
115 
116 
117 
118 }}} // namespace lib::diff::test
Interpreter interface to define the operations ("verbs"), which describe differences or changes in a ...
Definition: list-diff.hpp:63
Definition: run.hpp:40
Implementation namespace for support and library code.
Simplistic 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.