all vector tests pass
This commit is contained in:
@@ -28,13 +28,13 @@ int main() {
|
|||||||
tests_vector_push_back();
|
tests_vector_push_back();
|
||||||
tests_vector_pop_back();
|
tests_vector_pop_back();
|
||||||
tests_vector_insert();
|
tests_vector_insert();
|
||||||
// tests_vector_erase();
|
tests_vector_erase();
|
||||||
// tests_vector_swap();
|
tests_vector_swap();
|
||||||
// tests_vector_clear();
|
tests_vector_clear();
|
||||||
// tests_vector_get_allocator();
|
tests_vector_get_allocator();
|
||||||
// tests_vector_relational_operators();
|
tests_vector_relational_operators();
|
||||||
// tests_vector_swap_non_member();
|
tests_vector_swap_non_member();
|
||||||
// tests_vector_reverse_iterators();
|
tests_vector_reverse_iterators();
|
||||||
|
|
||||||
// MAP
|
// MAP
|
||||||
// tests_map_constructor();
|
// tests_map_constructor();
|
||||||
|
|||||||
@@ -488,7 +488,6 @@ TEST(tests_vector_push_back)
|
|||||||
TITLE(big push back :)
|
TITLE(big push back :)
|
||||||
|
|
||||||
for (int i = 0; i < 72363; i++)
|
for (int i = 0; i < 72363; i++)
|
||||||
// for (int i = 0; i < 363; i++)
|
|
||||||
{
|
{
|
||||||
myvector.push_back(VAL(9));
|
myvector.push_back(VAL(9));
|
||||||
std::cout << "[" << i
|
std::cout << "[" << i
|
||||||
@@ -616,18 +615,15 @@ TEST(tests_vector_insert)
|
|||||||
DELETE
|
DELETE
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
TEST(tests_vector_erase)
|
||||||
void tests_vector_erase()
|
|
||||||
{
|
{
|
||||||
TEST(vector::erase)
|
|
||||||
{
|
|
||||||
// title
|
// title
|
||||||
TITLE(cplusplus.com reference :)
|
TITLE(cplusplus.com reference :)
|
||||||
|
|
||||||
ft::vector<int> myvector;
|
ft::vector<T> myvector;
|
||||||
|
|
||||||
// set some values (from 1 to 10)
|
// set some values (from 1 to 10)
|
||||||
for (int i=1; i<=10; i++) myvector.push_back(i);
|
for (int i=1; i<=10; i++) myvector.push_back(VAL(i));
|
||||||
|
|
||||||
// erase the 6th element
|
// erase the 6th element
|
||||||
myvector.erase (myvector.begin()+5);
|
myvector.erase (myvector.begin()+5);
|
||||||
@@ -636,116 +632,86 @@ void tests_vector_erase()
|
|||||||
myvector.erase (myvector.begin(),myvector.begin()+3);
|
myvector.erase (myvector.begin(),myvector.begin()+3);
|
||||||
|
|
||||||
std::cout << "myvector contains:";
|
std::cout << "myvector contains:";
|
||||||
for (unsigned i=0; i<myvector.size(); ++i)
|
PRINT(myvector)
|
||||||
std::cout << ' ' << myvector[i];
|
|
||||||
std::cout << '\n';
|
|
||||||
|
|
||||||
|
|
||||||
// title
|
// title
|
||||||
TITLE(test iterator bigger or equal :)
|
TITLE(test iterator bigger or equal :)
|
||||||
ft::vector<int> vector2;
|
ft::vector<T> vector2;
|
||||||
int size;
|
|
||||||
|
|
||||||
for (int i=1; i<=100; i++) vector2.push_back(i);
|
for (int i=1; i<=100; i++) vector2.push_back(VAL(i));
|
||||||
size = vector2.size();
|
PRINT(vector2)
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
std::cout << "[" << i << "] " << vector2[i] << " ";
|
|
||||||
std::cout << "\nsize:" << size << " capacity:" << vector2.capacity() << "\n";
|
|
||||||
|
|
||||||
std::cout << "\nerase pos(7,36) :\n";
|
std::cout << "\nerase pos(7,36) :\n";
|
||||||
vector2.erase(vector2.begin() + 7, vector2.begin() + 36);
|
vector2.erase(vector2.begin() + 7, vector2.begin() + 36);
|
||||||
size = vector2.size();
|
PRINT(vector2)
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
std::cout << "[" << i << "] " << vector2[i] << " ";
|
|
||||||
std::cout << "\nsize:" << size << " capacity:" << vector2.capacity() << "\n";
|
|
||||||
|
|
||||||
std::cout << "\nerase pos(46,54) :\n";
|
std::cout << "\nerase pos(46,54) :\n";
|
||||||
vector2.erase(vector2.begin() + 46, vector2.begin() + 54);
|
vector2.erase(vector2.begin() + 46, vector2.begin() + 54);
|
||||||
size = vector2.size();
|
PRINT(vector2)
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
std::cout << "[" << i << "] " << vector2[i] << " ";
|
|
||||||
std::cout << "\nsize:" << size << " capacity:" << vector2.capacity() << "\n";
|
|
||||||
|
|
||||||
std::cout << "\nerase pos(7,7) :\n";
|
std::cout << "\nerase pos(7,7) :\n";
|
||||||
vector2.erase(vector2.begin() + 7, vector2.begin() + 7);
|
vector2.erase(vector2.begin() + 7, vector2.begin() + 7);
|
||||||
size = vector2.size();
|
PRINT(vector2)
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
std::cout << "[" << i << "] " << vector2[i] << " ";
|
DELETE
|
||||||
std::cout << "\nsize:" << size << " capacity:" << vector2.capacity() << "\n";
|
|
||||||
}
|
|
||||||
TESTEND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tests_vector_swap()
|
TEST(tests_vector_swap)
|
||||||
{
|
{
|
||||||
TEST(vector::swap)
|
|
||||||
{
|
|
||||||
// title
|
// title
|
||||||
TITLE(cplusplus.com reference :)
|
TITLE(cplusplus.com reference :)
|
||||||
|
|
||||||
ft::vector<int> foo (3,100); // three ints with a value of 100
|
ft::vector<T> foo (3,VAL(100)); // three ints with a value of 100
|
||||||
ft::vector<int> bar (5,200); // five ints with a value of 200
|
ft::vector<T> bar (5,VAL(200)); // five ints with a value of 200
|
||||||
|
|
||||||
foo.swap(bar);
|
foo.swap(bar);
|
||||||
|
|
||||||
std::cout << "foo contains:";
|
std::cout << "foo contains:";
|
||||||
for (unsigned i=0; i<foo.size(); i++)
|
PRINT(foo)
|
||||||
std::cout << ' ' << foo[i];
|
|
||||||
std::cout << '\n';
|
|
||||||
|
|
||||||
std::cout << "bar contains:";
|
std::cout << "bar contains:";
|
||||||
for (unsigned i=0; i<bar.size(); i++)
|
PRINT(bar)
|
||||||
std::cout << ' ' << bar[i];
|
|
||||||
std::cout << '\n';
|
DELETE
|
||||||
}
|
|
||||||
TESTEND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tests_vector_clear()
|
TEST(tests_vector_clear)
|
||||||
{
|
{
|
||||||
TEST(vector::clear)
|
|
||||||
{
|
|
||||||
// title
|
// title
|
||||||
TITLE(cplusplus.com reference :)
|
TITLE(cplusplus.com reference :)
|
||||||
|
|
||||||
ft::vector<int> myvector;
|
ft::vector<T> myvector;
|
||||||
myvector.push_back (100);
|
myvector.push_back (VAL(100));
|
||||||
myvector.push_back (200);
|
myvector.push_back (VAL(200));
|
||||||
myvector.push_back (300);
|
myvector.push_back (VAL(300));
|
||||||
|
|
||||||
std::cout << "myvector contains:";
|
std::cout << "myvector contains:";
|
||||||
for (unsigned i=0; i<myvector.size(); i++)
|
PRINT(myvector)
|
||||||
std::cout << ' ' << myvector[i];
|
|
||||||
std::cout << '\n';
|
|
||||||
|
|
||||||
myvector.clear();
|
myvector.clear();
|
||||||
myvector.push_back (1101);
|
myvector.push_back (VAL(1101));
|
||||||
myvector.push_back (2202);
|
myvector.push_back (VAL(2202));
|
||||||
|
|
||||||
std::cout << "myvector contains:";
|
std::cout << "myvector contains:";
|
||||||
for (unsigned i=0; i<myvector.size(); i++)
|
PRINT(myvector)
|
||||||
std::cout << ' ' << myvector[i];
|
|
||||||
std::cout << '\n';
|
DELETE
|
||||||
}
|
|
||||||
TESTEND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tests_vector_get_allocator()
|
TEST(tests_vector_get_allocator)
|
||||||
{
|
{
|
||||||
TEST(vector::get_allocator)
|
|
||||||
{
|
|
||||||
// title
|
// title
|
||||||
TITLE(cplusplus.com reference :)
|
TITLE(cplusplus.com reference :)
|
||||||
|
|
||||||
ft::vector<int> myvector;
|
ft::vector<T> myvector;
|
||||||
int * p;
|
T * p;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
// allocate an array with space for 5 elements using vector's allocator:
|
// allocate an array with space for 5 elements using vector's allocator:
|
||||||
p = myvector.get_allocator().allocate(5);
|
p = myvector.get_allocator().allocate(5);
|
||||||
|
|
||||||
// construct values in-place on the array:
|
// construct values in-place on the array:
|
||||||
for (i=0; i<5; i++) myvector.get_allocator().construct(&p[i],i);
|
for (i=0; i<5; i++) myvector.get_allocator().construct(&p[i],VAL(i));
|
||||||
|
|
||||||
std::cout << "The allocated array contains:";
|
std::cout << "The allocated array contains:";
|
||||||
for (i=0; i<5; i++) std::cout << ' ' << p[i];
|
for (i=0; i<5; i++) std::cout << ' ' << p[i];
|
||||||
@@ -754,19 +720,17 @@ void tests_vector_get_allocator()
|
|||||||
// destroy and deallocate:
|
// destroy and deallocate:
|
||||||
for (i=0; i<5; i++) myvector.get_allocator().destroy(&p[i]);
|
for (i=0; i<5; i++) myvector.get_allocator().destroy(&p[i]);
|
||||||
myvector.get_allocator().deallocate(p,5);
|
myvector.get_allocator().deallocate(p,5);
|
||||||
}
|
|
||||||
TESTEND
|
DELETE
|
||||||
}
|
}
|
||||||
|
|
||||||
void tests_vector_relational_operators()
|
TEST(tests_vector_relational_operators)
|
||||||
{
|
{
|
||||||
TEST(ft::relational operators)
|
|
||||||
{
|
|
||||||
// title
|
// title
|
||||||
TITLE(cplusplus.com reference :)
|
TITLE(cplusplus.com reference :)
|
||||||
|
|
||||||
ft::vector<int> foo (3,100); // three ints with a value of 100
|
ft::vector<T> foo (3,VAL(100)); // three ints with a value of 100
|
||||||
ft::vector<int> bar (2,200); // two ints with a value of 200
|
ft::vector<T> bar (2,VAL(200)); // two ints with a value of 200
|
||||||
|
|
||||||
if (foo==bar) std::cout << "foo and bar are equal\n";
|
if (foo==bar) std::cout << "foo and bar are equal\n";
|
||||||
if (foo!=bar) std::cout << "foo and bar are not equal\n";
|
if (foo!=bar) std::cout << "foo and bar are not equal\n";
|
||||||
@@ -774,45 +738,38 @@ void tests_vector_relational_operators()
|
|||||||
if (foo> bar) std::cout << "foo is greater than bar\n";
|
if (foo> bar) std::cout << "foo is greater than bar\n";
|
||||||
if (foo<=bar) std::cout << "foo is less than or equal to bar\n";
|
if (foo<=bar) std::cout << "foo is less than or equal to bar\n";
|
||||||
if (foo>=bar) std::cout << "foo is greater than or equal to bar\n";
|
if (foo>=bar) std::cout << "foo is greater than or equal to bar\n";
|
||||||
}
|
|
||||||
TESTEND
|
DELETE
|
||||||
}
|
}
|
||||||
void tests_vector_swap_non_member()
|
|
||||||
|
TEST(tests_vector_swap_non_member)
|
||||||
{
|
{
|
||||||
TEST(ft::swap vector)
|
|
||||||
{
|
|
||||||
// title
|
// title
|
||||||
TITLE(cplusplus.com reference :)
|
TITLE(cplusplus.com reference :)
|
||||||
|
|
||||||
ft::vector<int> foo (3,100); // three ints with a value of 100
|
ft::vector<T> foo (3,VAL(100)); // three ints with a value of 100
|
||||||
ft::vector<int> bar (5,200); // five ints with a value of 200
|
ft::vector<T> bar (5,VAL(200)); // five ints with a value of 200
|
||||||
|
|
||||||
foo.swap(bar);
|
foo.swap(bar);
|
||||||
|
|
||||||
std::cout << "foo contains:";
|
std::cout << "foo contains:";
|
||||||
for (ft::vector<int>::iterator it = foo.begin(); it!=foo.end(); ++it)
|
PRINT(foo)
|
||||||
std::cout << ' ' << *it;
|
|
||||||
std::cout << '\n';
|
|
||||||
|
|
||||||
std::cout << "bar contains:";
|
std::cout << "bar contains:";
|
||||||
for (ft::vector<int>::iterator it = bar.begin(); it!=bar.end(); ++it)
|
PRINT(bar)
|
||||||
std::cout << ' ' << *it;
|
|
||||||
std::cout << '\n';
|
DELETE
|
||||||
}
|
|
||||||
TESTEND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tests_vector_reverse_iterators()
|
TEST(tests_vector_reverse_iterators)
|
||||||
{
|
{
|
||||||
TEST(ft::reverse_iterator)
|
|
||||||
{
|
|
||||||
// title
|
// title
|
||||||
TITLE(cplusplus.com reference)
|
TITLE(cplusplus.com reference)
|
||||||
TITLE(::constructor ::operator* ::operator++(int))
|
TITLE(::constructor ::operator* ::operator++(val))
|
||||||
|
|
||||||
ft::vector<int> myvector;
|
ft::vector<T> myvector;
|
||||||
for (int i=0; i<10; i++) myvector.push_back(i);
|
for (int i=0; i<10; i++) myvector.push_back(VAL(i));
|
||||||
typedef ft::vector<int>::iterator iter_type;
|
typedef typename ft::vector<T>::iterator iter_type;
|
||||||
// ? 0 1 2 3 4 5 6 7 8 9 ?
|
// ? 0 1 2 3 4 5 6 7 8 9 ?
|
||||||
iter_type from (myvector.begin()); // ^
|
iter_type from (myvector.begin()); // ^
|
||||||
iter_type until (myvector.end()); // ^
|
iter_type until (myvector.end()); // ^
|
||||||
@@ -918,7 +875,7 @@ void tests_vector_reverse_iterators()
|
|||||||
// title
|
// title
|
||||||
TITLE(::operator- non-member)
|
TITLE(::operator- non-member)
|
||||||
|
|
||||||
ft::reverse_iterator<ft::vector<int>::iterator> rev_it_from,rev_it_until;
|
ft::reverse_iterator<typename ft::vector<T>::iterator> rev_it_from,rev_it_until;
|
||||||
rev_it_from = myvector.rbegin();
|
rev_it_from = myvector.rbegin();
|
||||||
rev_it_until = myvector.rend();
|
rev_it_until = myvector.rend();
|
||||||
std::cout << "myvector has " << (rev_it_until-rev_it_from) << " elements.\n";
|
std::cout << "myvector has " << (rev_it_until-rev_it_from) << " elements.\n";
|
||||||
@@ -931,9 +888,7 @@ void tests_vector_reverse_iterators()
|
|||||||
rev_it_n_memb = 3 + myvector.rbegin();
|
rev_it_n_memb = 3 + myvector.rbegin();
|
||||||
std::cout << "The fourth element from the end is: " << *rev_it_n_memb << '\n';
|
std::cout << "The fourth element from the end is: " << *rev_it_n_memb << '\n';
|
||||||
|
|
||||||
}
|
DELETE
|
||||||
TESTEND
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user