Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
advice-binding-pattern-test.cpp
Go to the documentation of this file.
1/*
2 AdviceBindingPattern(Test) - cover pattern matching used to dispatch Advice
3
4 Copyright (C)
5 2010, 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/format-cout.hpp"
22
24#include "common/advice.hpp"
25
26using lib::time::Time;
27
28
29
30namespace lumiera {
31namespace advice {
32namespace test {
33
34 namespace {
35 class DummyAdvice { };
36 }
37
38
39
40 /***************************************************************************/
57 class AdviceBindingPattern_test : public Test
58 {
59
60 virtual void
69
70
71 void
73 {
74#define _PARSE_AND_SHOW(_STR_) \
75 cout << _STR_ << "\t--->" << Binding(_STR_) << endl;
76
77 _PARSE_AND_SHOW ("");
78 _PARSE_AND_SHOW ("aSymbol");
79 _PARSE_AND_SHOW ("a.compound_Symbol-with-various.parts");
80 _PARSE_AND_SHOW ("trailing Garbage allowed. ☢☢ eat ☠☠☠ atomic ☠☠☠ waste ☢☢");
81 _PARSE_AND_SHOW ("a, list , of ,symbols.");
82 _PARSE_AND_SHOW ("nullary().");
83 _PARSE_AND_SHOW ("nullary( )");
84 _PARSE_AND_SHOW ("nullary .");
85 _PARSE_AND_SHOW ("predicate( with-argument )");
86
87 VERIFY_ERROR (BINDING_PATTERN_SYNTAX, Binding("no (valid definition here)"));
88 VERIFY_ERROR (BINDING_PATTERN_SYNTAX, Binding("predicate(with ☠☠☠ Garbage ☠☠☠"));
89 VERIFY_ERROR (BINDING_PATTERN_SYNTAX, Binding("§&Ω%€GΩ%€ar☠☠☠baäääääge"));
90
91 Binding testBinding;
92 testBinding.addTypeGuard<DummyAdvice>();
93 testBinding.addPredicate("one two(), three( four ).");
94
95 cout << testBinding << endl;
96 }
97
98
99 void
101 {
102 Binding b0, b00;
103 Binding b1 ("cat1(), cat2().");
104 Binding b2 (" cat2 cat1 ....");
105
106 cout << "b0==" << b0 << endl;
107 cout << "b1==" << b1 << endl;
108 cout << "b2==" << b2 << endl;
109
110
111 CHECK (b0 == b00); CHECK (b00 == b0);
112 CHECK (b1 == b2); CHECK (b2 == b1);
113
114 CHECK (b0 != b1); CHECK (b1 != b0);
115 CHECK (b0 != b2); CHECK (b2 != b0);
116
117 b2.addPredicate("cat1()"); // adding the same predicate multiple times has no effect
118 b2.addPredicate(" cat1 ");
119 CHECK (b1 == b2);
120 b2.addPredicate("cat3(zzz)");
121 CHECK (b1 != b2);
122
123 b1.addTypeGuard<Time>();
124 CHECK (b1 != b2);
125 b1.addPredicate(" cat3( zzz ) ");
126 CHECK (b1 != b2);
127 b2.addTypeGuard<Time>();
128 CHECK (b1 == b2);
129
130 cout << "b2==" << b2 << endl;
131 }
132
133
134 void
136 {
137 CHECK ( matches (Binding(), Binding()));
138 CHECK ( matches (Binding("pred()"), Binding("pred( ) ")));
139
140 CHECK ( matches (Binding("pred(x)"), Binding("pred(x)")));
141 CHECK (!matches (Binding("pred()"), Binding("pred(x)")));
142 CHECK (!matches (Binding("pred(x)"), Binding("pred(y)")));
143
144 CHECK ( matches (Binding("pred(x), pred(y)"), Binding("pred(y), pred(x)")));
145 CHECK (!matches (Binding("pred(x), pred(y)"), Binding("pred(y), pred(y)")));
146 }
147
148
149 void
151 {
152 Binding b1 ("pred()");
153 Binding b2 ("pred");
154 Binding b3 ("pred, pred(x)");
155 Binding b4 ("pred( x ) , pred().");
156 CHECK ( matches (b1,b2));
157 CHECK ( matches (b3,b4));
158
163
164 CHECK (hash_value(b1) == hash_value(bm1));
165 CHECK (hash_value(b2) == hash_value(bm2));
166 CHECK (hash_value(b3) == hash_value(bm3));
167 CHECK (hash_value(b4) == hash_value(bm4));
168
169 CHECK (hash_value(b1) != hash_value(b3));
170
171 CHECK ( matches (bm1,bm2));
172 CHECK ( matches (bm3,bm4));
173 CHECK (!matches (bm1,bm3));
174 CHECK (!matches (bm2,bm4));
175 }
176
177
184 void
186 {
187#if false
188 CHECK ( matches (Binding("pred(u)"), Binding("pred(X)")));
189 CHECK ( matches (Binding("pred(f(u))"), Binding("pred(f(X))")));
190 CHECK ( matches (Binding("pred(f(u,Y))"), Binding("pred(f(X,v))")));
191 CHECK ( matches (Binding("pred(f(u,X))"), Binding("pred(f(X,v))"))); // the so called "standardisation apart"
192
193 CHECK (!matches (Binding("pred(u,v)"), Binding("pred(X)")));
194 CHECK (!matches (Binding("pred(f(u))"), Binding("pred(f(v))")));
195 CHECK (!matches (Binding("pred(f(u))"), Binding("pred(g(X))")));
196 CHECK (!matches (Binding("pred(f(u,v))"), Binding("pred(f(X,X))")));
197
199
200#endif
201 }
202 };
203
204
205
208
209
210}}} // namespace lumiera::advice::test
#define _PARSE_AND_SHOW(_STR_)
Expecting Advice and giving Advice: a cross-cutting collaboration of loosely coupled participants.
Lumiera's internal time value datatype.
Functor object for matching against another Binding.
Conjunction of predicates to be matched against a collaboration partner for establishing an Advice co...
Binding const & addTypeGuard()
void addPredicate(Literal spec)
extend the definition of this binding by adding a predicate according to the given textual definition
Automatically use custom string conversion in C++ stream output.
HashVal hash_value(Binding::Matcher const &bm)
bool matches(Binding const &b1, Binding const &b2)
Lumiera public interface.
Definition advice.hpp:102
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
a family of time value like entities and their relationships.