ready for surrender

This commit is contained in:
hugogogo
2022-06-27 15:55:18 +02:00
parent 6617d6cdf5
commit 26436c8d8a
11 changed files with 217 additions and 143 deletions

View File

@@ -73,6 +73,11 @@ void tests_map_relational_operators();
void tests_map_swap_non_member();
// stack
void tests_stack_constructor();
void tests_stack_empty();
void tests_stack_size();
void tests_stack_top();
void tests_stack_push();
void tests_stack_pop();
#endif

View File

@@ -41,6 +41,7 @@
// prototypes
// *********************************************
// abstract class test -----------------------
struct A_test
{
virtual ~A_test(){};
@@ -48,6 +49,7 @@ struct A_test
std::string type;
virtual void func() = 0;
};
// mystruct ----------------------------------
struct mystruct {
public:
mystruct(int data = 0);
@@ -57,6 +59,7 @@ private:
int * _val;
};
std::ostream & operator<<(std::ostream & o, mystruct const * rhs);
// functions ---------------------------------
void add_to_list(std::string title, std::string type, A_test* test);
void delete_structs();
@@ -70,17 +73,19 @@ extern std::vector< mystruct* > mem_list;
// adding each test to the list
// ***************************
#define TEST(f_name) TEST_V(f_name)
/*
add_to_list(#f_name, "char", new(s_ ## f_name <char>));\
add_to_list(#f_name, "std::string", new(s_ ## f_name <std::string>));\
add_to_list(#f_name, "mystruct*", new(s_ ## f_name <mystruct*>));\
*/
#define TEST_V(f_name) \
template <class T> struct s_ ## f_name : public A_test\
{ void func(); };\
void f_name () {\
add_to_list("", "", NULL);\
add_to_list(#f_name, "int", new(s_ ## f_name <int>));\
add_to_list(#f_name, "char", new(s_ ## f_name <char>));\
add_to_list(#f_name, "std::string", new(s_ ## f_name <std::string>));\
add_to_list(#f_name, "mystruct*", new(s_ ## f_name <mystruct*>));\
}\
template <class T>\
void s_ ## f_name <T>::func()
@@ -93,16 +98,15 @@ extern std::vector< mystruct* > mem_list;
add_to_list(#f_name, "char, int", new(s_ ## f_name <char, int>));\
add_to_list(#f_name, "char, char", new(s_ ## f_name <char, char>));\
add_to_list(#f_name, "char, std::string", new(s_ ## f_name <char, std::string>));\
add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name <char, mystruct*>));\
add_to_list(#f_name, "int, int", new(s_ ## f_name <int, int>));\
add_to_list(#f_name, "int, char", new(s_ ## f_name <int, char>));\
add_to_list(#f_name, "int, std::string", new(s_ ## f_name <int, std::string>));\
add_to_list(#f_name, "int, mystruct*", new(s_ ## f_name <int, mystruct*>));\
}\
template <class T, class U>\
void s_ ## f_name <T, U>::func()
/*
add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name <char, mystruct*>));\
add_to_list(#f_name, "int, mystruct*", new(s_ ## f_name <int, mystruct*>));\
*/
// templates print

View File

@@ -4,87 +4,68 @@
int main() {
// VECTOR
// tests_vector_constructor();
// tests_vector_operator_assignation();
// tests_vector_begin();
// tests_vector_end();
// tests_vector_rbegin();
// tests_vector_rend();
// tests_vector_size();
// tests_vector_max_size();
// tests_vector_resize();
// tests_vector_capacity();
// tests_vector_empty();
// tests_vector_reserve();
// tests_vector_operator_access();
// tests_vector_at();
// tests_vector_front();
// tests_vector_back();
// tests_vector_assign();
// tests_vector_push_back();
// tests_vector_pop_back();
// tests_vector_insert();
// tests_vector_erase();
// tests_vector_swap();
// tests_vector_clear();
// tests_vector_get_allocator();
// tests_vector_relational_operators();
// tests_vector_swap_non_member();
// tests_vector_reverse_iterators();
tests_vector_constructor();
tests_vector_operator_assignation();
tests_vector_begin();
tests_vector_end();
tests_vector_rbegin();
tests_vector_rend();
tests_vector_size();
tests_vector_max_size();
tests_vector_resize();
tests_vector_capacity();
tests_vector_empty();
tests_vector_reserve();
tests_vector_operator_access();
tests_vector_at();
tests_vector_front();
tests_vector_back();
tests_vector_assign();
tests_vector_push_back();
tests_vector_pop_back();
tests_vector_insert();
tests_vector_erase();
tests_vector_swap();
tests_vector_clear();
tests_vector_get_allocator();
tests_vector_swap_non_member();
tests_vector_reverse_iterators();
tests_vector_relational_operators();
// MAP
// tests_map_simple();
// tests_map_constructor();
// tests_map_operator_assignation();
// tests_map_begin();
// tests_map_end();
// tests_map_rbegin();
// tests_map_rend();
// tests_map_empty();
// tests_map_size();
// tests_map_max_size();
// tests_map_operator_access();
// tests_map_insert();
// tests_map_erase();
// tests_map_swap();
// tests_map_clear();
// tests_map_key_comp();
// tests_map_value_comp();
// tests_map_find();
// tests_map_count();
// tests_map_lower_bound();
// tests_map_upper_bound();
// tests_map_equal_range();
// tests_map_get_allocator();
// tests_map_relational_operators();
// tests_map_swap_non_member();
tests_map_simple();
tests_map_constructor();
tests_map_operator_assignation();
tests_map_begin();
tests_map_end();
tests_map_rbegin();
tests_map_rend();
tests_map_empty();
tests_map_size();
tests_map_max_size();
tests_map_operator_access();
tests_map_insert();
tests_map_erase();
tests_map_swap();
tests_map_clear();
tests_map_key_comp();
tests_map_value_comp();
tests_map_find();
tests_map_count();
tests_map_lower_bound();
tests_map_upper_bound();
tests_map_equal_range();
tests_map_get_allocator();
tests_map_swap_non_member();
tests_map_relational_operators();
// STACK
tests_stack_constructor();
// tests_stack_operator_assignation();
// tests_stack_begin();
// tests_stack_end();
// tests_stack_rbegin();
// tests_stack_rend();
// tests_stack_size();
// tests_stack_max_size();
// tests_stack_resize();
// tests_stack_capacity();
// tests_stack_empty();
// tests_stack_reserve();
// tests_stack_operator_access();
// tests_stack_at();
// tests_stack_front();
// tests_stack_back();
// tests_stack_assign();
// tests_stack_push_back();
// tests_stack_pop_back();
// tests_stack_insert();
// tests_stack_erase();
// tests_stack_swap();
// tests_stack_clear();
// tests_stack_get_allocator();
tests_stack_empty();
tests_stack_size();
tests_stack_top();
tests_stack_push();
tests_stack_pop();
// execute tests and print them :
int size = test_list.size();

View File

@@ -5,7 +5,8 @@ TEST_DIR=$(dirname $0)
OUTPUT_STL="output_stl.log"
OUTPUT_FT="output_ft.log"
make > /dev/null
#make -j > /dev/null
make -j
echo -e "\nstl :"
time ./containers_ft > tests/$OUTPUT_STL
@@ -15,4 +16,4 @@ time ./containers_stl > tests/$OUTPUT_FT
diff --context=0 --color=always tests/$OUTPUT_STL tests/$OUTPUT_FT
/bin/rm $TEST_DIR/$OUTPUT_STL $TEST_DIR/$OUTPUT_FT
#/bin/rm $TEST_DIR/$OUTPUT_STL $TEST_DIR/$OUTPUT_FT

View File

@@ -36,13 +36,10 @@ void delete_structs() {
// ***********************************************
mystruct::mystruct(int data)
{_val = new int[2]; _val[0] = data; _val[1] = data;}
mystruct::~mystruct()
{delete[] _val;}
int * mystruct::get_data() const
{return _val;}
std::ostream & operator<<(std::ostream & o, mystruct const * rhs) {
if (rhs != NULL)
o << (*rhs).get_data()[0] << "," << (*rhs).get_data()[1];

View File

@@ -1,29 +1,135 @@
#include "tests_utils.hpp"
#ifdef STL
#define DEQ_VEC deque
#else
#define DEQ_VEC vector
#endif
TEST(tests_stack_constructor)
{
// title
TITLE(simple test)
std::deque<T> mydeque (3,VAL(100)); // deque with 3 elements
std::vector<T> myvector (2,VAL(200)); // vector with 2 elements
ft::DEQ_VEC<T> mycont (2,VAL(200)); // ft::vector/stl::deque with 2 elements
ft::vector<T> myvector (2,VAL(200)); // vector with 2 elements
ft::stack<T> first; // empty stack
ft::stack<T> second (mydeque); // stack initialized to copy of deque
ft::stack<T> second (mycont); // stack initialized to copy of vector
// ft::stack< T,std::vector<T> > third; // empty stack using vector
// ft::stack< T,std::vector<T> > fourth (myvector);
//
// std::cout << "size of first: " << first.size() << '\n';
// std::cout << "size of second: " << second.size() << '\n';
// std::cout << "size of third: " << third.size() << '\n';
// std::cout << "size of fourth: " << fourth.size() << '\n';
//
// PRINT(first)
// PRINT(second)
// PRINT(third)
// PRINT(fourth)
//
// DELETE
ft::stack< T,ft::vector<T> > third; // empty stack using vector
ft::stack< T,ft::vector<T> > fourth (myvector);
std::cout << "size of first: " << first.size() << '\n';
std::cout << "size of second: " << second.size() << '\n';
std::cout << "size of third: " << third.size() << '\n';
std::cout << "size of fourth: " << fourth.size() << '\n';
PRINT(first)
PRINT(second)
PRINT(third)
PRINT(fourth)
DELETE
}
TEST(tests_stack_empty)
{
// title
TITLE(simple test)
ft::stack<T> mystack;
int sum (0);
for (int i=1;i<=10;i++) mystack.push(VAL(i));
while (!mystack.empty())
{
sum += TOI(mystack.top());
mystack.pop();
}
std::cout << "total: " << sum << '\n';
PRINT(mystack)
DELETE
}
TEST(tests_stack_size)
{
// title
TITLE(simple test)
ft::stack<T> myints;
std::cout << "0. size: " << myints.size() << '\n';
for (int i=0; i<5; i++) myints.push(VAL(i));
std::cout << "1. size: " << myints.size() << '\n';
myints.pop();
std::cout << "2. size: " << myints.size() << '\n';
PRINT(myints)
DELETE
}
TEST(tests_stack_top)
{
// title
TITLE(simple test)
ft::stack<T> mystack;
mystack.push(VAL(10));
std::cout << "mystack.top() is now " << mystack.top() << '\n';
mystack.push(VAL(20));
std::cout << "mystack.top() is now " << mystack.top() << '\n';
mystack.push(VAL(-12));
std::cout << "mystack.top() is now " << mystack.top() << '\n';
mystack.push(VAL(26));
std::cout << "mystack.top() is now " << mystack.top() << '\n';
// mystack.top() -= VAL(5);
PRINT(mystack)
DELETE
}
TEST(tests_stack_push)
{
// title
TITLE(simple test)
ft::stack<T> mystack;
for (int i=0; i<5; ++i) mystack.push(VAL(i));
PRINT(mystack)
DELETE
}
TEST(tests_stack_pop)
{
// title
TITLE(simple test)
ft::stack<T> mystack;
for (int i=0; i<5; ++i) mystack.push(VAL(i));
std::cout << "Popping out elements...";
while (!mystack.empty())
{
std::cout << ' ' << mystack.top();
mystack.pop();
}
std::cout << '\n';
DELETE
}