remove obsolete tests
parent
27005f1715
commit
3a21c86a7e
|
@ -1,44 +0,0 @@
|
||||||
#include <assert.h>
|
|
||||||
#include "ostd/array.hh"
|
|
||||||
#include "ostd/string.hh"
|
|
||||||
|
|
||||||
using namespace ostd;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
Array<int, 5> x = { 2, 4, 8, 16, 32 };
|
|
||||||
|
|
||||||
assert(x.front() == 2);
|
|
||||||
assert(x.back() == 32);
|
|
||||||
|
|
||||||
assert(x[0] == 2);
|
|
||||||
assert(x[2] == 8);
|
|
||||||
|
|
||||||
assert(*(x.at(0)) == x[0]);
|
|
||||||
assert(*(x.at(3)) == x[3]);
|
|
||||||
|
|
||||||
assert(x.size() == 5);
|
|
||||||
|
|
||||||
assert(!x.empty());
|
|
||||||
|
|
||||||
assert(x.in_range(4));
|
|
||||||
assert(x.in_range(0));
|
|
||||||
assert(!x.in_range(5));
|
|
||||||
|
|
||||||
assert(x.data()[0] == x[0]);
|
|
||||||
|
|
||||||
auto r = x.iter();
|
|
||||||
assert(r.front() == 2);
|
|
||||||
assert(r.back() == 32);
|
|
||||||
|
|
||||||
Array<int, 5> z;
|
|
||||||
x.swap(z);
|
|
||||||
|
|
||||||
assert(z.front() == 2);
|
|
||||||
assert(z.back() == 32);
|
|
||||||
|
|
||||||
assert(z.size() == 5);
|
|
||||||
|
|
||||||
assert(to_string(z) == "{2, 4, 8, 16, 32}");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
#include <assert.h>
|
|
||||||
#include "ostd/utility.hh"
|
|
||||||
#include "ostd/string.hh"
|
|
||||||
|
|
||||||
using namespace ostd;
|
|
||||||
|
|
||||||
struct Foo {
|
|
||||||
int x;
|
|
||||||
Foo(): x(5) {}
|
|
||||||
Foo(int v): x(v) {}
|
|
||||||
Foo(const Foo &o): x(o.x) {}
|
|
||||||
Foo(Foo &&o): x(o.x) { o.x = 0; }
|
|
||||||
Foo &operator=(int v) {
|
|
||||||
x = v;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct NotSwappable {
|
|
||||||
int i;
|
|
||||||
NotSwappable(int v): i(v) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Swappable {
|
|
||||||
int i;
|
|
||||||
bool swapped;
|
|
||||||
Swappable(int v): i(v), swapped(false) {}
|
|
||||||
void swap(Swappable &v) {
|
|
||||||
auto j = i;
|
|
||||||
i = v.i;
|
|
||||||
v.i = j;
|
|
||||||
swapped = v.swapped = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
Foo bar(150);
|
|
||||||
Foo baz(move(bar));
|
|
||||||
|
|
||||||
assert(bar.x == 0);
|
|
||||||
assert(baz.x == 150);
|
|
||||||
|
|
||||||
Foo cp(baz);
|
|
||||||
|
|
||||||
assert(baz.x == 150);
|
|
||||||
assert(cp.x == 150);
|
|
||||||
|
|
||||||
auto i = exchange(baz, 20);
|
|
||||||
assert(baz.x == 20);
|
|
||||||
assert(i.x == 150);
|
|
||||||
|
|
||||||
NotSwappable nsx(10);
|
|
||||||
NotSwappable nsy(20);
|
|
||||||
|
|
||||||
swap(nsx, nsy);
|
|
||||||
assert(nsx.i == 20);
|
|
||||||
assert(nsy.i == 10);
|
|
||||||
|
|
||||||
Swappable sx(10);
|
|
||||||
Swappable sy(20);
|
|
||||||
|
|
||||||
assert(!sx.swapped);
|
|
||||||
assert(!sy.swapped);
|
|
||||||
|
|
||||||
swap(sx, sy);
|
|
||||||
assert(sx.swapped);
|
|
||||||
assert(sy.swapped);
|
|
||||||
assert(sx.i == 20);
|
|
||||||
assert(sy.i == 10);
|
|
||||||
|
|
||||||
int ai[3] = { 5, 10, 15 };
|
|
||||||
int bi[3] = { 6, 11, 16 };
|
|
||||||
swap(ai, bi);
|
|
||||||
|
|
||||||
assert(ai[0] == 6);
|
|
||||||
assert(bi[2] == 15);
|
|
||||||
|
|
||||||
auto x = make_pair(5, 3.14f);
|
|
||||||
|
|
||||||
assert((IsSame<decltype(x.first), int>));
|
|
||||||
assert((IsSame<decltype(x.second), float>));
|
|
||||||
|
|
||||||
assert(x.first == 5);
|
|
||||||
assert(x.second == 3.14f);
|
|
||||||
|
|
||||||
auto st = make_pair(5, 10);
|
|
||||||
assert(to_string(st) == "{5, 10}");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
#include <assert.h>
|
|
||||||
#include "ostd/vector.hh"
|
|
||||||
#include "ostd/string.hh"
|
|
||||||
|
|
||||||
using namespace ostd;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
Vector<int> x = { 5, 10, 15, 20 };
|
|
||||||
|
|
||||||
assert(x.front() == 5);
|
|
||||||
assert(x.back() == 20);
|
|
||||||
|
|
||||||
assert(x[0] == 5);
|
|
||||||
assert(x[2] == 15);
|
|
||||||
|
|
||||||
assert(*(x.at(0)) == x[0]);
|
|
||||||
assert(*(x.at(3)) == x[3]);
|
|
||||||
|
|
||||||
assert(x.data()[0] == x[0]);
|
|
||||||
|
|
||||||
assert(x.size() == 4);
|
|
||||||
|
|
||||||
Vector<int> y(5, 10);
|
|
||||||
|
|
||||||
assert(y.size() == 5);
|
|
||||||
assert(y.front() == 10);
|
|
||||||
assert(y.back() == 10);
|
|
||||||
|
|
||||||
Vector<int> z(x);
|
|
||||||
|
|
||||||
assert(x.front() == z.front());
|
|
||||||
assert(x.back() == z.back());
|
|
||||||
|
|
||||||
z.clear();
|
|
||||||
|
|
||||||
assert(z.size() == 0);
|
|
||||||
assert(z.capacity() != 0);
|
|
||||||
assert(z.empty());
|
|
||||||
|
|
||||||
z = move(y);
|
|
||||||
|
|
||||||
assert(z.size() == 5);
|
|
||||||
assert(y.size() == 0);
|
|
||||||
assert(z.front() == 10);
|
|
||||||
assert(z.back() == 10);
|
|
||||||
|
|
||||||
z.resize(150, 5);
|
|
||||||
assert(z.size() == 150);
|
|
||||||
assert(z.front() == 10);
|
|
||||||
assert(z.back() == 5);
|
|
||||||
|
|
||||||
assert(z.push(30) == 30);
|
|
||||||
assert(z.back() == 30);
|
|
||||||
|
|
||||||
assert(z.emplace_back(20) == 20);
|
|
||||||
assert(z.back() == 20);
|
|
||||||
|
|
||||||
z.clear();
|
|
||||||
z.resize(10, 5);
|
|
||||||
|
|
||||||
assert(z.in_range(9));
|
|
||||||
assert(z.in_range(0));
|
|
||||||
assert(!z.in_range(10));
|
|
||||||
|
|
||||||
z.insert(2, 4);
|
|
||||||
assert(z[2] == 4);
|
|
||||||
assert(z[0] == 5);
|
|
||||||
assert(z[3] == 5);
|
|
||||||
assert(z.size() == 11);
|
|
||||||
|
|
||||||
auto r = z.iter();
|
|
||||||
assert(r.front() == 5);
|
|
||||||
assert(r.back() == 5);
|
|
||||||
assert(r[2] == 4);
|
|
||||||
|
|
||||||
auto r2 = iter(z);
|
|
||||||
assert(r.front() == r2.front());
|
|
||||||
|
|
||||||
Vector<int> w;
|
|
||||||
w.swap(z);
|
|
||||||
|
|
||||||
assert(z.size() == 0);
|
|
||||||
assert(w.size() != 0);
|
|
||||||
assert(w.front() == 5);
|
|
||||||
assert(w.back() == 5);
|
|
||||||
|
|
||||||
int pushn[] = { 3, 2, 1 };
|
|
||||||
w.push_n(pushn, 3);
|
|
||||||
|
|
||||||
assert(to_string(w) == "{5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 3, 2, 1}");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue