void test_matrix_rep()
{
	Rep matrix;
	matrix.set(1, 1, 1);
	matrix.reserve(3, 3);
	matrix.set(3, 2, 3);
	assert(matrix.get(3, 2) == 3);
	assert(matrix.get(4, 3) == 0);

	assert(matrix.is_null(4,3));
	assert(!matrix.is_null(3,2));

	matrix.set(4, 2, 2);
	matrix.reserve(4, 4);

	assert(matrix.get(3, 2) == 3);
	assert(matrix.get(4, 2) == 2);
	assert(!matrix.is_null(4, 2));
	assert(matrix.is_null(10, 10));
}
Example #2
0
wstring& wstring::replace(size_t pos, size_t n1, size_t n2, wchar_t c) {
    const size_t len = length();
    if (pos > len)
        throw out_of_range("pos > len");
    if (n1 > len - pos)
        n1 = len - pos;
    if (len - n1 > max_size() - n2)
        throw length_error("len - n1 > max_size() - n2");
    size_t newlen = len - n1 + n2;
    if (check_realloc(newlen)) {
        Rep *p = Rep::create(newlen);
        p->copy(0, data(), pos);
        p->copy(pos + n2, data() + pos + n1, len -(pos + n1));
        p->set (pos, c, n2);
        repup(p);
    }
    else {
        rep()->move(pos + n2, data() + pos + n1, len -(pos + n1));
        rep()->set (pos, c, n2);
    }
    rep()->len = newlen;
    return *this;
}