You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
783 B
33 lines
783 B
7 years ago
|
#include <mcl/array.hpp>
|
||
7 years ago
|
#include <cybozu/test.hpp>
|
||
|
|
||
|
CYBOZU_TEST_AUTO(resize)
|
||
|
{
|
||
7 years ago
|
mcl::Array<int> a, b;
|
||
7 years ago
|
CYBOZU_TEST_EQUAL(a.size(), 0);
|
||
|
CYBOZU_TEST_EQUAL(b.size(), 0);
|
||
|
|
||
|
const size_t n = 3;
|
||
|
bool ok = a.resize(n);
|
||
|
CYBOZU_TEST_ASSERT(ok);
|
||
|
CYBOZU_TEST_EQUAL(n, a.size());
|
||
|
for (size_t i = 0; i < n; i++) {
|
||
|
a[i] = i;
|
||
|
}
|
||
|
ok = b.copy(a);
|
||
|
CYBOZU_TEST_ASSERT(ok);
|
||
|
CYBOZU_TEST_EQUAL(b.size(), n);
|
||
|
CYBOZU_TEST_EQUAL_ARRAY(a.data(), b.data(), n);
|
||
|
|
||
|
const size_t small = n - 1;
|
||
|
ok = b.resize(small);
|
||
|
CYBOZU_TEST_ASSERT(ok);
|
||
|
CYBOZU_TEST_EQUAL(b.size(), small);
|
||
|
CYBOZU_TEST_EQUAL_ARRAY(a.data(), b.data(), small);
|
||
|
const size_t large = n * 2;
|
||
|
ok = b.resize(large);
|
||
|
CYBOZU_TEST_ASSERT(ok);
|
||
|
CYBOZU_TEST_EQUAL(b.size(), large);
|
||
|
CYBOZU_TEST_EQUAL_ARRAY(a.data(), b.data(), small);
|
||
|
}
|