half tests ok on map

This commit is contained in:
hugogogo
2022-06-21 14:41:24 +02:00
parent 28acc5ef51
commit 844701201f
5 changed files with 135 additions and 130 deletions

View File

@@ -4,6 +4,15 @@
#include "tests_utils.hpp"
/**/ // UTILS for some tests
/**/ bool fncomp (char lhs, char rhs) {return lhs<rhs;}
/**/
/**/ struct classcomp {
/**/ bool operator() (const char& lhs, const char& rhs) const
/**/ {return lhs<rhs;}
/**/ };
/**/ ///////////////////////
TEST_M(tests_map_simple)
{
// title
@@ -19,34 +28,30 @@ TEST_M(tests_map_simple)
DELETE
}
/*
TEST_M(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;}
// };
ft::map<T,U> first;
std::map<char,int> first;
first[VALT('a')]=VALU(10);
first[VALT('b')]=VALU(30);
first[VALT('c')]=VALU(50);
first[VALT('d')]=VALU(70);
first['a']=10;
first['b']=30;
first['c']=50;
first['d']=70;
ft::map<T,U> second (first.begin(),first.end());
std::map<char,int> second (first.begin(),first.end());
ft::map<T,U> third (second);
std::map<char,int> third (second);
std::map<char,int,classcomp> fourth; // class as Compare
ft::map<T,U,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
ft::map<T,U,bool(*)(char,char)> fifth (fn_pt); // function pointer as Compare
PRINT(first)
PRINT(second)
PRINT(third)
DELETE
}
@@ -56,19 +61,25 @@ TEST_M(tests_map_operator_assignation)
// title
TITLE(cplusplus.com reference)
std::map<char,int> first;
std::map<char,int> second;
ft::map<T,U> first;
ft::map<T,U> second;
first['x']=8;
first['y']=16;
first['z']=32;
first[VALT('x')]=VALU(8);
first[VALT('y')]=VALU(16);
first[VALT('z')]=VALU(32);
PRINT(first)
PRINT(second)
second=first; // second now contains 3 ints
first=std::map<char,int>(); // and first is now empty
first=ft::map<T,U>(); // and first is now empty
std::cout << "Size of first: " << first.size() << '\n';
std::cout << "Size of second: " << second.size() << '\n';
PRINT(first)
PRINT(second)
DELETE
}
@@ -77,15 +88,13 @@ TEST_M(tests_map_begin)
// title
TITLE(cplusplus.com reference)
std::map<char,int> mymap;
ft::map<T,U> mymap;
mymap['b'] = 100;
mymap['a'] = 200;
mymap['c'] = 300;
mymap[VALT('b')] = VALU(100);
mymap[VALT('a')] = VALU(200);
mymap[VALT('c')] = VALU(300);
// show content:
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
std::cout << it->first << " => " << it->second << '\n';
PRINT(mymap)
DELETE
}
@@ -95,15 +104,13 @@ TEST_M(tests_map_end)
// title
TITLE(cplusplus.com reference)
std::map<char,int> mymap;
ft::map<T,U> mymap;
mymap['b'] = 100;
mymap['a'] = 200;
mymap['c'] = 300;
mymap[VALT('b')] = VALU(100);
mymap[VALT('a')] = VALU(200);
mymap[VALT('c')] = VALU(300);
// show content:
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
std::cout << it->first << " => " << it->second << '\n';
PRINT(mymap)
DELETE
}
@@ -113,14 +120,14 @@ TEST_M(tests_map_rbegin)
// title
TITLE(cplusplus.com reference)
std::map<char,int> mymap;
ft::map<T,U> mymap;
mymap['x'] = 100;
mymap['y'] = 200;
mymap['z'] = 300;
mymap[VALT('x')] = VALU(100);
mymap[VALT('y')] = VALU(200);
mymap[VALT('z')] = VALU(300);
// show content:
std::map<char,int>::reverse_iterator rit;
typename ft::map<T,U>::reverse_iterator rit;
for (rit=mymap.rbegin(); rit!=mymap.rend(); ++rit)
std::cout << rit->first << " => " << rit->second << '\n';
@@ -132,14 +139,14 @@ TEST_M(tests_map_rend)
// title
TITLE(cplusplus.com reference)
std::map<char,int> mymap;
ft::map<T,U> mymap;
mymap['x'] = 100;
mymap['y'] = 200;
mymap['z'] = 300;
mymap[VALT('x')] = VALU(100);
mymap[VALT('y')] = VALU(200);
mymap[VALT('z')] = VALU(300);
// show content:
std::map<char,int>::reverse_iterator rit;
typename ft::map<T,U>::reverse_iterator rit;
for (rit=mymap.rbegin(); rit!=mymap.rend(); ++rit)
std::cout << rit->first << " => " << rit->second << '\n';
@@ -151,16 +158,16 @@ TEST_M(tests_map_empty)
// title
TITLE(cplusplus.com reference)
std::map<char,int> mymap;
ft::map<T,U> mymap;
mymap['a']=10;
mymap['b']=20;
mymap['c']=30;
mymap[VALT('a')]=VALU(10);
mymap[VALT('b')]=VALU(20);
mymap[VALT('c')]=VALU(30);
while (!mymap.empty())
{
std::cout << mymap.begin()->first << " => " << mymap.begin()->second << '\n';
mymap.erase(mymap.begin());
std::cout << mymap.begin()->first << " => " << mymap.begin()->second << '\n';
mymap.erase(mymap.begin());
}
DELETE
@@ -171,13 +178,15 @@ TEST_M(tests_map_size)
// title
TITLE(cplusplus.com reference)
std::map<char,int> mymap;
mymap['a']=101;
mymap['b']=202;
mymap['c']=302;
ft::map<T,U> mymap;
mymap[VALT('a')]=VALU(101);
mymap[VALT('b')]=VALU(202);
mymap[VALT('c')]=VALU(302);
std::cout << "mymap.size() is " << mymap.size() << '\n';
PRINT(mymap)
DELETE
}
@@ -187,11 +196,11 @@ TEST_M(tests_map_max_size)
TITLE(cplusplus.com reference)
int i;
std::map<int,int> mymap;
std::map<T,U> mymap;
if (mymap.max_size()>1000)
{
for (i=0; i<1000; i++) mymap[i]=0;
for (i=0; i<1000; i++) mymap[i]=VALU(0);
std::cout << "The map contains 1000 elements.\n";
}
else std::cout << "The map could not hold 1000 elements.\n";
@@ -204,22 +213,23 @@ TEST_M(tests_map_operator_access)
// title
TITLE(cplusplus.com reference)
std::map<char,std::string> mymap;
ft::map<T,U> mymap;
mymap['a']="an element";
mymap['b']="another element";
mymap['c']=mymap['b'];
mymap[VALT('a')]=VALU("An element");
mymap[VALT('b')]=VALU("another element");
mymap[VALT('c')]=mymap[VAL('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['a'] is " << mymap[VALT('a')] << '\n';
std::cout << "mymap['b'] is " << mymap[VALT('b')] << '\n';
std::cout << "mymap['c'] is " << mymap[VALT('c')] << '\n';
std::cout << "mymap['d'] is " << mymap[VALT('d')] << '\n';
std::cout << "mymap now contains " << mymap.size() << " elements.\n";
DELETE
}
/*
TEST_M(tests_map_insert)
{
// title
@@ -604,7 +614,6 @@ TEST_M(tests_map_swap_non_member)
DELETE
}
*/
#endif