PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
FunctionMapTest.cpp
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: FunctionMapTest.cpp
4// Purpose: Tests the FunctionMap 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#include "../base/PNode.h"
28#include "../base/FunctionMap.h"
29#include "../base/Variant.h"
30#include "../base/grammar.tab.hpp"
31
32#include <iostream>
33#include <stdio.h>
34
35
36//The following is the entry point for the command-line version
37int main(int argc, char **argv)
38{
39
40 using std::cout;
41 using std::endl;
42 using std::flush;
43
44 long int a = 12341;
45 long double b = 3352.9933;
46
47 cout << "\n\n\n==========================================================\n";
48 cout << "Testing the FunctionMap Class\n";
49 cout << "==========================================================\n";
50
51
52 cout << "\n\n\n==========================================================\n";
53 cout << "Making a new FunctionMap\n";
54 cout << "==========================================================\n";
55 FunctionMap myFMap; cout << "." << flush;
56
57 cout << "\n\n\n==========================================================\n";
58 cout << "Making some OpNodes\n";
59 cout << "==========================================================\n";
60 PNode *myPNode1 = new OpNode(PEBL_ADD,0,0); cout << "." << flush;
61 PNode *myPNode2 = new OpNode(PEBL_DIVIDE,0,0); cout << "." << flush;
62 PNode *myPNode3 = new OpNode(PEBL_ELSE, 0,0); cout << "." << flush;
63 PNode *myPNode4 = new OpNode(PEBL_GE,0,0); cout << "." << flush;
64 PNode *myPNode5 = new OpNode(PEBL_EQ,0,0); cout << "." << flush;
65 PNode *myPNode6;
66
67 cout << *myPNode1 << endl;
68 cout << *myPNode2 << endl;
69 cout << *myPNode3 << endl;
70 cout << *myPNode4 << endl;
71 cout << *myPNode5 << endl;
72
73 cout << "\n\n\n==========================================================\n";
74 cout << "Adding nodes to map\n";
75 cout << "==========================================================\n";
76 myFMap.AddFunction("one", (OpNode*)myPNode1); cout << "." << flush;
77 myFMap.AddFunction("two",(OpNode*)myPNode2); cout << "." << flush;
78 myFMap.AddFunction("four",(OpNode*)myPNode3); cout << "." << flush;
79 myFMap.AddFunction("four", (OpNode*)myPNode4); cout << "." << flush;
80 myFMap.AddFunction("four", (OpNode*)myPNode5); cout << "." << flush;
81
82 cout << "\n\n\n==========================================================\n";
83 cout << "Dumping entire values from map.\n";
84 cout << "==========================================================\n";
85 myFMap.DumpValues();
86
87 cout << "\n\n\n==========================================================\n";
88 cout << "Testing basic retrieval\n";
89 cout << "==========================================================\n";
90 myPNode6 = myFMap.GetFunction("four");
91 cout << " Retrieved four: " << *myPNode6 << endl;
92
93 myPNode6 = myFMap.GetFunction("two");
94 cout << " Retrieved two: " << *myPNode6 << endl;
95
96 myPNode6 = myFMap.GetFunction("one");
97 cout << " Retrieved one: " << *myPNode6 << endl;
98
99 myPNode6 = myFMap.GetFunction("nobody");
100 cout << " Retrieved nobody: " << *myPNode6 << endl;
101
102
103
104
105 cout << "\n\n\n==========================================================\n";
106 cout << "Testing Deleting\n";
107 cout << "==========================================================\n";
108
109 myFMap.DumpValues(); cout << "--\n";
110
111 cout << "Deleting 'four'" << endl;
112 myFMap.Erase("four"); myFMap.DumpValues();cout << "---------------------------\n";
113 cout << "Deleting 'two'" << endl;
114 myFMap.Erase("two"); myFMap.DumpValues();cout << "---------------------------\n";
115 cout << "Deleting 'one'" << endl;
116 myFMap.Erase("one"); myFMap.DumpValues();cout << "---------------------------\n";
117 cout << "Deleting 'one'" << endl;
118 myFMap.Erase("one"); myFMap.DumpValues();cout << "---------------------------\n";
119 cout << "Deleting 'one'" << endl;
120 myFMap.Erase("one"); myFMap.DumpValues();cout << "---------------------------\n";
121 cout << "Deleting 'four'" << endl;
122 myFMap.Erase("four"); myFMap.DumpValues();cout << "---------------------------\n";
123 cout << "Deleting 'four'" << endl;
124 myFMap.Erase("four"); myFMap.DumpValues();cout << "---------------------------\n";
125
126
127
128
129 cout << "==========================================================\n";
130 cout << "Finished Function Map Tests" << endl;
131 cout << "==========================================================\n";
132 cout << "==========================================================\n";
133 cout << "==========================================================\n";
134 cout << "==========================================================\n";
135 cout << "==========================================================\n";
136 return 0;
137}
138
int main(int argc, char **argv)
void DumpValues()
void AddFunction(std::string funcname, OpNode *node)
PNode * GetFunction(const std::string &funcname)
void Erase(const std::string &funcname)
Definition PNode.h:45