Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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
27using lib::append_all;
28using util::isnil;
29using std::string;
30using std::vector;
31
32
33namespace lib {
34namespace diff{
35namespace 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
48 using DiffSeq = vector<DiffStep>;
49
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
Detect and describe changes in a monitored data sequence.
Interpreter interface to define the operations ("verbs"), which describe differences or changes in a ...
Definition list-diff.hpp:64
#define TOK(id)
#define DiffStep_CTOR(_ID_)
shortcut to define tokens of the diff language.
Helpers for working with iterators based on the pipeline model.
Compare two data sequences to find or describe differences.
Implementation namespace for support and library code.
void append_all(IT iter, CON &container)
Test runner and basic definitions for tests.
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...