stack.test.cc

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 #include <lestes/common.hh>
00029 #include <lestes/std/stack.hh>
00030 #include <lestes/std/vector.hh>
00031 
00032 using namespace ::lestes;
00033 using namespace ::lestes::std;
00034 
00035 int main()
00036 {
00037         ptr < stack < int > > q0 = stack < int > :: create();
00038         lassert(q0->empty());
00039         q0->push(1);
00040         lassert(q0->top() == 1);
00041         lassert(!q0->empty());
00042         q0->push(2);
00043         lassert(q0->top() == 2);
00044         q0->push(3);
00045         lassert(q0->top() == 3);
00046         q0->pop();
00047         lassert(q0->top() == 2);
00048         q0->push(4);
00049         lassert(q0->top() == 4);
00050         q0->push(5);
00051         lassert(q0->top() == 5);
00052         q0->push(6);
00053         lassert(q0->top() == 6);
00054         q0->pop();
00055         lassert(q0->top() == 5);
00056         q0->pop();
00057         lassert(q0->top() == 4);
00058         q0->pop();
00059         lassert(q0->top() == 2);
00060         q0->pop();
00061         lassert(q0->top() == 1);
00062         q0->pop();
00063         lassert(q0->empty());
00064 
00065 #if vector_is_manhandled_to_be_usable_in_stack
00066         ptr < stack < int, vector < int > > > q1 = stack < int, vector < int > > :: create();
00067         lassert(q1->empty());
00068         q1->push(1);
00069         lassert(q1->top() == 1);
00070         lassert(!q1->empty());
00071         q1->push(2);
00072         lassert(q1->top() == 2);
00073         q1->push(3);
00074         lassert(q1->top() == 3);
00075         q1->pop();
00076         lassert(q1->top() == 2);
00077         q1->push(4);
00078         lassert(q1->top() == 4);
00079         q1->push(5);
00080         lassert(q1->top() == 5);
00081         q1->push(6);
00082         lassert(q1->top() == 6);
00083         q1->pop();
00084         lassert(q1->top() == 5);
00085         q1->pop();
00086         lassert(q1->top() == 4);
00087         q1->pop();
00088         lassert(q1->top() == 2);
00089         q1->pop();
00090         lassert(q1->top() == 1);
00091         q1->pop();
00092         lassert(q1->empty());
00093 #else
00094         ptr < object > q1 = stack < srp < object > > :: create();
00095 #endif
00096 
00097         ptr < stack < srp < object > > > q2 = stack < srp < object >  > :: create();
00098         lassert(q2->empty());
00099         q2->push(q0);
00100         lassert(q2->top() == q0);
00101         lassert(!q2->empty());
00102         q2->push(q1);
00103         lassert(q2->top() != q0);
00104         lassert(q2->top() == q1);
00105         lassert(!q2->empty());
00106         q2->pop();
00107         lassert(q2->top() == q0);
00108         lassert(!q2->empty());
00109         q2->push(q2);
00110         lassert(q2->top() == q2);
00111         q2->pop();
00112         lassert(q2->top() == q0);
00113         q2->pop();
00114         lassert(q2->empty());
00115 
00116         
00117 }

Generated on Mon Feb 12 18:23:36 2007 for lestes by doxygen 1.5.1-20070107