ready for surrender
This commit is contained in:
22
Makefile
22
Makefile
@@ -34,7 +34,7 @@ NAME = containers
|
||||
NAME_FT = containers_ft
|
||||
NAME_STL = containers_stl
|
||||
|
||||
CC = g++
|
||||
CC = clang++
|
||||
EXT = cpp
|
||||
|
||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
||||
@@ -61,14 +61,14 @@ D_SRCS = ./tests
|
||||
#SRCS = main42.cpp
|
||||
#SRCS = main_map_1.cpp
|
||||
#SRCS = main_map_2.cpp
|
||||
SRCS = main_stack_1.cpp
|
||||
#SRCS = \
|
||||
# main.cpp \
|
||||
# tests_definitions.cpp \
|
||||
# \
|
||||
# tests_vector.cpp \
|
||||
# tests_map.cpp \
|
||||
# tests_stack.cpp
|
||||
#SRCS = main_stack_1.cpp
|
||||
SRCS = \
|
||||
main.cpp \
|
||||
tests_definitions.cpp \
|
||||
\
|
||||
tests_vector.cpp \
|
||||
tests_map.cpp \
|
||||
tests_stack.cpp
|
||||
|
||||
D_HEADERS = ./headers
|
||||
HEADERS = \
|
||||
@@ -124,13 +124,13 @@ $(D_OBJS_STL)/%.o: %.$(EXT) | $(D_OBJS_STL)
|
||||
$(D_OBJS_FT) $(D_OBJS_STL):
|
||||
mkdir $@
|
||||
|
||||
$(OBJS): $(F_INCLUDES)
|
||||
$(OBJS_FT) $(OBJS_STL): $(F_INCLUDES)
|
||||
|
||||
# https://stackoverflow.com/questions/19259108/makefile-same-rule-for-multiple-targets
|
||||
$(NAME_FT): $(OBJS_FT)
|
||||
$(NAME_STL): $(OBJS_STL)
|
||||
$(NAME_FT) $(NAME_STL):
|
||||
@echo $(CYAN)"linkage (link objects.o)"$(RESET)
|
||||
@echo $(PURPLE)"linkage (link objects.o)"$(RESET)
|
||||
@$(CC) $^ -o $@ $(LIBS)
|
||||
|
||||
leaks: leaksft
|
||||
|
||||
BIN
containers_ft
BIN
containers_ft
Binary file not shown.
BIN
containers_stl
Executable file
BIN
containers_stl
Executable file
Binary file not shown.
@@ -6,34 +6,15 @@ namespace ft {
|
||||
|
||||
template <class InputIt1, class InputIt2>
|
||||
bool lexicographical_compare
|
||||
( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) {
|
||||
( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2 ) {
|
||||
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (first2 == last2 || *first2 < *first1)
|
||||
return false;
|
||||
else if (*first1 < *first2)
|
||||
for (; first1 != last1; first1++, first2++) {
|
||||
if (*first1 < *first2)
|
||||
return true;
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return (first2 != last2);
|
||||
}
|
||||
|
||||
template <class InputIt1, class InputIt2, class Compare>
|
||||
bool lexicographical_compare
|
||||
( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp) {
|
||||
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (first2 == last2 || comp(*first2, *first1))
|
||||
if (*first2 < *first1)
|
||||
return false;
|
||||
else if (comp(*first1, *first2))
|
||||
return true;
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return (first2 != last2);
|
||||
return (first1 == last1 && first2 != last2);
|
||||
}
|
||||
|
||||
} // namespace ft
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace ft {
|
||||
template <
|
||||
typename T,
|
||||
typename Container = ft::vector<T>
|
||||
> class stack
|
||||
{
|
||||
> class stack {
|
||||
|
||||
public:
|
||||
typedef Container container_type;
|
||||
typedef typename Container::value_type value_type;
|
||||
@@ -22,7 +22,6 @@ public:
|
||||
************/
|
||||
// constructors ------------------------------
|
||||
explicit stack(const container_type& cont = Container()) : c(cont) {}
|
||||
explicit stack(stack const &other): c(other.c) {}
|
||||
|
||||
|
||||
/**********************
|
||||
@@ -55,7 +54,7 @@ public:
|
||||
friend bool operator>=(const stack<T2,C2>& lhs, const stack<T2,C2>& rhs);
|
||||
|
||||
protected:
|
||||
Container c;
|
||||
container_type c;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
133
tests/main.cpp
133
tests/main.cpp
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user