d08 ajouts de tests et reparation ex02
This commit is contained in:
Binary file not shown.
@@ -68,7 +68,7 @@ bool Span::empty() const {
|
||||
* PUBLIC MEMBER FUNCTIONS
|
||||
*********************************************/
|
||||
|
||||
void Span::addNumber(int nb) {
|
||||
void Span::addNumber(int nb) {
|
||||
if (_container.size() >= _max)
|
||||
throw std::out_of_range(B_RED "out of range number" RESET);
|
||||
_container.push_back(nb);
|
||||
@@ -98,8 +98,6 @@ void Span::addNumber(InputIterator first, InputIterator last) {
|
||||
}
|
||||
template void Span::addNumber<int*>(int*, int*);
|
||||
|
||||
|
||||
|
||||
unsigned int Span::shortestSpan() {
|
||||
int const size = _container.size();
|
||||
unsigned int shortest = longestSpan();
|
||||
@@ -123,9 +121,3 @@ unsigned int Span::longestSpan() {
|
||||
return (_sort.back() - _sort.front());
|
||||
}
|
||||
|
||||
/*********************************************
|
||||
* NESTED CLASS
|
||||
*********************************************/
|
||||
|
||||
//void Span::Class::function() {}
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ public:
|
||||
Span & operator=( Span const & rhs );
|
||||
|
||||
void addNumber(int nb);
|
||||
// void addNumber(int * arr, unsigned int size);
|
||||
template <class InputIterator>
|
||||
void addNumber(InputIterator first, InputIterator last);
|
||||
// void addNumber(int * arr, unsigned int size);
|
||||
|
||||
unsigned int shortestSpan();
|
||||
unsigned int longestSpan();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "colors.h"
|
||||
#include <cstdlib> // rand
|
||||
|
||||
#include "Span.hpp"
|
||||
|
||||
|
||||
@@ -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