re-organisation of files
This commit is contained in:
4
Makefile
4
Makefile
@@ -51,7 +51,9 @@ INCLUDES = -I$(D_HEADERS) \
|
||||
D_SRCS = ./tests
|
||||
#SRCS = main42.cpp
|
||||
SRCS = main.cpp \
|
||||
tests_vectors.cpp
|
||||
tests_vector.cpp
|
||||
|
||||
# tests_map.cpp
|
||||
|
||||
D_HEADERS = ./headers
|
||||
HEADERS = colors.h \
|
||||
|
||||
166
headers/map.hpp
Normal file
166
headers/map.hpp
Normal file
@@ -0,0 +1,166 @@
|
||||
|
||||
#ifndef MAP_HPP
|
||||
# define MAP_HPP
|
||||
|
||||
//# include "colors.h"
|
||||
//# include <iostream>
|
||||
//# include <string>
|
||||
//# include <memory> // std::allocator
|
||||
//# include <algorithm> // std::min, std::max
|
||||
//# include <stdexcept> // out_of_range, length_error, logic_error
|
||||
//# include <cstddef> // NULL, std::size_t, std::ptrdiff_t
|
||||
//
|
||||
//# include "enable_if.hpp"
|
||||
//# include "is_integral.hpp"
|
||||
//# include "reverse_iterator.hpp"
|
||||
//# include "equal.hpp"
|
||||
//# include "lexicographical_compare.hpp"
|
||||
|
||||
namespace ft {
|
||||
|
||||
//template <
|
||||
// class T,
|
||||
// class Allocator = std::allocator<T> >
|
||||
class map {
|
||||
|
||||
public:
|
||||
|
||||
// typedef T value_type;
|
||||
// typedef Allocator allocator_type;
|
||||
// typedef std::size_t size_type;
|
||||
// typedef std::ptrdiff_t difference_type;
|
||||
//
|
||||
// typedef T * iterator;
|
||||
// typedef T const * const_iterator;
|
||||
// typedef ft::reverse_iterator<iterator> reverse_iterator;
|
||||
// typedef ft::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
//
|
||||
// // dependent qualified name :
|
||||
// // https://en.cppreference.com/w/cpp/keyword/typename
|
||||
// typedef typename Allocator::reference reference;
|
||||
// typedef typename Allocator::const_reference const_reference;
|
||||
|
||||
|
||||
|
||||
/************
|
||||
* copliens :
|
||||
************/
|
||||
//// constructors ------------------------------
|
||||
// explicit map (const key_compare& comp = key_compare(),
|
||||
// const allocator_type& alloc = allocator_type());
|
||||
// template <class InputIterator>
|
||||
// map (InputIterator first, InputIterator last,
|
||||
// const key_compare& comp = key_compare(),
|
||||
// const allocator_type& alloc = allocator_type());
|
||||
// map (const map& x);
|
||||
//// destructor --------------------------------
|
||||
// ~map();
|
||||
//// operator= ---------------------------------
|
||||
// map& operator= (const map& x);
|
||||
|
||||
|
||||
/*************
|
||||
* iterators :
|
||||
*************/
|
||||
//// begin -------------------------------------
|
||||
// iterator begin();
|
||||
// const_iterator begin() const;
|
||||
//// end ---------------------------------------
|
||||
// iterator end();
|
||||
// const_iterator end() const;
|
||||
//// rbegin ------------------------------------
|
||||
// reverse_iterator rbegin();
|
||||
// const_reverse_iterator rbegin() const;
|
||||
//// rend --------------------------------------
|
||||
// reverse_iterator rend();
|
||||
// const_reverse_iterator rend() const;
|
||||
|
||||
|
||||
/************
|
||||
* capacity :
|
||||
************/
|
||||
//// empty -------------------------------------
|
||||
// bool empty() const;
|
||||
//// size --------------------------------------
|
||||
// size_type size() const;
|
||||
//// max_size ----------------------------------
|
||||
// size_type max_size() const;
|
||||
|
||||
|
||||
/******************
|
||||
* element access :
|
||||
******************/
|
||||
//// operator[] --------------------------------
|
||||
// mapped_type & operator[] (const key_type& k);
|
||||
|
||||
|
||||
/*************
|
||||
* modifiers :
|
||||
*************/
|
||||
//// insert ------------------------------------
|
||||
// pair<iterator,bool> insert (const value_type& val);
|
||||
// iterator insert (iterator position, const value_type& val);
|
||||
// template <class InputIterator>
|
||||
// void insert (InputIterator first, InputIterator last);
|
||||
//// erase -------------------------------------
|
||||
// void erase (iterator position);
|
||||
// size_type erase (const key_type& k);
|
||||
// void erase (iterator first, iterator last);
|
||||
//// swap --------------------------------------
|
||||
// void swap (map& x);
|
||||
//// clear -------------------------------------
|
||||
// void clear();
|
||||
|
||||
|
||||
/*************
|
||||
* observers :
|
||||
*************/
|
||||
//// key_comp ----------------------------------
|
||||
// key_compare key_comp() const;
|
||||
//// value_comp --------------------------------
|
||||
// value_compare value_comp() const;
|
||||
|
||||
|
||||
/**************
|
||||
* operations :
|
||||
**************/
|
||||
//// find --------------------------------------
|
||||
// iterator find (const key_type& k);
|
||||
// const_iterator find (const key_type& k) const;
|
||||
//// count -------------------------------------
|
||||
// size_type count (const key_type& k) const;
|
||||
//// lower_bound -------------------------------
|
||||
// iterator lower_bound (const key_type& k);
|
||||
// const_iterator lower_bound (const key_type& k) const;
|
||||
//// upper_bound -------------------------------
|
||||
// iterator upper_bound (const key_type& k);
|
||||
// const_iterator upper_bound (const key_type& k) const;
|
||||
//// equal_range -------------------------------
|
||||
// pair<const_iterator,const_iterator> equal_range (const key_type& k) const;
|
||||
// pair<iterator,iterator> equal_range (const key_type& k);
|
||||
|
||||
|
||||
/*************
|
||||
* allocator :
|
||||
*************/
|
||||
//// get_allocator -----------------------------
|
||||
// allocator_type get_allocator() const;
|
||||
|
||||
private:
|
||||
|
||||
// size_type _size;
|
||||
// size_type _capacity;
|
||||
// value_type * _mem_ptr;
|
||||
// allocator_type _allocator;
|
||||
//
|
||||
// void _destroy(iterator first, iterator last);
|
||||
// void _increment_capacity(size_type n);
|
||||
|
||||
};
|
||||
|
||||
} // namespace ft
|
||||
|
||||
# include "map.tpp"
|
||||
|
||||
#endif
|
||||
|
||||
132
headers/tests.hpp
Normal file
132
headers/tests.hpp
Normal file
@@ -0,0 +1,132 @@
|
||||
#ifndef TESTS_HPP
|
||||
# define TESTS_HPP
|
||||
|
||||
#include "colors.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iomanip> // std::setw()
|
||||
#include <iterator> // std::reverse_iterator
|
||||
#include <utility> // std::make_pair
|
||||
#include <sstream> // std::stringstream
|
||||
|
||||
|
||||
|
||||
// toogle between test ft and stl
|
||||
// *************************
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#ifdef STL
|
||||
namespace ft = std;
|
||||
#else
|
||||
#include "vector.hpp"
|
||||
#include "reverse_iterator.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
// global variables
|
||||
// ***************************************
|
||||
std::vector< std::vector<A_test*> > test_list;
|
||||
std::vector<mystruct*> mem_list;
|
||||
|
||||
|
||||
|
||||
// global functions
|
||||
// ***************************************
|
||||
void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4);
|
||||
|
||||
|
||||
// struct for tests
|
||||
// ***************************************
|
||||
struct mystruct {
|
||||
public:
|
||||
mystruct(int data = 0);
|
||||
~mystruct();
|
||||
int * get_data() const;
|
||||
private:
|
||||
int * _val;
|
||||
};
|
||||
std::ostream & operator<<(std::ostream & o, mystruct const * rhs);
|
||||
|
||||
|
||||
// adding each test to the list
|
||||
// ***************************
|
||||
#define TEST(f_name) \
|
||||
template <class T> struct s_ ## f_name : public A_test\
|
||||
{ void func(); };\
|
||||
void f_name ()\
|
||||
{ add_to_list(\
|
||||
#f_name,\
|
||||
new(s_ ## f_name <int>),\
|
||||
new(s_ ## f_name <char>),\
|
||||
new(s_ ## f_name <std::string>),\
|
||||
new(s_ ## f_name <mystruct*>)\
|
||||
);}\
|
||||
template <class T>\
|
||||
void s_ ## f_name <T>::func()
|
||||
|
||||
|
||||
// defines
|
||||
// ****************************************
|
||||
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
||||
# define VAL(n) val<T>(n)
|
||||
# define TOI(n) toi<T>(n)
|
||||
# define PRINT(n) print_vector<T>(n);
|
||||
# define DELETE delete_structs();
|
||||
|
||||
|
||||
// prototypes
|
||||
// *********************************************
|
||||
// vectors
|
||||
void tests_vector_constructor();
|
||||
void tests_vector_operator_assignation();
|
||||
void tests_vector_begin();
|
||||
void tests_vector_end();
|
||||
void tests_vector_rbegin();
|
||||
void tests_vector_rend();
|
||||
void tests_vector_size();
|
||||
void tests_vector_max_size();
|
||||
void tests_vector_resize();
|
||||
void tests_vector_capacity();
|
||||
void tests_vector_empty();
|
||||
void tests_vector_reserve();
|
||||
void tests_vector_operator_access();
|
||||
void tests_vector_at();
|
||||
void tests_vector_front();
|
||||
void tests_vector_back();
|
||||
void tests_vector_assign();
|
||||
void tests_vector_push_back();
|
||||
void tests_vector_pop_back();
|
||||
void tests_vector_insert();
|
||||
void tests_vector_erase();
|
||||
void tests_vector_swap();
|
||||
void tests_vector_clear();
|
||||
void tests_vector_get_allocator();
|
||||
void tests_vector_relational_operators();
|
||||
void tests_vector_swap_non_member();
|
||||
void tests_vector_reverse_iterators();
|
||||
// map
|
||||
void tests_map_simple();
|
||||
//void tests_map_constructor();
|
||||
//void tests_map_operator_assignation();
|
||||
//void tests_map_begin();
|
||||
//void tests_map_end();
|
||||
//void tests_map_rbegin();
|
||||
//void tests_map_rend();
|
||||
//void tests_map_empty();
|
||||
//void tests_map_size();
|
||||
//void tests_map_max_size();
|
||||
//void tests_map_operator_access();
|
||||
//void tests_map_insert();
|
||||
//void tests_map_erase();
|
||||
//void tests_map_swap();
|
||||
//void tests_map_clear();
|
||||
//void tests_map_key_comp();
|
||||
//void tests_map_value_comp();
|
||||
//void tests_map_find();
|
||||
//void tests_map_count();
|
||||
//void tests_map_lower_bound();
|
||||
//void tests_map_upper_bound();
|
||||
//void tests_map_equal_range();
|
||||
//void tests_map_get_allocator();
|
||||
#endif
|
||||
|
||||
@@ -27,8 +27,8 @@ void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4)
|
||||
}
|
||||
|
||||
|
||||
// *********************************************
|
||||
// prototypes
|
||||
// **************************************
|
||||
// prototypes vector
|
||||
void tests_vector_constructor();
|
||||
void tests_vector_operator_assignation();
|
||||
void tests_vector_begin();
|
||||
@@ -57,5 +57,33 @@ void tests_vector_relational_operators();
|
||||
void tests_vector_swap_non_member();
|
||||
void tests_vector_reverse_iterators();
|
||||
|
||||
|
||||
// *****************************************
|
||||
// prototypes map
|
||||
void tests_map_simple();
|
||||
//void tests_map_constructor();
|
||||
//void tests_map_operator_assignation();
|
||||
//void tests_map_begin();
|
||||
//void tests_map_end();
|
||||
//void tests_map_rbegin();
|
||||
//void tests_map_rend();
|
||||
//void tests_map_empty();
|
||||
//void tests_map_size();
|
||||
//void tests_map_max_size();
|
||||
//void tests_map_operator_access();
|
||||
//void tests_map_insert();
|
||||
//void tests_map_erase();
|
||||
//void tests_map_swap();
|
||||
//void tests_map_clear();
|
||||
//void tests_map_key_comp();
|
||||
//void tests_map_value_comp();
|
||||
//void tests_map_find();
|
||||
//void tests_map_count();
|
||||
//void tests_map_lower_bound();
|
||||
//void tests_map_upper_bound();
|
||||
//void tests_map_equal_range();
|
||||
//void tests_map_get_allocator();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
#include "A_test.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iomanip> // std::setw()
|
||||
#include <iterator> // std::reverse_iterator
|
||||
#include <utility> // std::make_pair
|
||||
#include <map> // std::map
|
||||
#include <sstream>
|
||||
#include <sstream> // std::stringstream
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
// toogle between test ft and stl
|
||||
|
||||
120
templates/map.tpp
Normal file
120
templates/map.tpp
Normal file
@@ -0,0 +1,120 @@
|
||||
|
||||
//#define VT_TPL template <class T, class Allocator>
|
||||
//#define VT vector<T, Allocator>
|
||||
|
||||
//#define MP_TPL template < typename Key, typename T, typename Compare, typename Allocator >
|
||||
//#define MP map<Key, T, Compare, Allocator>
|
||||
|
||||
|
||||
namespace ft {
|
||||
|
||||
|
||||
/************
|
||||
* copliens :
|
||||
************/
|
||||
//// constructors ------------------------------
|
||||
// explicit map (const key_compare& comp = key_compare(),
|
||||
// const allocator_type& alloc = allocator_type());
|
||||
// template <class InputIterator>
|
||||
// map (InputIterator first, InputIterator last,
|
||||
// const key_compare& comp = key_compare(),
|
||||
// const allocator_type& alloc = allocator_type());
|
||||
// map (const map& x);
|
||||
//// destructor --------------------------------
|
||||
// ~map();
|
||||
//// operator= ---------------------------------
|
||||
// map& operator= (const map& x);
|
||||
|
||||
|
||||
/*************
|
||||
* iterators :
|
||||
*************/
|
||||
//// begin -------------------------------------
|
||||
// iterator begin();
|
||||
// const_iterator begin() const;
|
||||
//// end ---------------------------------------
|
||||
// iterator end();
|
||||
// const_iterator end() const;
|
||||
//// rbegin ------------------------------------
|
||||
// reverse_iterator rbegin();
|
||||
// const_reverse_iterator rbegin() const;
|
||||
//// rend --------------------------------------
|
||||
// reverse_iterator rend();
|
||||
// const_reverse_iterator rend() const;
|
||||
|
||||
|
||||
/************
|
||||
* capacity :
|
||||
************/
|
||||
//// empty -------------------------------------
|
||||
// bool empty() const;
|
||||
//// size --------------------------------------
|
||||
// size_type size() const;
|
||||
//// max_size ----------------------------------
|
||||
// size_type max_size() const;
|
||||
|
||||
|
||||
/******************
|
||||
* element access :
|
||||
******************/
|
||||
//// operator[] --------------------------------
|
||||
// mapped_type & operator[] (const key_type& k);
|
||||
|
||||
|
||||
/*************
|
||||
* modifiers :
|
||||
*************/
|
||||
//// insert ------------------------------------
|
||||
// pair<iterator,bool> insert (const value_type& val);
|
||||
// iterator insert (iterator position, const value_type& val);
|
||||
// template <class InputIterator>
|
||||
// void insert (InputIterator first, InputIterator last);
|
||||
//// erase -------------------------------------
|
||||
// void erase (iterator position);
|
||||
// size_type erase (const key_type& k);
|
||||
// void erase (iterator first, iterator last);
|
||||
//// swap --------------------------------------
|
||||
// void swap (map& x);
|
||||
//// clear -------------------------------------
|
||||
// void clear();
|
||||
|
||||
|
||||
/*************
|
||||
* observers :
|
||||
*************/
|
||||
//// key_comp ----------------------------------
|
||||
// key_compare key_comp() const;
|
||||
//// value_comp --------------------------------
|
||||
// value_compare value_comp() const;
|
||||
|
||||
|
||||
/**************
|
||||
* operations :
|
||||
**************/
|
||||
//// find --------------------------------------
|
||||
// iterator find (const key_type& k);
|
||||
// const_iterator find (const key_type& k) const;
|
||||
//// count -------------------------------------
|
||||
// size_type count (const key_type& k) const;
|
||||
//// lower_bound -------------------------------
|
||||
// iterator lower_bound (const key_type& k);
|
||||
// const_iterator lower_bound (const key_type& k) const;
|
||||
//// upper_bound -------------------------------
|
||||
// iterator upper_bound (const key_type& k);
|
||||
// const_iterator upper_bound (const key_type& k) const;
|
||||
//// equal_range -------------------------------
|
||||
// pair<const_iterator,const_iterator> equal_range (const key_type& k) const;
|
||||
// pair<iterator,iterator> equal_range (const key_type& k);
|
||||
|
||||
|
||||
/*************
|
||||
* allocator :
|
||||
*************/
|
||||
//// get_allocator -----------------------------
|
||||
// allocator_type get_allocator() const;
|
||||
|
||||
} // namespace ft
|
||||
|
||||
//#undef VT
|
||||
//#undef VT_TPL
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
namespace ft {
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
* COPLIENS
|
||||
*********************************************/
|
||||
@@ -64,13 +63,11 @@ VT_TPL VT & VT::
|
||||
|
||||
vector new_vector;
|
||||
|
||||
//Base::operator=(rhs);
|
||||
if ( this != &rhs )
|
||||
{
|
||||
new_vector.reserve(_capacity);
|
||||
new_vector.assign(rhs.begin(), rhs.end());
|
||||
swap(new_vector);
|
||||
//_size = rhs.size();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -460,20 +457,6 @@ VT_TPL void VT::
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
* NESTED CLASS
|
||||
*********************************************/
|
||||
//void vector::Class::function() {}
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
* STATICS
|
||||
*********************************************/
|
||||
//std::string const vector::_bar = "bar";
|
||||
|
||||
|
||||
|
||||
/************************
|
||||
* non-member functions :
|
||||
************************/
|
||||
@@ -511,752 +494,3 @@ VT_TPL
|
||||
|
||||
#undef VT
|
||||
#undef VT_TPL
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////:
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
// #define VT_TPL template <class T, class Allocator>
|
||||
// #define VT vector<T, Allocator>
|
||||
//
|
||||
// namespace ft {
|
||||
//
|
||||
//
|
||||
//
|
||||
// /*********************************************
|
||||
// * COPLIENS
|
||||
// *********************************************/
|
||||
// // constructors ------------------------------
|
||||
// VT_TPL VT::
|
||||
// vector( const Allocator & alloc )
|
||||
// : _size(0)
|
||||
// , _capacity(0)
|
||||
// , _mem_ptr(NULL)
|
||||
// , _allocator(alloc) {
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
// VT_TPL VT::
|
||||
// vector( size_type n, const T & val, const Allocator & alloc )
|
||||
// : _size(0)
|
||||
// , _capacity(0)
|
||||
// , _mem_ptr(NULL)
|
||||
// , _allocator(alloc) {
|
||||
//
|
||||
// assign(n, val);
|
||||
// return;
|
||||
// }
|
||||
// VT_TPL template <class InputIterator> VT::
|
||||
// vector(InputIterator first, InputIterator last, const Allocator & alloc)
|
||||
// : _size(0)
|
||||
// , _capacity(0)
|
||||
// , _mem_ptr(NULL)
|
||||
// , _allocator(alloc) {
|
||||
//
|
||||
// assign(first, last);
|
||||
// return;
|
||||
// }
|
||||
// // copy constructor --------------------------
|
||||
// VT_TPL VT::
|
||||
// vector( vector const & src )
|
||||
// : _size(0)
|
||||
// , _capacity(0)
|
||||
// , _mem_ptr(NULL)
|
||||
// , _allocator(src._allocator) {
|
||||
//
|
||||
// *this = src;
|
||||
// return;
|
||||
// }
|
||||
// // destructors -------------------------------
|
||||
// VT_TPL VT::
|
||||
// ~vector() { return; }
|
||||
// // operator= ---------------------------------
|
||||
// VT_TPL VT & VT::
|
||||
// operator=( vector const & rhs ) {
|
||||
//
|
||||
// vector new_vector;
|
||||
//
|
||||
// //Base::operator=(rhs);
|
||||
// if ( this != &rhs )
|
||||
// {
|
||||
// new_vector.reserve(_capacity);
|
||||
// new_vector.assign(rhs.begin(), rhs.end());
|
||||
// swap(new_vector);
|
||||
// //_size = rhs.size();
|
||||
// }
|
||||
// return *this;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /*************
|
||||
// * iterators :
|
||||
// *************/
|
||||
// // begin -------------------------------------
|
||||
// VT_TPL typename VT::iterator VT::
|
||||
// begin() { return _mem_ptr; }
|
||||
// VT_TPL typename VT::const_iterator VT::
|
||||
// begin() const { return _mem_ptr; }
|
||||
// // end ---------------------------------------
|
||||
// VT_TPL typename VT::iterator VT::
|
||||
// end() { return &_mem_ptr[_size]; }
|
||||
// VT_TPL typename VT::const_iterator VT::
|
||||
// end() const { return &_mem_ptr[_size]; }
|
||||
// // rbegin ------------------------------------
|
||||
// VT_TPL typename VT::reverse_iterator VT::
|
||||
// rbegin() { return reverse_iterator(end()); }
|
||||
// VT_TPL typename VT::const_reverse_iterator VT::
|
||||
// rbegin() const { return const_reverse_iterator(end()); }
|
||||
// // rend --------------------------------------
|
||||
// VT_TPL typename VT::reverse_iterator VT::
|
||||
// rend() { return reverse_iterator(begin()); }
|
||||
// VT_TPL typename VT::const_reverse_iterator VT::
|
||||
// rend() const { return const_reverse_iterator(begin()); }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /************
|
||||
// * capacity :
|
||||
// ************/
|
||||
// // size --------------------------------------
|
||||
// VT_TPL typename VT::size_type VT::
|
||||
// size( ) const { return _size; }
|
||||
// // max_size ----------------------------------
|
||||
// VT_TPL typename VT::size_type VT::
|
||||
// max_size() const { return (_allocator.max_size()); }
|
||||
// // resize ------------------------------------
|
||||
// VT_TPL void VT::
|
||||
// resize(size_type n, value_type val) {
|
||||
//
|
||||
// if (n > _size)
|
||||
// {
|
||||
// if (n > _capacity)
|
||||
// _increment_capacity(n);
|
||||
// while (_size != n)
|
||||
// {
|
||||
// _allocator.construct(&_mem_ptr[_size], val);
|
||||
// ++_size;
|
||||
// }
|
||||
// }
|
||||
// else if (n < _size)
|
||||
// {
|
||||
// while (_size != n)
|
||||
// _allocator.destroy(&_mem_ptr[--_size]);
|
||||
// }
|
||||
// }
|
||||
// // capacity ----------------------------------
|
||||
// VT_TPL typename VT::size_type VT::
|
||||
// capacity() const { return _capacity; }
|
||||
// // empty -------------------------------------
|
||||
// VT_TPL bool VT::
|
||||
// empty() const { return (_size == 0); }
|
||||
// // reserve -----------------------------------
|
||||
// VT_TPL void VT::
|
||||
// reserve( size_type new_cap ) {
|
||||
//
|
||||
// T* new_arr;
|
||||
// T* old_arr = _mem_ptr;
|
||||
//
|
||||
// if (new_cap > max_size())
|
||||
// throw std::length_error("vector::reserve");
|
||||
//
|
||||
// if (_capacity >= new_cap)
|
||||
// return ;
|
||||
// new_arr = _allocator.allocate(new_cap);
|
||||
//
|
||||
// if (old_arr)
|
||||
// {
|
||||
// iterator first = begin();
|
||||
// iterator last = end();
|
||||
// _mem_ptr = new_arr;
|
||||
// _size = 0;
|
||||
// assign(first, last);
|
||||
// _destroy(first, last);
|
||||
// _allocator.deallocate(old_arr, _capacity);
|
||||
// }
|
||||
// else
|
||||
// _mem_ptr = new_arr;
|
||||
//
|
||||
// _capacity = new_cap;
|
||||
//
|
||||
//
|
||||
// // value_type * tmp_ptr;
|
||||
// // value_type * old_ptr = _mem_ptr;
|
||||
// // iterator first = begin();
|
||||
// // iterator last = end();
|
||||
// //
|
||||
// // if (new_cap > _allocator.max_size())
|
||||
// // throw std::length_error("reserve: new_cap > max_size");
|
||||
// // if (_capacity == _allocator.max_size())
|
||||
// // throw std::length_error("reserve: capacity == max_size");
|
||||
// // if (new_cap <= _capacity)
|
||||
// // return ;
|
||||
// //
|
||||
// // _capacity = new_cap;
|
||||
// // tmp_ptr = _allocator.allocate(new_cap);
|
||||
// //
|
||||
// // if (_mem_ptr)
|
||||
// // {
|
||||
// // _mem_ptr = tmp_ptr;
|
||||
// // _size = 0;
|
||||
// // assign(first, last);
|
||||
// // _destroy(begin(), end());
|
||||
// // _allocator.deallocate(old_ptr, _capacity);
|
||||
// // }
|
||||
// // _mem_ptr = tmp_ptr;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /******************
|
||||
// * element access :
|
||||
// ******************/
|
||||
// // operator[] --------------------------------
|
||||
// VT_TPL typename VT::reference VT::
|
||||
// operator[](size_type n) { return _mem_ptr[n]; }
|
||||
// VT_TPL typename VT::const_reference VT::
|
||||
// operator[](size_type n) const { return _mem_ptr[n]; }
|
||||
// // at ----------------------------------------
|
||||
// VT_TPL typename VT::reference VT::
|
||||
// at(size_type n) {
|
||||
//
|
||||
// if (n >= _size)
|
||||
// throw std::out_of_range("vector out of range");
|
||||
// return (_mem_ptr[n]);
|
||||
// }
|
||||
// VT_TPL typename VT::const_reference VT::
|
||||
// at(size_type n) const {
|
||||
//
|
||||
// if (n >= _size)
|
||||
// throw std::out_of_range("vector out of range");
|
||||
// return (_mem_ptr[n]);
|
||||
// }
|
||||
// // front -------------------------------------
|
||||
// VT_TPL typename VT::reference VT::
|
||||
// front() { return (*_mem_ptr); }
|
||||
// VT_TPL typename VT::const_reference VT::
|
||||
// front() const { return (*_mem_ptr); }
|
||||
// // back --------------------------------------
|
||||
// VT_TPL typename VT::reference VT::
|
||||
// back() { return (_mem_ptr[_size - 1]); }
|
||||
// VT_TPL typename VT::const_reference VT::
|
||||
// back() const { return (_mem_ptr[_size - 1]); }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /*************
|
||||
// * modifiers :
|
||||
// *************/
|
||||
// // assign ------------------------------------
|
||||
// VT_TPL template <class InputIterator>
|
||||
// typename enable_if< !is_integral<InputIterator>::value,void >::type VT::
|
||||
// assign( InputIterator first, InputIterator last) {
|
||||
//
|
||||
// _assign(first, last, typename iterator_traits<InputIterator>::iterator_category());
|
||||
//
|
||||
// // InputIterator tmp = first;
|
||||
// // unsigned int range = 0;
|
||||
// //
|
||||
// // clear();
|
||||
// //
|
||||
// // while (tmp++ != last)
|
||||
// // range++;
|
||||
// // if (range >= _capacity)
|
||||
// // _increment_capacity(range);
|
||||
// // while (first != last)
|
||||
// // {
|
||||
// // _allocator.construct(&_mem_ptr[_size], *first);
|
||||
// // first++;
|
||||
// // _size++;
|
||||
// // }
|
||||
// }
|
||||
// VT_TPL
|
||||
// template < typename InputIt >
|
||||
// void VT::
|
||||
// _assign(InputIt first, InputIt last, std::input_iterator_tag)
|
||||
// {
|
||||
// clear();
|
||||
//
|
||||
// while (first != last)
|
||||
// {
|
||||
// if (_size + 1 > _capacity)
|
||||
// _increment_capacity(_size + 1);
|
||||
// _allocator.construct(&_mem_ptr[_size], *first);
|
||||
// ++first;
|
||||
// ++_size;
|
||||
// }
|
||||
// }
|
||||
// VT_TPL
|
||||
// template < typename ForwardIt >
|
||||
// void VT::
|
||||
// _assign(ForwardIt first, ForwardIt last, std::forward_iterator_tag)
|
||||
// {
|
||||
// clear();
|
||||
//
|
||||
// difference_type diff = std::distance(first, last);
|
||||
// if (diff < 0)
|
||||
// throw std::logic_error("Wrong iterator order");
|
||||
//
|
||||
// if (static_cast<size_type>(diff) > _capacity)
|
||||
// _increment_capacity(diff);
|
||||
//
|
||||
// while (first != last)
|
||||
// {
|
||||
// _allocator.construct(&_mem_ptr[_size], *first);
|
||||
// ++first;
|
||||
// ++_size;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// VT_TPL void VT::
|
||||
// assign( size_type n, const T & val ) {
|
||||
//
|
||||
// if (n > _allocator.max_size())
|
||||
// throw std::length_error("assign: n > max_size");
|
||||
//
|
||||
// value_type * tmp_ptr;
|
||||
//
|
||||
// _destroy(begin(), end());
|
||||
// if (n > _capacity)
|
||||
// {
|
||||
// _capacity = n;
|
||||
// tmp_ptr = _allocator.allocate(n);
|
||||
// if (_mem_ptr)
|
||||
// _allocator.deallocate(_mem_ptr, _capacity);
|
||||
// _mem_ptr = tmp_ptr;
|
||||
// }
|
||||
// _size = n;
|
||||
// while (n)
|
||||
// _allocator.construct(&_mem_ptr[--n], val);
|
||||
// }
|
||||
// // push_back ---------------------------------
|
||||
// VT_TPL void VT::
|
||||
// push_back( const value_type & element ) {
|
||||
//
|
||||
// if (_size >= _capacity)
|
||||
// _increment_capacity(1);
|
||||
// _allocator.construct(&_mem_ptr[_size], element);
|
||||
// _size++;
|
||||
// }
|
||||
// // pop_back ----------------------------------
|
||||
// VT_TPL void VT::
|
||||
// pop_back() { _allocator.destroy(end() - 1); _size--; }
|
||||
// // insert ------------------------------------
|
||||
// VT_TPL typename VT::iterator VT::
|
||||
// insert(iterator pos, const value_type& value) {
|
||||
// // insert(iterator position, const value_type& val) {
|
||||
//
|
||||
// if (_size + 1 > _capacity)
|
||||
// {
|
||||
// difference_type offset = pos - begin();
|
||||
// _increment_capacity(_size + 1);
|
||||
// pos = begin() + offset;
|
||||
// }
|
||||
//
|
||||
// iterator it_end = end();
|
||||
// if (pos != it_end)
|
||||
// {
|
||||
// iterator i = it_end;
|
||||
// --i;
|
||||
// _allocator.construct(i + 1, *i);
|
||||
// while (i != pos)
|
||||
// {
|
||||
// --i;
|
||||
// *(i + 1) = *i;
|
||||
// }
|
||||
// _allocator.destroy(pos);
|
||||
// }
|
||||
// _allocator.construct(pos, value);
|
||||
// _size += 1;
|
||||
// return (pos);
|
||||
//
|
||||
//
|
||||
//
|
||||
// // difference_type distance;
|
||||
// // iterator it;
|
||||
// //
|
||||
// // if (_size + 1 > _capacity)
|
||||
// // {
|
||||
// // distance = position - begin();
|
||||
// // _increment_capacity(1);
|
||||
// // position = begin() + distance;
|
||||
// // }
|
||||
// // it = end();
|
||||
// // if (position != it)
|
||||
// // {
|
||||
// // _allocator.construct(it, *(it - 1));
|
||||
// // while (it-- != position)
|
||||
// // *(it + 1) = *it;
|
||||
// // }
|
||||
// // _allocator.destroy(position);
|
||||
// // _allocator.construct(position, val);
|
||||
// // _size++;
|
||||
// // return (position);
|
||||
// }
|
||||
// VT_TPL void VT::
|
||||
// insert(iterator pos, size_type count, const value_type& value) {
|
||||
// // insert(iterator position, size_type n, const value_type& val) {
|
||||
//
|
||||
// if (_size + count > _capacity)
|
||||
// {
|
||||
// difference_type offset = pos - begin();
|
||||
// // _auto_realloc(_size + count);
|
||||
// _increment_capacity(count);
|
||||
// pos = begin() + offset;
|
||||
// }
|
||||
//
|
||||
// iterator it_end = end();
|
||||
// if (pos != it_end)
|
||||
// {
|
||||
// iterator i = it_end;
|
||||
// while (i + count != it_end && i != pos)
|
||||
// {
|
||||
// --i;
|
||||
// _allocator.construct(i + count, *i);
|
||||
// }
|
||||
// while (i != pos)
|
||||
// {
|
||||
// --i;
|
||||
// *(i + count) = *i;
|
||||
// }
|
||||
// // _destroy_objects(pos, std::min(pos + count, it_end));
|
||||
// _destroy(pos, std::min(pos + count, it_end));
|
||||
// }
|
||||
//
|
||||
// iterator last = pos + count;
|
||||
// while (pos != last)
|
||||
// {
|
||||
// _allocator.construct(pos, value);
|
||||
// ++pos;
|
||||
// }
|
||||
// _size += count;
|
||||
//
|
||||
// // difference_type distance;
|
||||
// // iterator it_end;
|
||||
// // iterator it;
|
||||
// //
|
||||
// // if (_size + n > _capacity)
|
||||
// // {
|
||||
// // distance = position - begin();
|
||||
// // _increment_capacity(n);
|
||||
// // position = begin() + distance;
|
||||
// // }
|
||||
// //
|
||||
// // it_end = end();
|
||||
// // if (position != it_end)
|
||||
// // {
|
||||
// // it = it_end;
|
||||
// // while (it + n != it_end && it != position)
|
||||
// // {
|
||||
// // it--;
|
||||
// // _allocator.construct(it + n, *it);
|
||||
// // }
|
||||
// // while (it != position)
|
||||
// // {
|
||||
// // it--;
|
||||
// // *(it + n) = *it;
|
||||
// // }
|
||||
// // _destroy(position, std::min(position + n, it_end));
|
||||
// // }
|
||||
// //
|
||||
// // for (size_type i = 0; i < n; i++, position++)
|
||||
// // _allocator.construct(position, val);
|
||||
// // _size += n;
|
||||
// }
|
||||
// VT_TPL template <class InputIterator>
|
||||
// typename enable_if< !is_integral<InputIterator>::value,void >::type VT::
|
||||
// insert(iterator position, InputIterator first, InputIterator last) {
|
||||
//
|
||||
// difference_type dist;
|
||||
// difference_type n;
|
||||
// iterator it_end;
|
||||
// iterator it;
|
||||
//
|
||||
// n = std::distance(first, last);
|
||||
// if (_size + n > _capacity)
|
||||
// {
|
||||
// dist = position - begin();
|
||||
// _increment_capacity(n);
|
||||
// position = begin() + dist;
|
||||
// }
|
||||
//
|
||||
// it_end = end();
|
||||
// if (position != it_end)
|
||||
// {
|
||||
// it = it_end;
|
||||
// while (it + n != it_end && it != position)
|
||||
// {
|
||||
// it--;
|
||||
// _allocator.construct(it + n, *it);
|
||||
// }
|
||||
// while (it != position)
|
||||
// {
|
||||
// it--;
|
||||
// *(it + n) = *it;
|
||||
// }
|
||||
// _destroy(position, std::min(position + n, it_end));
|
||||
// }
|
||||
//
|
||||
// while (first != last)
|
||||
// {
|
||||
// _allocator.construct(position, *first);
|
||||
// ++position;
|
||||
// ++first;
|
||||
// }
|
||||
//
|
||||
// _size += n;
|
||||
// }
|
||||
// // erase -------------------------------------
|
||||
// VT_TPL typename VT::iterator VT::
|
||||
// erase(iterator position) {
|
||||
//
|
||||
// iterator i = position;
|
||||
// iterator it_end = end() - 1;
|
||||
//
|
||||
// while (i != it_end)
|
||||
// {
|
||||
// *i = *(i + 1);
|
||||
// ++i;
|
||||
// }
|
||||
// _allocator.destroy(it_end);
|
||||
// _size -= 1;
|
||||
// return (position);
|
||||
// }
|
||||
// VT_TPL typename VT::iterator VT::
|
||||
// erase(iterator first, iterator last) {
|
||||
//
|
||||
// iterator it_end = end();
|
||||
// difference_type diff = std::distance(first, last);
|
||||
//
|
||||
// if (diff <= 0)
|
||||
// return (first);
|
||||
//
|
||||
// it_end = end();
|
||||
// while (last != it_end)
|
||||
// {
|
||||
// *first = *last;
|
||||
// first++;
|
||||
// last++;
|
||||
// }
|
||||
// _destroy(it_end - diff, it_end);
|
||||
// _size -= diff;
|
||||
//
|
||||
// return (first);
|
||||
// }
|
||||
// // swap --------------------------------------
|
||||
// VT_TPL void VT::
|
||||
// swap(vector& x) {
|
||||
//
|
||||
// T* tmp_mem_ptr;
|
||||
// size_type tmp_size;
|
||||
// size_type tmp_capacity;
|
||||
//
|
||||
// tmp_mem_ptr = x._mem_ptr;
|
||||
// tmp_size = x._size;
|
||||
// tmp_capacity = x._capacity;
|
||||
//
|
||||
// x._mem_ptr = _mem_ptr;
|
||||
// x._size = _size;
|
||||
// x._capacity = _capacity;
|
||||
//
|
||||
// _mem_ptr = tmp_mem_ptr;
|
||||
// _size = tmp_size;
|
||||
// _capacity = tmp_capacity;
|
||||
// }
|
||||
// // clear -------------------------------------
|
||||
// VT_TPL void VT::
|
||||
// clear() { _destroy(begin(), end()); _size = 0; }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /*************
|
||||
// * allocator :
|
||||
// *************/
|
||||
// // get_allocator -----------------------------
|
||||
// VT_TPL typename VT::allocator_type VT::
|
||||
// get_allocator() const { return (_allocator); }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /*********************************************
|
||||
// * PRIVATE MEMBER FUNCTIONS
|
||||
// *********************************************/
|
||||
// VT_TPL void VT::
|
||||
// _destroy(iterator first, iterator last) {
|
||||
//
|
||||
// while (first != last)
|
||||
// {
|
||||
// _allocator.destroy(first);
|
||||
// first++;
|
||||
// }
|
||||
// }
|
||||
// VT_TPL void VT::
|
||||
// _increment_capacity(size_type min_new_cap) {
|
||||
// // _increment_capacity(size_type n) {
|
||||
//
|
||||
// size_type new_cap;
|
||||
//
|
||||
// if (_capacity == max_size())
|
||||
// throw std::length_error("vector::reserve");
|
||||
// new_cap = std::min(max_size() / 2, _size) * 2;
|
||||
// new_cap = std::max(new_cap, min_new_cap);
|
||||
// reserve(new_cap);
|
||||
//
|
||||
//
|
||||
// // size_type res;
|
||||
// //
|
||||
// // res = std::max(_size * 2, n);
|
||||
// // reserve(std::min(res, _allocator.max_size()));
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /*********************************************
|
||||
// * NESTED CLASS
|
||||
// *********************************************/
|
||||
// //void vector::Class::function() {}
|
||||
//
|
||||
//
|
||||
//
|
||||
// /*********************************************
|
||||
// * STATICS
|
||||
// *********************************************/
|
||||
// //std::string const vector::_bar = "bar";
|
||||
//
|
||||
//
|
||||
//
|
||||
// /************************
|
||||
// * non-member functions :
|
||||
// ************************/
|
||||
// // operator == -------------------------------
|
||||
// VT_TPL
|
||||
// bool operator== (const VT & lhs, const VT & rhs) {
|
||||
//
|
||||
// if (lhs.size() != rhs.size())
|
||||
// return false;
|
||||
// return ft::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||
// }
|
||||
// // operator < --------------------------------
|
||||
// VT_TPL
|
||||
// bool operator< (const VT & lhs, const VT & rhs) {
|
||||
//
|
||||
// return ft::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
||||
// }
|
||||
// // operator != -------------------------------
|
||||
// VT_TPL
|
||||
// bool operator!= (const VT & lhs, const VT & rhs) { return !(lhs == rhs); }
|
||||
// // operator <= -------------------------------
|
||||
// VT_TPL
|
||||
// bool operator<= (const VT & lhs, const VT & rhs) { return !(lhs > rhs); }
|
||||
// // operator > --------------------------------
|
||||
// VT_TPL
|
||||
// bool operator> (const VT & lhs, const VT & rhs) { return (rhs < lhs); }
|
||||
// // operator >= -------------------------------
|
||||
// VT_TPL
|
||||
// bool operator>= (const VT & lhs, const VT & rhs) { return !(lhs < rhs); }
|
||||
// // swap (vector) -------------------------------
|
||||
// VT_TPL
|
||||
// void swap (VT & lhs, VT & rhs) { lhs.swap(rhs); }
|
||||
//
|
||||
// } // namespace ft
|
||||
//
|
||||
// #undef VT
|
||||
// #undef VT_TPL
|
||||
//
|
||||
|
||||
@@ -1,67 +1,68 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "colors.h"
|
||||
#include <iomanip> // std::setw()
|
||||
#include "tests_proto.hpp"
|
||||
#include "colors.h"
|
||||
#include "A_test.hpp"
|
||||
//#include "tests_proto.hpp"
|
||||
|
||||
|
||||
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_relational_operators();
|
||||
// tests_vector_swap_non_member();
|
||||
// tests_vector_reverse_iterators();
|
||||
|
||||
// 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_resize();
|
||||
// tests_map_capacity();
|
||||
// tests_map_empty();
|
||||
// tests_map_reserve();
|
||||
// tests_map_operator_access();
|
||||
// tests_map_at();
|
||||
// tests_map_front();
|
||||
// tests_map_back();
|
||||
// tests_map_assign();
|
||||
// tests_map_push_back();
|
||||
// tests_map_pop_back();
|
||||
// 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();
|
||||
|
||||
|
||||
// STACK
|
||||
// tests_stack_constructor();
|
||||
// tests_stack_operator_assignation();
|
||||
|
||||
551
tests/tests_map.cpp
Normal file
551
tests/tests_map.cpp
Normal file
@@ -0,0 +1,551 @@
|
||||
|
||||
#ifndef TESTS_MAP_CPP
|
||||
#define TESTS_MAP_CPP
|
||||
|
||||
#include "tests_utils.hpp"
|
||||
|
||||
TEST(tests_map_simple)
|
||||
{
|
||||
// title
|
||||
TITLE(simple test)
|
||||
|
||||
std::map<char,int> first;
|
||||
std::map<char, int>::iterator it;
|
||||
|
||||
first['a']=10;
|
||||
first['b']=30;
|
||||
first['c']=50;
|
||||
first['d']=70;
|
||||
|
||||
for(it=first.begin(); it!=first.end(); ++it){
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
}
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
/*
|
||||
TEST(tests_map_constructor)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
// bool fncomp (char lhs, char rhs) {return lhs<rhs;}
|
||||
//
|
||||
// struct classcomp {
|
||||
// bool operator() (const char& lhs, const char& rhs) const
|
||||
// {return lhs<rhs;}
|
||||
// };
|
||||
|
||||
std::map<char,int> first;
|
||||
|
||||
first['a']=10;
|
||||
first['b']=30;
|
||||
first['c']=50;
|
||||
first['d']=70;
|
||||
|
||||
std::map<char,int> second (first.begin(),first.end());
|
||||
|
||||
std::map<char,int> third (second);
|
||||
|
||||
std::map<char,int,classcomp> fourth; // class as Compare
|
||||
|
||||
bool(*fn_pt)(char,char) = fncomp;
|
||||
std::map<char,int,bool(*)(char,char)> fifth (fn_pt); // function pointer as Compare
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_operator_assignation)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> first;
|
||||
std::map<char,int> second;
|
||||
|
||||
first['x']=8;
|
||||
first['y']=16;
|
||||
first['z']=32;
|
||||
|
||||
second=first; // second now contains 3 ints
|
||||
first=std::map<char,int>(); // and first is now empty
|
||||
|
||||
std::cout << "Size of first: " << first.size() << '\n';
|
||||
std::cout << "Size of second: " << second.size() << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_begin)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
mymap['b'] = 100;
|
||||
mymap['a'] = 200;
|
||||
mymap['c'] = 300;
|
||||
|
||||
// show content:
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_end)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
mymap['b'] = 100;
|
||||
mymap['a'] = 200;
|
||||
mymap['c'] = 300;
|
||||
|
||||
// show content:
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_rbegin)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
mymap['x'] = 100;
|
||||
mymap['y'] = 200;
|
||||
mymap['z'] = 300;
|
||||
|
||||
// show content:
|
||||
std::map<char,int>::reverse_iterator rit;
|
||||
for (rit=mymap.rbegin(); rit!=mymap.rend(); ++rit)
|
||||
std::cout << rit->first << " => " << rit->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_rend)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
mymap['x'] = 100;
|
||||
mymap['y'] = 200;
|
||||
mymap['z'] = 300;
|
||||
|
||||
// show content:
|
||||
std::map<char,int>::reverse_iterator rit;
|
||||
for (rit=mymap.rbegin(); rit!=mymap.rend(); ++rit)
|
||||
std::cout << rit->first << " => " << rit->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_empty)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
mymap['a']=10;
|
||||
mymap['b']=20;
|
||||
mymap['c']=30;
|
||||
|
||||
while (!mymap.empty())
|
||||
{
|
||||
std::cout << mymap.begin()->first << " => " << mymap.begin()->second << '\n';
|
||||
mymap.erase(mymap.begin());
|
||||
}
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_size)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
mymap['a']=101;
|
||||
mymap['b']=202;
|
||||
mymap['c']=302;
|
||||
|
||||
std::cout << "mymap.size() is " << mymap.size() << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_max_size)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
int i;
|
||||
std::map<int,int> mymap;
|
||||
|
||||
if (mymap.max_size()>1000)
|
||||
{
|
||||
for (i=0; i<1000; i++) mymap[i]=0;
|
||||
std::cout << "The map contains 1000 elements.\n";
|
||||
}
|
||||
else std::cout << "The map could not hold 1000 elements.\n";
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_operator_access)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,std::string> mymap;
|
||||
|
||||
mymap['a']="an element";
|
||||
mymap['b']="another element";
|
||||
mymap['c']=mymap['b'];
|
||||
|
||||
std::cout << "mymap['a'] is " << mymap['a'] << '\n';
|
||||
std::cout << "mymap['b'] is " << mymap['b'] << '\n';
|
||||
std::cout << "mymap['c'] is " << mymap['c'] << '\n';
|
||||
std::cout << "mymap['d'] is " << mymap['d'] << '\n';
|
||||
|
||||
std::cout << "mymap now contains " << mymap.size() << " elements.\n";
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_insert)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
// first insert function version (single parameter):
|
||||
mymap.insert ( std::pair<char,int>('a',100) );
|
||||
mymap.insert ( std::pair<char,int>('z',200) );
|
||||
|
||||
std::pair<std::map<char,int>::iterator,bool> ret;
|
||||
ret = mymap.insert ( std::pair<char,int>('z',500) );
|
||||
if (ret.second==false) {
|
||||
std::cout << "element 'z' already existed";
|
||||
std::cout << " with a value of " << ret.first->second << '\n';
|
||||
}
|
||||
|
||||
// second insert function version (with hint position):
|
||||
std::map<char,int>::iterator it = mymap.begin();
|
||||
mymap.insert (it, std::pair<char,int>('b',300)); // max efficiency inserting
|
||||
mymap.insert (it, std::pair<char,int>('c',400)); // no max efficiency inserting
|
||||
|
||||
// third insert function version (range insertion):
|
||||
std::map<char,int> anothermap;
|
||||
anothermap.insert(mymap.begin(),mymap.find('c'));
|
||||
|
||||
// showing contents:
|
||||
std::cout << "mymap contains:\n";
|
||||
for (it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
std::cout << "anothermap contains:\n";
|
||||
for (it=anothermap.begin(); it!=anothermap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_erase)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
std::map<char,int>::iterator it;
|
||||
|
||||
// insert some values:
|
||||
mymap['a']=10;
|
||||
mymap['b']=20;
|
||||
mymap['c']=30;
|
||||
mymap['d']=40;
|
||||
mymap['e']=50;
|
||||
mymap['f']=60;
|
||||
|
||||
it=mymap.find('b');
|
||||
mymap.erase (it); // erasing by iterator
|
||||
|
||||
mymap.erase ('c'); // erasing by key
|
||||
|
||||
it=mymap.find ('e');
|
||||
mymap.erase ( it, mymap.end() ); // erasing by range
|
||||
|
||||
// show content:
|
||||
for (it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_swap)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> foo,bar;
|
||||
|
||||
foo['x']=100;
|
||||
foo['y']=200;
|
||||
|
||||
bar['a']=11;
|
||||
bar['b']=22;
|
||||
bar['c']=33;
|
||||
|
||||
foo.swap(bar);
|
||||
|
||||
std::cout << "foo contains:\n";
|
||||
for (std::map<char,int>::iterator it=foo.begin(); it!=foo.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
std::cout << "bar contains:\n";
|
||||
for (std::map<char,int>::iterator it=bar.begin(); it!=bar.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_clear)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
mymap['x']=100;
|
||||
mymap['y']=200;
|
||||
mymap['z']=300;
|
||||
|
||||
std::cout << "mymap contains:\n";
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
mymap.clear();
|
||||
mymap['a']=1101;
|
||||
mymap['b']=2202;
|
||||
|
||||
std::cout << "mymap contains:\n";
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_key_comp)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
std::map<char,int>::key_compare mycomp = mymap.key_comp();
|
||||
|
||||
mymap['a']=100;
|
||||
mymap['b']=200;
|
||||
mymap['c']=300;
|
||||
|
||||
std::cout << "mymap contains:\n";
|
||||
|
||||
char highest = mymap.rbegin()->first; // key value of last element
|
||||
|
||||
std::map<char,int>::iterator it = mymap.begin();
|
||||
do {
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
} while ( mycomp((*it++).first, highest) );
|
||||
|
||||
std::cout << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_value_comp)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
mymap['x']=1001;
|
||||
mymap['y']=2002;
|
||||
mymap['z']=3003;
|
||||
|
||||
std::cout << "mymap contains:\n";
|
||||
|
||||
std::pair<char,int> highest = *mymap.rbegin(); // last element
|
||||
|
||||
std::map<char,int>::iterator it = mymap.begin();
|
||||
do {
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
} while ( mymap.value_comp()(*it++, highest) );
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_find)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
std::map<char,int>::iterator it;
|
||||
|
||||
mymap['a']=50;
|
||||
mymap['b']=100;
|
||||
mymap['c']=150;
|
||||
mymap['d']=200;
|
||||
|
||||
it = mymap.find('b');
|
||||
if (it != mymap.end())
|
||||
mymap.erase (it);
|
||||
|
||||
// print content:
|
||||
std::cout << "elements in mymap:" << '\n';
|
||||
std::cout << "a => " << mymap.find('a')->second << '\n';
|
||||
std::cout << "c => " << mymap.find('c')->second << '\n';
|
||||
std::cout << "d => " << mymap.find('d')->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_count)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
char c;
|
||||
|
||||
mymap ['a']=101;
|
||||
mymap ['c']=202;
|
||||
mymap ['f']=303;
|
||||
|
||||
for (c='a'; c<'h'; c++)
|
||||
{
|
||||
std::cout << c;
|
||||
if (mymap.count(c)>0)
|
||||
std::cout << " is an element of mymap.\n";
|
||||
else
|
||||
std::cout << " is not an element of mymap.\n";
|
||||
}
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_lower_bound)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
std::map<char,int>::iterator itlow,itup;
|
||||
|
||||
mymap['a']=20;
|
||||
mymap['b']=40;
|
||||
mymap['c']=60;
|
||||
mymap['d']=80;
|
||||
mymap['e']=100;
|
||||
|
||||
itlow=mymap.lower_bound ('b'); // itlow points to b
|
||||
itup=mymap.upper_bound ('d'); // itup points to e (not d!)
|
||||
|
||||
mymap.erase(itlow,itup); // erases [itlow,itup)
|
||||
|
||||
// print content:
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_upper_bound)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
std::map<char,int>::iterator itlow,itup;
|
||||
|
||||
mymap['a']=20;
|
||||
mymap['b']=40;
|
||||
mymap['c']=60;
|
||||
mymap['d']=80;
|
||||
mymap['e']=100;
|
||||
|
||||
itlow=mymap.lower_bound ('b'); // itlow points to b
|
||||
itup=mymap.upper_bound ('d'); // itup points to e (not d!)
|
||||
|
||||
mymap.erase(itlow,itup); // erases [itlow,itup)
|
||||
|
||||
// print content:
|
||||
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_equal_range)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
std::map<char,int> mymap;
|
||||
|
||||
mymap['a']=10;
|
||||
mymap['b']=20;
|
||||
mymap['c']=30;
|
||||
|
||||
std::pair<std::map<char,int>::iterator,std::map<char,int>::iterator> ret;
|
||||
ret = mymap.equal_range('b');
|
||||
|
||||
std::cout << "lower bound points to: ";
|
||||
std::cout << ret.first->first << " => " << ret.first->second << '\n';
|
||||
|
||||
std::cout << "upper bound points to: ";
|
||||
std::cout << ret.second->first << " => " << ret.second->second << '\n';
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
TEST(tests_map_get_allocator)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
int psize;
|
||||
std::map<char,int> mymap;
|
||||
std::pair<const char,int>* p;
|
||||
|
||||
// allocate an array of 5 elements using mymap's allocator:
|
||||
p=mymap.get_allocator().allocate(5);
|
||||
|
||||
// assign some values to array
|
||||
psize = sizeof(std::map<char,int>::value_type)*5;
|
||||
|
||||
std::cout << "The allocated array has a size of " << psize << " bytes.\n";
|
||||
|
||||
mymap.get_allocator().deallocate(p,5);
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
117
tests/tests_utils.cpp
Normal file
117
tests/tests_utils.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
|
||||
#include "tests.hpp"
|
||||
|
||||
void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4) {
|
||||
|
||||
std::vector<A_test*> test_sub_list;
|
||||
|
||||
s1->title = s;
|
||||
s2->title = s;
|
||||
s3->title = s;
|
||||
s4->title = s;
|
||||
s1->type = "int";
|
||||
s2->type = "char";
|
||||
s3->type = "std::string";
|
||||
s4->type = "mystruct";
|
||||
test_sub_list.push_back(s1);
|
||||
test_sub_list.push_back(s2);
|
||||
test_sub_list.push_back(s3);
|
||||
test_sub_list.push_back(s4);
|
||||
test_list.push_back(test_sub_list);
|
||||
}
|
||||
|
||||
void delete_structs() {
|
||||
|
||||
std::vector<mystruct*>::iterator it;
|
||||
std::vector<mystruct*>::iterator it_end = mem_list.end();
|
||||
|
||||
for (it = mem_list.begin(); it != it_end; ++it)
|
||||
delete *it;
|
||||
mem_list.clear();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void print_vector(ft::vector<T> vec) {
|
||||
|
||||
int i = 0;
|
||||
typename ft::vector<T>::iterator it;
|
||||
typename ft::vector<T>::iterator it_end = vec.end();
|
||||
|
||||
for (it = vec.begin(); it != it_end; ++it, i++)
|
||||
std::cout << "[" << i << "]" << *it << " ";
|
||||
std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\n";
|
||||
}
|
||||
|
||||
// mystruct
|
||||
// *********************************************
|
||||
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];
|
||||
else
|
||||
o << "NULL";
|
||||
return (o);
|
||||
}
|
||||
|
||||
|
||||
// get a value
|
||||
// *********************************************
|
||||
template <class T>
|
||||
T val(int n) {(void)n; return (T());
|
||||
}
|
||||
template <>
|
||||
int val(int n) {return (n);
|
||||
}
|
||||
template <>
|
||||
char val(int n) {return (n % 94 + 33);
|
||||
}
|
||||
template <>
|
||||
std::string val(int n) {
|
||||
|
||||
std::string str;
|
||||
std::stringstream stream;
|
||||
|
||||
stream << n;
|
||||
stream >> str;
|
||||
stream.clear();
|
||||
return (str);
|
||||
}
|
||||
template <>
|
||||
mystruct* val(int n) {
|
||||
|
||||
mystruct *s = new mystruct(n);
|
||||
mem_list.push_back(s);
|
||||
return ( s );
|
||||
}
|
||||
|
||||
|
||||
// convert a value
|
||||
// *****************************************
|
||||
template <class T>
|
||||
int toi(T t) {(void)t; return (0);
|
||||
}
|
||||
template <>
|
||||
int toi(int i) {return (i);
|
||||
}
|
||||
template <>
|
||||
int toi(char c) {return (c);
|
||||
}
|
||||
template <>
|
||||
int toi(std::string str) {
|
||||
|
||||
int i;
|
||||
std::stringstream stream;
|
||||
|
||||
stream << str;
|
||||
stream >> i;
|
||||
stream.clear();
|
||||
return (i);
|
||||
}
|
||||
template <>
|
||||
int toi(mystruct* s) {
|
||||
|
||||
return ( s->get_data()[0] );
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
#ifndef TESTS_VECTORS_CPP
|
||||
#define TESTS_VECTORS_CPP
|
||||
#ifndef TESTS_VECTOR_CPP
|
||||
#define TESTS_VECTOR_CPP
|
||||
|
||||
#include "tests_utils.hpp"
|
||||
|
||||
Reference in New Issue
Block a user