✨ feat: 添加 list 实现与测试,添加 stack 测试
This commit is contained in:
11
tests/CMakeLists.txt
Normal file
11
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
## 添加 list library
|
||||
## 设置 include
|
||||
|
||||
|
||||
add_executable(test-list test-list.cpp)
|
||||
target_link_libraries(test-list list)
|
||||
target_include_directories(test-list PRIVATE ${INCLUDE_DIR})
|
||||
|
||||
|
||||
add_executable(test-stack test-stack.cpp)
|
||||
|
26
tests/test-list.cpp
Normal file
26
tests/test-list.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "list.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void test(){
|
||||
List list;
|
||||
list.push_back(1);
|
||||
list.push_back(2);
|
||||
list.push_back(3);
|
||||
|
||||
std::cout << "First elecment:" << list.front() << std::endl;
|
||||
std::cout << "Last elecment:" << list.back() << std::endl;
|
||||
std::cout << "Size:" << list.size() << std::endl;
|
||||
std::cout << "List elements:" << std::endl;
|
||||
list.dump();
|
||||
list.pop_back();
|
||||
std::cout << "After pop_back:" << std::endl;
|
||||
list.dump();
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
test();
|
||||
return 0;
|
||||
}
|
21
tests/test-stack.cpp
Normal file
21
tests/test-stack.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::stack<int> stack;
|
||||
stack.push(1);
|
||||
stack.push(2);
|
||||
stack.push(3);
|
||||
std::cout << "Current stack size: "<< stack.size() << std::endl;
|
||||
std::cout << "Stack is empty? "<< stack.empty() << std::endl;
|
||||
while (!stack.empty())
|
||||
{
|
||||
std::cout << stack.top() << " ";
|
||||
stack.pop();
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
// system("pause");
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user