d08 ajouts de tests et reparation ex02
This commit is contained in:
Binary file not shown.
@@ -98,8 +98,6 @@ void Span::addNumber(InputIterator first, InputIterator last) {
|
|||||||
}
|
}
|
||||||
template void Span::addNumber<int*>(int*, int*);
|
template void Span::addNumber<int*>(int*, int*);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int Span::shortestSpan() {
|
unsigned int Span::shortestSpan() {
|
||||||
int const size = _container.size();
|
int const size = _container.size();
|
||||||
unsigned int shortest = longestSpan();
|
unsigned int shortest = longestSpan();
|
||||||
@@ -123,9 +121,3 @@ unsigned int Span::longestSpan() {
|
|||||||
return (_sort.back() - _sort.front());
|
return (_sort.back() - _sort.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************
|
|
||||||
* NESTED CLASS
|
|
||||||
*********************************************/
|
|
||||||
|
|
||||||
//void Span::Class::function() {}
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ public:
|
|||||||
Span & operator=( Span const & rhs );
|
Span & operator=( Span const & rhs );
|
||||||
|
|
||||||
void addNumber(int nb);
|
void addNumber(int nb);
|
||||||
// void addNumber(int * arr, unsigned int size);
|
|
||||||
template <class InputIterator>
|
template <class InputIterator>
|
||||||
void addNumber(InputIterator first, InputIterator last);
|
void addNumber(InputIterator first, InputIterator last);
|
||||||
|
// void addNumber(int * arr, unsigned int size);
|
||||||
|
|
||||||
unsigned int shortestSpan();
|
unsigned int shortestSpan();
|
||||||
unsigned int longestSpan();
|
unsigned int longestSpan();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
|
#include <cstdlib> // rand
|
||||||
|
|
||||||
#include "Span.hpp"
|
#include "Span.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,8 @@ D_SRCS = .
|
|||||||
SRCS = main.cpp
|
SRCS = main.cpp
|
||||||
|
|
||||||
D_HEADERS = .
|
D_HEADERS = .
|
||||||
HEADERS =
|
HEADERS = colors.h \
|
||||||
#HEADERS = colors.h \
|
MutantStack.hpp
|
||||||
# MutantStack.hpp
|
|
||||||
|
|
||||||
D_OBJS = builds
|
D_OBJS = builds
|
||||||
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)
|
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)
|
||||||
|
|||||||
@@ -7,22 +7,24 @@ template <typename T>
|
|||||||
class MutantStack : public std::stack<T> {
|
class MutantStack : public std::stack<T> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/*
|
||||||
typedef T * iterator;
|
typedef T * iterator;
|
||||||
typedef T const * const_iterator;
|
typedef T const * const_iterator;
|
||||||
|
|
||||||
iterator begin() {return (&this->top() - (this->size() - 1));}
|
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 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::iterator iterator;
|
||||||
// typedef typename std::stack<T>::container_type::const_iterator const_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();}
|
|
||||||
|
|
||||||
|
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
|
#endif
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
#include "MutantStack.hpp"
|
#include "MutantStack.hpp"
|
||||||
|
#include <cstdlib> // rand
|
||||||
|
|
||||||
#define N_TEST "2"
|
#define N_TEST "3"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||||
<< "test simple iterator :" RESET "\n";
|
<< "test simple iterator :" RESET "\n";
|
||||||
@@ -26,6 +28,100 @@ int main() {
|
|||||||
std::cout << *it << "\n";
|
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 "] "
|
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||||
<< "tests subject :" RESET "\n";
|
<< "tests subject :" RESET "\n";
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user