PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PNodeTest.cpp
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: PNodeTest.cpp
4// Purpose: Tests the Variant 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/Variant.h"
29#include "../base/grammar.tab.hpp"
30#include <iostream>
31
32using std::cout;
33using std::endl;
34using std::flush;
35
36
37//The following is the entry point for the command-line version
38int main(int argc, char **argv)
39{
40 long int a = 12341;
41 long double b = 3352.9933;
42
43
44 cout << "\n\n\n==========================================================\n";
45 cout << "Testing the PNode Class\n";
46 cout << "==========================================================\n";
47
48 /* The PNode test is pretty lame because the class doesn't do much
49 * in and of itself. Probably should use an Evaluator to test it
50 * better.
51 */
52
53 cout << "Constructing Variants" << endl;
54 Variant v1 = 27; //An integer Variant
55 Variant v2 = 343.1234; //A float Variant
56 Variant v3 = Variant("Potato",P_DATA_VARIABLE);//A Variable variant
57
58
59 cout << "\n\n\n---------------------------------------------\n";
60 cout << "Creating new PNodes (All Datanodes)";
61 cout << "\n\n\n---------------------------------------------\n";
62
63 cout << "Creating p0" << endl;
64 PNode * p0 = new DataNode();
65
66
67 cout << "Creating p1" << endl;
68 PNode * p1 = new DataNode(v2);
69
70 cout << "Creating p2" << endl;
71 PNode * p2 = new DataNode(v2);
72
73 cout << "\n\n\n---------------------------------------------\n";
74 cout << "Printing PNodes (All Datanodes)\n";
75 cout << "---------------------------------------------\n";
76
77 cout << *p0 << endl;
78 cout << *p1 << endl;
79 cout << *p2 << endl;
80
81
82
83 cout << "\n\n\n---------------------------------------------\n";
84 cout << "Creating p3" << endl;
85 cout << "---------------------------------------------\n";
86
87 DataNode * p3 = new DataNode(v3);
88
89
90 cout << "Retrieving the variant in P3" << endl;
91 v2 =p3->GetValue();
92 cout << "value: " << flush << v2 << endl;
93
94
95 cout << "---------------------------------------------\n";
96 //-----------------------------------------------
97 cout << "Creating p4" << endl;
98 PNode * p4 = new OpNode(PEBL_ADD, p0, p1);
99
100 cout << "Creating p5" << endl;
101 PNode * p5 = new OpNode(PEBL_SUBTRACT, p2, p3);
102
103 cout << "Creating p6" << endl;
104 PNode * p6 = new OpNode(PEBL_ADD, p4, p5);
105
106
107 cout << "\n\n\n---------------------------------------------\n";
108 cout << "Printing PNodes (Datanodes and Opnodes)\n";
109 cout << "---------------------------------------------\n";
110
111 cout << *p0 << endl;
112 cout << *p1 << endl;
113 cout << *p2 << endl;
114
115
116 cout << *p4 << endl;
117 cout << *p5 << endl;
118 cout << *p6 << endl;
119
120
121
122 cout << "\n\n\n---------------------------------------------\n";
123 cout << "Realigning nodes.\n";
124 cout << "---------------------------------------------\n";
125
126 p0 = ((OpNode*)p6)->GetRight();
127 p1 = ((OpNode*)p5)->GetRight();
128
129 cout << *p0 << endl;
130 cout << *p1 << endl;
131
132 cout << "Finished" << endl;
133 return 0;
134}
135
int main(int argc, char **argv)
Definition PNodeTest.cpp:38
const Variant & GetValue() const
Definition PNode.h:152
Definition PNode.h:45