[iter] fix forward implementation in hb_concat().
Add test coverage for forward.
This commit is contained in:
parent
39e76af19e
commit
2e935514d9
|
@ -627,10 +627,12 @@ struct hb_concat_iter_t :
|
||||||
void __forward__ (unsigned n)
|
void __forward__ (unsigned n)
|
||||||
{
|
{
|
||||||
if (n > a.len ()) {
|
if (n > a.len ()) {
|
||||||
a.__forward__ (a.len ());
|
|
||||||
n -= a.len ();
|
n -= a.len ();
|
||||||
|
a.__forward__ (a.len ());
|
||||||
|
b.__forward__ (n);
|
||||||
|
} else {
|
||||||
|
a.__forward__ (n);
|
||||||
}
|
}
|
||||||
b.__forward (n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_concat_iter_t __end__ () const { return hb_concat_iter_t (a.end (), b.end ()); }
|
hb_concat_iter_t __end__ () const { return hb_concat_iter_t (a.end (), b.end ()); }
|
||||||
|
|
|
@ -132,8 +132,11 @@ static void test_concat ()
|
||||||
hb_vector_t<int> d = {1, 2, 3, 4, 5};
|
hb_vector_t<int> d = {1, 2, 3, 4, 5};
|
||||||
|
|
||||||
auto it1 = hb_concat (a, b);
|
auto it1 = hb_concat (a, b);
|
||||||
|
assert (it1.len () == 5);
|
||||||
auto it2 = hb_concat (c, d);
|
auto it2 = hb_concat (c, d);
|
||||||
|
assert (it2.len () == 5);
|
||||||
auto it3 = hb_concat (d, c);
|
auto it3 = hb_concat (d, c);
|
||||||
|
assert (it3.len () == 5);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
assert(it1[i] == i + 1);
|
assert(it1[i] == i + 1);
|
||||||
assert(it2[i] == i + 1);
|
assert(it2[i] == i + 1);
|
||||||
|
@ -143,6 +146,25 @@ static void test_concat ()
|
||||||
check_sequential (it1);
|
check_sequential (it1);
|
||||||
check_sequential (it2);
|
check_sequential (it2);
|
||||||
check_sequential (it3);
|
check_sequential (it3);
|
||||||
|
|
||||||
|
auto it4 = +it1;
|
||||||
|
it4 += 2;
|
||||||
|
assert (*it4 == 3);
|
||||||
|
assert (it4);
|
||||||
|
assert (it4.len () == 3);
|
||||||
|
|
||||||
|
it4 += 2;
|
||||||
|
assert (*it4 == 5);
|
||||||
|
assert (it4);
|
||||||
|
assert (it4.len () == 1);
|
||||||
|
|
||||||
|
it4++;
|
||||||
|
assert (!it4);
|
||||||
|
assert (it4.len () == 0);
|
||||||
|
|
||||||
|
auto it5 = +it1;
|
||||||
|
it5 += 3;
|
||||||
|
assert (*it5 == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue