mirror of
https://github.com/13hannes11/UU_la_parallel_programming_practical_assignments.git
synced 2024-09-04 00:50:58 +02:00
add abstract datatype datastructure for stack
This commit is contained in:
78
Assignment_3/test/ADT_Stack_test.cpp
Normal file
78
Assignment_3/test/ADT_Stack_test.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include <lib/ADT_Stack.h>
|
||||
|
||||
TEST(ADTStackTest, SimplePushPop) {
|
||||
std::vector<operation> ops;
|
||||
|
||||
ops.push_back(create_operation(methodname::push, 1));
|
||||
ops.push_back(create_operation(methodname::pop, 1));
|
||||
|
||||
ADTStack * adt = new ADTStack();
|
||||
adt->do_ops(ops);
|
||||
}
|
||||
|
||||
TEST(ADTStackTest, SimplePopWrong) {
|
||||
std::vector<operation> ops;
|
||||
ops.push_back(create_operation(methodname::push, 2));
|
||||
ops.push_back(create_operation(methodname::pop, 1));
|
||||
|
||||
ADTStack * adt = new ADTStack();
|
||||
|
||||
try {
|
||||
adt->do_ops(ops);
|
||||
FAIL() << "Expected std::invalid_argument";
|
||||
}
|
||||
catch(std::invalid_argument const & err) {
|
||||
EXPECT_EQ(err.what(),std::string("Invalid operation: pop 1 (actual top: 2)"));
|
||||
}
|
||||
catch(...) {
|
||||
FAIL() << "Expected std::invalid_argument";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ADTStackTest, PopEmpty) {
|
||||
std::vector<operation> ops;
|
||||
ops.push_back(create_operation(methodname::pop, 1));
|
||||
|
||||
ADTStack * adt = new ADTStack();
|
||||
|
||||
try {
|
||||
adt->do_ops(ops);
|
||||
FAIL() << "Expected std::invalid_argument";
|
||||
}
|
||||
catch(std::invalid_argument const & err) {
|
||||
EXPECT_EQ(err.what(),std::string("Invalid operation: pop 1 (stack is empty)"));
|
||||
}
|
||||
catch(...) {
|
||||
FAIL() << "Expected std::invalid_argument";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ADTStackTest, SizeEmpty) {
|
||||
std::vector<operation> ops;
|
||||
ops.push_back(create_operation(methodname::size, 0));
|
||||
|
||||
ADTStack * adt = new ADTStack();
|
||||
adt->do_ops(ops);
|
||||
}
|
||||
TEST(ADTStackTest, SizeEmptyWrong) {
|
||||
std::vector<operation> ops;
|
||||
ops.push_back(create_operation(methodname::size, 1));
|
||||
|
||||
ADTStack * adt = new ADTStack();
|
||||
|
||||
try {
|
||||
adt->do_ops(ops);
|
||||
FAIL() << "Expected std::invalid_argument";
|
||||
}
|
||||
catch(std::invalid_argument const & err) {
|
||||
EXPECT_EQ(err.what(),std::string("Invalid operation: size 1 (actual size: 0)"));
|
||||
}
|
||||
catch(...) {
|
||||
FAIL() << "Expected std::invalid_argument";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,3 +10,8 @@ add_executable(node_unit_test Node_test.cpp)
|
||||
target_link_libraries(node_unit_test PUBLIC gtest gtest_main)
|
||||
target_link_libraries(node_unit_test PUBLIC sets)
|
||||
add_test(NodeTest node_unit_test)
|
||||
|
||||
add_executable(adt_unit_test ADT_Stack_test.cpp)
|
||||
target_link_libraries(adt_unit_test PUBLIC gtest gtest_main)
|
||||
target_link_libraries(adt_unit_test PUBLIC sets)
|
||||
add_test(ADTTest adt_unit_test)
|
||||
|
||||
Reference in New Issue
Block a user