1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
#include <cassert>
#include "List.h"
using namespace std;
int main()
{
List<int> l;
assert(l.size() == 0);
assert(l.empty());
l.push_front(44); // list = 44
assert(!l.empty());
assert(l.front() == 44);
assert(l.back() == 44);
l.push_front(33); // list = 33, 44
assert(l.size() == 2);
assert(l.front() == 33);
assert(l.back() == 44);
l.push_front(22); // list = 22, 33, 44
List<int>::iterator it = l.begin();
l.insert(it, 11); // list = 11, 22, 33, 44
it = l.begin();
assert(l.front() == 11);
assert(*it == 11);
assert(*++it == 22);
assert(*++it == 33);
assert(*++it == 44);
it = l.begin();
++it;
++it;
++it;
l.insert(it, 38); // list = 11, 22, 33, 38, 44
List<int>::iterator it2 = l.begin();
assert(*it2 == 11);
assert(*++it2 == 22);
assert(*++it2 == 33);
assert(*++it2 == 38);
assert(*++it2 == 44);
l.pop_front(); // list = 22, 33, 38, 44
it2 = l.begin();
assert(*it2 == 22);
assert(*++it2 == 33);
assert(*++it2 == 38);
assert(*++it2 == 44);
l.pop_back(); //list = 22, 33, 38
List<int> copy = l; //copy = 22, 33, 38
assert(copy.size() == 3);
List<int>::iterator it3 = copy.begin();
assert(*it3 == 22);
assert(*++it3 == 33);
copy.erase(it3); //copy = 22, 38
assert(copy.size() == 2);
it3 = copy.begin();
assert(*it3 == 22);
assert(*++it3 == 38);
cout << "SUCCESS\n";
}
|