/* * stacktest.cpp * * Created on: 24.10.2012 * Author: trifon */ #include "test.h" #include "sstack.cpp" #include "lstack.cpp" typedef LStack<> TestStack; bool truetest() { return true; } bool falsetest() { return false; } bool createtest() { TestStack s; return s.empty(); } bool emptytest() { TestStack s; s.push(15); return !s.empty(); } bool peekerrortest() { TestStack s; int x; return !s.peek(x); } bool poperrortest() { TestStack s; int x; return !s.pop(x); } bool pushpeektest() { TestStack s; int x = 10; s.push(x); int y = 0; return s.peek(y) && y == x; } bool pushpoptest() { TestStack s; int x = 10; s.push(x); int y = 0; return s.pop(y) && y == x; } bool stacktest() { TestStack s; for(int i = 0; i < 10; i++) s.push(i); // s.print(); for(int i = 9; i >= 0; i--) { int j; if (!s.pop(j) || j != i) return false; } return true; } bool copytest() { TestStack s1; s1.push(10); TestStack s2 = s1; s2.print(); int x; s1.pop(x); x = 12; s1.push(x); s2.pop(x); return x == 10; } const int TEST_NUMBER = 10; Test stacktests[] = { { "TrueTest", truetest }, { "FalseTest", falsetest }, { "CreateTest", createtest }, { "EmptyTest", emptytest }, { "PeekErrorTest", peekerrortest }, { "PopErrorTest", poperrortest }, { "PushPeekTest", pushpeektest }, { "PushPopTest", pushpoptest }, { "StackTest", stacktest }, { "CopyTest", copytest }, }; int main() { runTests(stacktests, TEST_NUMBER); return 0; }