/* * stack_test.cpp * * Created on: 17.10.2013 * Author: trifon */ #include "test.h" #include "sstack.cpp" #include "lstack.cpp" typedef LStack TestStack; bool emptyTest() { return TestStack().empty(); } bool emptyPushTest() { TestStack s; s.push(10); return !s.empty(); } bool popTopErrorTest() { TestStack s; int x; return !s.top(x) && !s.pop(x); } bool topPushTest() { TestStack s; s.push(10); int x = 0; return s.top(x) && x == 10; } bool popPushTest() { TestStack s; for(int i = 0; i < 5; i++) s.push(i); int x; for(int i = 4; i >= 0; i--) if (!s.pop(x) || x != i) return false; return s.empty(); } bool copyTest() { TestStack s1; s1.push(1); TestStack s2 = s1; s2 = s1; int x; s1.pop(x); s1.push(2); return s2.pop(x) && x == 1; } int const NTESTS = 6; Test tests[] = { { "emptyTest", emptyTest }, { "emptyPushTest", emptyPushTest }, { "popTopErrorTest", popTopErrorTest }, { "topPushTest", topPushTest }, { "popPushTest", popPushTest }, { "copyTest", copyTest } }; int main() { runTests(tests, NTESTS); return 0; }