/****************************************************************************/
/* */
/* Copyright (C) 1998; IPL, Information Processing Ltd */
/* */
/****************************************************************************/
/* */
/* Cantata++ Demo - Unbounded Stack Test script */
/* */
/****************************************************************************/
#include <cppth.h>
#include <cppcr.h>
#include "stack.h"
#pragma ipl cantata++ ignore on
class TEST_CLASS(stack)
{
public:
static void run_test();
static void test_1();
static void test_2();
};
void TEST_CLASS(stack)::run_test()
{
test_1();
test_2();
};
void TEST_CLASS(stack)::test_1()
{
START_TEST("Empty stack", "Test the default constructor, is_empty() and "
"pop on an empty stack");
// Set up input data
START_EXCEPTION
stack stack1;
// Run software under test and check results
CHECK(stack1.is_empty(), true);
stack1.pop();
EXPECT_EXCEPTION(stack::empty_pop)
END_EXCEPTION
END_TEST();
}
void TEST_CLASS(stack)::test_2()
{
START_TEST("Push/pop", "Test the push and pop member functions");
// Set up input data
START_EXCEPTION
stack stack1;
// Run software under test
stack1.push(3);
stack1.push(2);
stack1.push(1);
// Check results
CHECK(stack1.is_empty(), false);
CHECK(stack1.pop(), 1);
CHECK(stack1.pop(), 2);
CHECK(stack1.pop(), 3);
CHECK(stack1.is_empty(), true);
NO_EXCEPTIONS
END_EXCEPTION
END_TEST();
}
int main()
{
OPEN_LOG("test_stack.ctr");
START_SCRIPT("stack", true);
TEST_CLASS(stack)::run_test();
return !END_SCRIPT(true);
}
#pragma ipl cantata++ ignore off