2017-12-19 23:07:51 +00:00
|
|
|
#include <cassert>
|
2017-12-21 22:02:49 +00:00
|
|
|
#include <iostream>
|
2017-12-20 15:33:19 +00:00
|
|
|
#include <ods/simplist.h>
|
2017-12-21 22:02:49 +00:00
|
|
|
#include <ods/simpuset.h>
|
2017-12-19 23:07:51 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_simplist(void)
|
|
|
|
{
|
|
|
|
ods::SimpList<int> sl;
|
|
|
|
|
|
|
|
sl.add(0, 1);
|
|
|
|
sl.add(1, 2);
|
|
|
|
sl.add(2, 3);
|
|
|
|
assert(sl.size() == 3);
|
2017-12-21 22:02:49 +00:00
|
|
|
|
|
|
|
sl.add(0, 4);
|
|
|
|
sl.add(1, 5);
|
|
|
|
sl.add(2, 6);
|
|
|
|
assert(sl.size() == 6);
|
|
|
|
|
|
|
|
int expected[6] = {4, 5, 6, 1, 2, 3};
|
|
|
|
for (size_t i = 0; i < 6; i++) {
|
|
|
|
assert(sl.get(i) == expected[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool caught = false;
|
|
|
|
try {
|
|
|
|
sl.add(8, 8);
|
|
|
|
} catch (std::invalid_argument) {
|
|
|
|
caught = true;
|
|
|
|
}
|
|
|
|
assert(caught);
|
|
|
|
|
|
|
|
assert(sl.get(2) == 6);
|
|
|
|
sl.remove(2);
|
|
|
|
assert(sl.get(2) == 1);
|
|
|
|
assert(sl.size() == 5);
|
|
|
|
sl.set(2, 6);
|
|
|
|
assert(sl.get(2) == 6);
|
|
|
|
|
|
|
|
// expected = {1, 2, 3, 4, 5, 6};
|
|
|
|
for (size_t i = 0; i < 6; i++) {
|
|
|
|
expected[i] = i+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 5; i++) {
|
|
|
|
sl.set(i, i+1);
|
|
|
|
}
|
|
|
|
sl.add(5, 6);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 6; i++) {
|
|
|
|
assert(sl.get(i) == expected[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_simpuset(void)
|
|
|
|
{
|
|
|
|
ods::SimpUSet<int> us;
|
|
|
|
|
|
|
|
assert(us.add(1));
|
2017-12-19 23:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
check_simplist();
|
2017-12-21 22:02:49 +00:00
|
|
|
check_simpuset();
|
|
|
|
cout << "OK" << endl;
|
2017-12-19 23:07:51 +00:00
|
|
|
}
|