all vector tests pass

This commit is contained in:
hugogogo
2022-06-17 01:20:46 +02:00
parent da4ebc13fd
commit df6332b496
2 changed files with 235 additions and 280 deletions

View File

@@ -28,13 +28,13 @@ int main() {
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_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_constructor();

View File

@@ -488,7 +488,6 @@ TEST(tests_vector_push_back)
TITLE(big push back :)
for (int i = 0; i < 72363; i++)
// for (int i = 0; i < 363; i++)
{
myvector.push_back(VAL(9));
std::cout << "[" << i
@@ -616,18 +615,15 @@ TEST(tests_vector_insert)
DELETE
}
/*
void tests_vector_erase()
{
TEST(vector::erase)
TEST(tests_vector_erase)
{
// title
TITLE(cplusplus.com reference :)
ft::vector<int> myvector;
ft::vector<T> myvector;
// 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
myvector.erase (myvector.begin()+5);
@@ -636,116 +632,86 @@ void tests_vector_erase()
myvector.erase (myvector.begin(),myvector.begin()+3);
std::cout << "myvector contains:";
for (unsigned i=0; i<myvector.size(); ++i)
std::cout << ' ' << myvector[i];
std::cout << '\n';
PRINT(myvector)
// title
TITLE(test iterator bigger or equal :)
ft::vector<int> vector2;
int size;
ft::vector<T> vector2;
for (int i=1; i<=100; i++) vector2.push_back(i);
size = vector2.size();
for (int i = 0; i < size; i++)
std::cout << "[" << i << "] " << vector2[i] << " ";
std::cout << "\nsize:" << size << " capacity:" << vector2.capacity() << "\n";
for (int i=1; i<=100; i++) vector2.push_back(VAL(i));
PRINT(vector2)
std::cout << "\nerase pos(7,36) :\n";
vector2.erase(vector2.begin() + 7, vector2.begin() + 36);
size = vector2.size();
for (int i = 0; i < size; i++)
std::cout << "[" << i << "] " << vector2[i] << " ";
std::cout << "\nsize:" << size << " capacity:" << vector2.capacity() << "\n";
PRINT(vector2)
std::cout << "\nerase pos(46,54) :\n";
vector2.erase(vector2.begin() + 46, vector2.begin() + 54);
size = vector2.size();
for (int i = 0; i < size; i++)
std::cout << "[" << i << "] " << vector2[i] << " ";
std::cout << "\nsize:" << size << " capacity:" << vector2.capacity() << "\n";
PRINT(vector2)
std::cout << "\nerase pos(7,7) :\n";
vector2.erase(vector2.begin() + 7, vector2.begin() + 7);
size = vector2.size();
for (int i = 0; i < size; i++)
std::cout << "[" << i << "] " << vector2[i] << " ";
std::cout << "\nsize:" << size << " capacity:" << vector2.capacity() << "\n";
}
TESTEND
PRINT(vector2)
DELETE
}
void tests_vector_swap()
{
TEST(vector::swap)
TEST(tests_vector_swap)
{
// title
TITLE(cplusplus.com reference :)
ft::vector<int> foo (3,100); // three ints with a value of 100
ft::vector<int> bar (5,200); // five ints with a value of 200
ft::vector<T> foo (3,VAL(100)); // three ints with a value of 100
ft::vector<T> bar (5,VAL(200)); // five ints with a value of 200
foo.swap(bar);
std::cout << "foo contains:";
for (unsigned i=0; i<foo.size(); i++)
std::cout << ' ' << foo[i];
std::cout << '\n';
PRINT(foo)
std::cout << "bar contains:";
for (unsigned i=0; i<bar.size(); i++)
std::cout << ' ' << bar[i];
std::cout << '\n';
}
TESTEND
PRINT(bar)
DELETE
}
void tests_vector_clear()
{
TEST(vector::clear)
TEST(tests_vector_clear)
{
// title
TITLE(cplusplus.com reference :)
ft::vector<int> myvector;
myvector.push_back (100);
myvector.push_back (200);
myvector.push_back (300);
ft::vector<T> myvector;
myvector.push_back (VAL(100));
myvector.push_back (VAL(200));
myvector.push_back (VAL(300));
std::cout << "myvector contains:";
for (unsigned i=0; i<myvector.size(); i++)
std::cout << ' ' << myvector[i];
std::cout << '\n';
PRINT(myvector)
myvector.clear();
myvector.push_back (1101);
myvector.push_back (2202);
myvector.push_back (VAL(1101));
myvector.push_back (VAL(2202));
std::cout << "myvector contains:";
for (unsigned i=0; i<myvector.size(); i++)
std::cout << ' ' << myvector[i];
std::cout << '\n';
}
TESTEND
PRINT(myvector)
DELETE
}
void tests_vector_get_allocator()
{
TEST(vector::get_allocator)
TEST(tests_vector_get_allocator)
{
// title
TITLE(cplusplus.com reference :)
ft::vector<int> myvector;
int * p;
ft::vector<T> myvector;
T * p;
unsigned int i;
// allocate an array with space for 5 elements using vector's allocator:
p = myvector.get_allocator().allocate(5);
// 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:";
for (i=0; i<5; i++) std::cout << ' ' << p[i];
@@ -754,19 +720,17 @@ void tests_vector_get_allocator()
// destroy and deallocate:
for (i=0; i<5; i++) myvector.get_allocator().destroy(&p[i]);
myvector.get_allocator().deallocate(p,5);
}
TESTEND
DELETE
}
void tests_vector_relational_operators()
{
TEST(ft::relational operators)
TEST(tests_vector_relational_operators)
{
// title
TITLE(cplusplus.com reference :)
ft::vector<int> foo (3,100); // three ints with a value of 100
ft::vector<int> bar (2,200); // two ints with a value of 200
ft::vector<T> foo (3,VAL(100)); // three ints with a value of 100
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 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 less than or equal to bar\n";
if (foo>=bar) std::cout << "foo is greater than or equal to bar\n";
DELETE
}
TESTEND
}
void tests_vector_swap_non_member()
{
TEST(ft::swap vector)
TEST(tests_vector_swap_non_member)
{
// title
TITLE(cplusplus.com reference :)
ft::vector<int> foo (3,100); // three ints with a value of 100
ft::vector<int> bar (5,200); // five ints with a value of 200
ft::vector<T> foo (3,VAL(100)); // three ints with a value of 100
ft::vector<T> bar (5,VAL(200)); // five ints with a value of 200
foo.swap(bar);
std::cout << "foo contains:";
for (ft::vector<int>::iterator it = foo.begin(); it!=foo.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
PRINT(foo)
std::cout << "bar contains:";
for (ft::vector<int>::iterator it = bar.begin(); it!=bar.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
}
TESTEND
PRINT(bar)
DELETE
}
void tests_vector_reverse_iterators()
{
TEST(ft::reverse_iterator)
TEST(tests_vector_reverse_iterators)
{
// title
TITLE(cplusplus.com reference)
TITLE(::constructor ::operator* ::operator++(int))
TITLE(::constructor ::operator* ::operator++(val))
ft::vector<int> myvector;
for (int i=0; i<10; i++) myvector.push_back(i);
typedef ft::vector<int>::iterator iter_type;
ft::vector<T> myvector;
for (int i=0; i<10; i++) myvector.push_back(VAL(i));
typedef typename ft::vector<T>::iterator iter_type;
// ? 0 1 2 3 4 5 6 7 8 9 ?
iter_type from (myvector.begin()); // ^
iter_type until (myvector.end()); // ^
@@ -918,7 +875,7 @@ void tests_vector_reverse_iterators()
// title
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_until = myvector.rend();
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();
std::cout << "The fourth element from the end is: " << *rev_it_n_memb << '\n';
DELETE
}
TESTEND
}
*/
#endif