d08 ajouts de tests et reparation ex02
This commit is contained in:
@@ -32,9 +32,8 @@ D_SRCS = .
|
||||
SRCS = main.cpp
|
||||
|
||||
D_HEADERS = .
|
||||
HEADERS =
|
||||
#HEADERS = colors.h \
|
||||
# MutantStack.hpp
|
||||
HEADERS = colors.h \
|
||||
MutantStack.hpp
|
||||
|
||||
D_OBJS = builds
|
||||
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)
|
||||
|
||||
@@ -7,22 +7,24 @@ template <typename T>
|
||||
class MutantStack : public std::stack<T> {
|
||||
|
||||
public:
|
||||
/*
|
||||
typedef T * iterator;
|
||||
typedef T const * const_iterator;
|
||||
|
||||
iterator begin() {return (&this->top() - (this->size() - 1));}
|
||||
iterator end() {return (&this->top()+ 1);}
|
||||
iterator end() {return (&this->top() + 1);}
|
||||
|
||||
const_iterator begin() const {return (&this->top() - (this->size() - 1));}
|
||||
const_iterator end() const {return (&this->top()+ 1);}
|
||||
const_iterator end() const {return (&this->top() + 1);}
|
||||
*/
|
||||
|
||||
// typedef typename std::stack<T>::container_type::iterator iterator;
|
||||
// typedef typename std::stack<T>::container_type::const_iterator const_iterator;
|
||||
|
||||
// iterator begin() {return this->c.begin();}
|
||||
// iterator end() {return this->c.end();}
|
||||
// const_iterator begin() const {return this->c.begin();}
|
||||
// const_iterator end() const {return this->c.end();}
|
||||
typedef typename std::stack<T>::container_type::iterator iterator;
|
||||
typedef typename std::stack<T>::container_type::const_iterator const_iterator;
|
||||
|
||||
iterator begin() {return this->c.begin();}
|
||||
iterator end() {return this->c.end();}
|
||||
const_iterator begin() const {return this->c.begin();}
|
||||
const_iterator end() const {return this->c.end();}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include <iostream>
|
||||
#include "colors.h"
|
||||
#include "MutantStack.hpp"
|
||||
#include <cstdlib> // rand
|
||||
|
||||
#define N_TEST "2"
|
||||
#define N_TEST "3"
|
||||
|
||||
int main() {
|
||||
int i = 0;
|
||||
srand(time(NULL));
|
||||
|
||||
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||
<< "test simple iterator :" RESET "\n";
|
||||
@@ -26,6 +28,100 @@ int main() {
|
||||
std::cout << *it << "\n";
|
||||
}
|
||||
|
||||
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||
<< "test stack size 128:" RESET "\n";
|
||||
{
|
||||
MutantStack<int> mstack;
|
||||
|
||||
mstack.push(-42);
|
||||
for (unsigned int i = 0; i < 126; i++)
|
||||
mstack.push(rand() % 10000000000000);
|
||||
mstack.push(42);
|
||||
|
||||
MutantStack<int>::iterator it = mstack.begin();
|
||||
MutantStack<int>::iterator ite = mstack.end();
|
||||
|
||||
std::cout << "[ ";
|
||||
for (; it != ite; it++)
|
||||
std::cout << *it << " ";
|
||||
std::cout << "]\n";
|
||||
|
||||
it = mstack.begin();
|
||||
ite = mstack.end();
|
||||
|
||||
std::cout << B_BLUE "firtst and last :" RESET "\n";
|
||||
std::cout << *it << " | " << *(ite - 1) << "\n\n";
|
||||
}
|
||||
|
||||
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||
<< "test stack size 129:" RESET "\n";
|
||||
{
|
||||
MutantStack<int> mstack;
|
||||
|
||||
mstack.push(-42);
|
||||
for (unsigned int i = 0; i < 127; i++)
|
||||
mstack.push(rand() % 10000000000000);
|
||||
mstack.push(42);
|
||||
|
||||
MutantStack<int>::iterator it = mstack.begin();
|
||||
MutantStack<int>::iterator ite = mstack.end();
|
||||
|
||||
std::cout << "[ ";
|
||||
for (; it != ite; it++)
|
||||
std::cout << *it << " ";
|
||||
std::cout << "]\n";
|
||||
|
||||
it = mstack.begin();
|
||||
ite = mstack.end();
|
||||
|
||||
std::cout << B_BLUE "firtst and last :" RESET "\n";
|
||||
std::cout << *it << " | " << *(ite - 1) << "\n\n";
|
||||
}
|
||||
|
||||
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||
<< "test stack size 10000:" RESET "\n";
|
||||
{
|
||||
MutantStack<int> mstack;
|
||||
|
||||
mstack.push(-42);
|
||||
for (unsigned int i = 0; i < 10000; i++)
|
||||
mstack.push(rand() % 10000000000000);
|
||||
mstack.push(42);
|
||||
|
||||
MutantStack<int>::iterator it = mstack.begin();
|
||||
MutantStack<int>::iterator ite = mstack.end();
|
||||
|
||||
std::cout << "[ ";
|
||||
for (; it != ite; it++)
|
||||
std::cout << *it << " ";
|
||||
std::cout << "]\n";
|
||||
|
||||
it = mstack.begin();
|
||||
ite = mstack.end();
|
||||
|
||||
std::cout << B_BLUE "firtst and last :" RESET "\n";
|
||||
std::cout << *it << " | " << *(ite - 1) << "\n\n";
|
||||
}
|
||||
|
||||
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||
<< "test const iterator :" RESET "\n";
|
||||
{
|
||||
MutantStack<int> mstack;
|
||||
|
||||
mstack.push(7);
|
||||
mstack.push(987);
|
||||
mstack.push(9);
|
||||
mstack.push(8);
|
||||
mstack.push(34);
|
||||
mstack.push(1);
|
||||
|
||||
MutantStack<int>::const_iterator it = mstack.begin();
|
||||
MutantStack<int>::const_iterator ite = mstack.end();
|
||||
|
||||
for (; it != ite; it++)
|
||||
std::cout << *it << "\n";
|
||||
}
|
||||
|
||||
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||
<< "tests subject :" RESET "\n";
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user