PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
VariableMapTest.cpp
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: VariableMapTest.cpp
4// Purpose: Tests the VariableMap Class
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003 Shane T. Mueller <smueller@umich.edu>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
28
29
30#include "../base/Evaluator.h"
31#include "../base/FunctionMap.h"
32#include "../base/grammar.tab.hpp"
33#include "../base/Loader.h"
34
35#include "../base/PComplexData.h"
36#include "../base/PList.h"
37#include "../base/PNode.h"
38
39#include "../base/Variant.h"
40#include "../base/VariableMap.h"
41
42
43#include "../devices/PEventLoop.h"
44
45#include "../libs/PEBLObjects.h"
46
47#include "../utility/PError.h"
48#include "../utility/PEBLPath.h"
49#include "../utility/PEBLUtility.h"
50#include "../utility/rc_ptrs.h"
51
52
53#include <iostream>
54#include <stdio.h>
55
56
57using std::cout;
58using std::endl;
59using std::flush;
60
61
68
69
70//The following is the entry point for the command-line version
71int main(int argc, char **argv)
72{
73 VariableMap myVMap;
74 Variant v(33);
75 myVMap.AddVariable("one", v);
76 cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
77 myVMap.DumpValues();
78 cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
79 cout << "=========================Real test\n";
80 cout << "========================="<< myVMap.RetrieveValue("one") << endl;
81 Variant v2;
82 v2 = myVMap.RetrieveValue("one");
83 cout << "========================="<< v2 << endl;
84
87 PComplexData * pcd = new PComplexData(pob);
88 Variant v3 = Variant(pcd);
89 myVMap.AddVariable("image",v3);
90 cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
91 myVMap.DumpValues();
92 cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
93 Variant v4 = v3;
94 cout << "Copied variant:" << v4;
95 Variant v5;
96
97
98 cout <<"Extracted: " << myVMap.RetrieveValue("image") << endl;;
99 v5 = myVMap.RetrieveValue("image");
100 cout << "Extracted/assigned variant: " << v5 << endl;
101
102}
103int extra (){
104
105 long int a = 12341;
106 long double b = 3352.9933;
107
108 cout << "\n\n\n==========================================================\n";
109 cout << "Testing the VariableMap Class\n";
110 cout << "==========================================================\n";
111
112
113 cout << "\n\n\n==========================================================\n";
114 cout << "Testing basic encoding\n";
115 cout << "==========================================================\n";
116
117 VariableMap myVMap; cout << "." << flush;
118
119 Variant myVariant1(34); cout << "." << flush;
120 Variant myVariant2(33.5252); cout << "." << flush;
121 Variant myVariant3(0); cout << "." << flush;
122 int i;
123
124 myVMap.AddVariable("one", myVariant1); cout << "." << flush;
125 myVMap.AddVariable("two", myVariant2); cout << "." << flush;
126 myVMap.AddVariable("three", myVariant3); cout << "." << flush;
127 myVMap.AddVariable("four", myVariant1); cout << "." << flush;
128
129
130 cout << "\n\n\n==========================================================\n";
131 cout << "Testing basic retreival\n";
132 cout << "==========================================================\n";
133
134 myVariant3 = myVMap.RetrieveValue("one");
135 cout << " Retrieved one: " << myVariant3 << endl;
136 myVariant3 = myVMap.RetrieveValue("two");
137 cout << " Retrieved two: " << myVariant3 << endl;
138 myVariant3 = myVMap.RetrieveValue("three");
139 cout << " Retrieved three: " << myVariant3 << endl;
140 myVariant3 = myVMap.RetrieveValue("four");
141 cout << " Retrieved four: " << myVariant3 << endl;
142
143
144 cout << "\n\n\n==========================================================\n";
145 cout << "Testing overwriting\n";
146 cout << "==========================================================\n";
147
148
149 myVMap.AddVariable("one", myVariant2);
150 myVMap.AddVariable("two", myVariant3);
151 myVMap.AddVariable("three", myVariant1);
152 myVMap.AddVariable("four", myVariant2+ myVariant1);
153
154
155 myVariant3 = myVMap.RetrieveValue("one");
156 cout << " Retrieved one: " << myVariant3 << endl;
157 myVariant3 = myVMap.RetrieveValue("two");
158 cout << " Retrieved two: " << myVariant3 << endl;
159 myVariant3 = myVMap.RetrieveValue("three");
160 cout << " Retrieved three: " << myVariant3 << endl;
161 myVariant3 = myVMap.RetrieveValue("four");
162 cout << " Retrieved four: " << myVariant3 << endl;
163
164
165
166 cout << "\n\n\n==========================================================\n";
167 cout << "Testing retrieval of undefined\n";
168 cout << "==========================================================\n";
169
170 myVariant3 = myVMap.RetrieveValue("oney");
171 cout << " Retrieved oney: " << myVariant3 << endl;
172 myVariant3 = myVMap.RetrieveValue("TWO");
173 cout << " Retrieved TWO: " << myVariant3 << endl;
174 myVariant3 = myVMap.RetrieveValue("about");
175 cout << " Retrieved about: " << myVariant3 << endl;
176 myVariant3 = myVMap.RetrieveValue("something");
177 cout << " Retrieved something: " << myVariant3 << endl;
178
179 cout << "\n\n\n==========================================================\n";
180 cout << "Testing DumpValues Method\n";
181 cout << "==========================================================\n";
182
183 myVMap.DumpValues();
184
185
186 cout << "\n\n\n==========================================================\n";
187 cout << "Performance test: 1000000 reencodings\n";
188 cout << "==========================================================\n";
189
190 for(i = 0; i<1000000; i++)
191 {
192 myVMap.AddVariable("one", myVariant2);
193 if(i%1000==0) cout << "." << flush;
194 }
195 cout << "Finished 1000000 reencodings" << endl;
196
197
198
199
200 cout << "\n\n\n==========================================================\n";
201 cout << "Performance test: 1000000 reencodings with creation of new Variant\n";
202 cout << "==========================================================\n";
203
204 for(i = 0; i<1000000; i++)
205 {
206 myVMap.AddVariable("one", Variant(3435.2));
207 if(i%1000==0) cout << "." << flush;
208 }
209 cout << "Finished 1000000 reencodings" << endl;
210
211
212
213 cout << "\n\n\n==========================================================\n";
214 cout << "Performance test: 1000000 retrievals\n";
215 cout << "==========================================================\n";
216
217 for(i = 0; i<1000000; i++)
218 {
219 myVariant2 = myVMap.RetrieveValue("one");
220 if(i%1000==0) cout << "." << flush;
221 }
222 cout << "Finished 1000000 retrievals" << endl;
223
224
225
226 cout << "\n\n\n==========================================================\n";
227 cout << "Performance test: 1000000 Unique encodings\n";
228 cout << "==========================================================\n";
229
230 char name[20];
231 for(i = 0; i<1000000; i++)
232 {
233
234 sprintf(name, "%10d",i);
235
236 myVMap.AddVariable(name, Variant(i));
237 if(i%1000==0) cout << "." << flush;
238 }
239 cout << "Finished 1000000 Unique encodings" << endl;
240
241
242
243 cout << "\n\n\n==========================================================\n";
244 cout << "Performance test: 1000000 Unique retrievals\n";
245 cout << "==========================================================\n";
246
247
248 for(i = 999999; i>=0; i--)
249 {
250 sprintf(name, "%10d",i);
251 myVariant2 = myVMap.RetrieveValue(name);
252 if(i%1000==0) cout << "." << flush;
253 }
254 cout << "Finished 1000000 Unique retrievals" << endl;
255
256
257 cout << "\n\n\n==========================================================\n";
258 cout << "Performance test: 100000 Unique erases\n";
259 cout << "==========================================================\n";
260
261
262 for(i = 999999; i>=0; i--)
263 {
264 sprintf(name, "%10d",i);
265 myVMap.Erase(name);
266 if(i%1000==0) cout << "." << flush;
267 }
268 cout << "Finished 1000000 Unique retrievals" << endl;
269
270
271 cout << "==========================================================\n";
272 cout << "Dumping Remaining Values:" << endl;
273 cout << "==========================================================\n";
274 myVMap.DumpValues();
275
276
277
278
279 cout << "\n\n\n==========================================================\n";
280 cout << "Testing basic retrieval Again\n";
281 cout << "==========================================================\n";
282
283 myVariant3 = myVMap.RetrieveValue("one");
284 cout << " Retrieved one: " << myVariant3 << endl;
285 myVariant3 = myVMap.RetrieveValue("two");
286 cout << " Retrieved two: " << myVariant3 << endl;
287 myVariant3 = myVMap.RetrieveValue("three");
288 cout << " Retrieved three: " << myVariant3 << endl;
289 myVariant3 = myVMap.RetrieveValue("four");
290 cout << " Retrieved four: " << myVariant3 << endl;
291
292
293
294
295 cout << "==========================================================\n";
296 cout << "Finished Variable Map Tests" << endl;
297 cout << "==========================================================\n";
298 cout << "==========================================================\n";
299 cout << "==========================================================\n";
300 cout << "==========================================================\n";
301 cout << "==========================================================\n";
302 return 0;
303}
304
#define NULL
Definition BinReloc.cpp:317
int main(int argc, char **argv)
int extra()
static const PNode * gEvalNode
static PEBLPath gPath
static PEventLoop * mEventLoop
static VariableMap gGlobalVariableMap
static FunctionMap mFunctionMap
Initiate some static member data.
Definition PNode.h:45
Validator platform image box - no image loading, used only for compilation.
void DumpValues()
void Erase(const std::string &varname)
void AddVariable(const std::string &varname, const Variant &val)
Variant RetrieveValue(const std::string &varname)