Implement IntArrayView::skip().

Change-Id: Ib7f13963ac1d9c64eff2c08391154c6a25024126
main
Keisuke Kuroyanagi 2014-08-28 12:12:56 +09:00
parent 733a023b64
commit e394a0c6ff
2 changed files with 24 additions and 0 deletions

View File

@ -96,6 +96,13 @@ class IntArrayView {
return IntArrayView(mPtr, std::min(maxSize, mSize));
}
const IntArrayView skip(const size_t n) const {
if (mSize <= n) {
return IntArrayView();
}
return IntArrayView(mPtr + n, mSize - n);
}
private:
DISALLOW_ASSIGNMENT_OPERATOR(IntArrayView);

View File

@ -72,5 +72,22 @@ TEST(IntArrayViewTest, TestLimit) {
}
}
TEST(IntArrayViewTest, TestSkip) {
const std::vector<int> intVector = {3, 2, 1, 0, -1, -2};
IntArrayView intArrayView(intVector);
EXPECT_TRUE(intArrayView.skip(intVector.size()).empty());
EXPECT_TRUE(intArrayView.skip(intVector.size() + 1).empty());
EXPECT_EQ(intArrayView.size(), intArrayView.skip(0).size());
EXPECT_EQ(intArrayView.size(), intArrayView.limit(1000).size());
static const size_t SKIP_COUNT = 2;
IntArrayView subView = intArrayView.skip(SKIP_COUNT);
EXPECT_EQ(intVector.size() - SKIP_COUNT, subView.size());
for (size_t i = 0; i < subView.size(); ++i) {
EXPECT_EQ(intVector[i + SKIP_COUNT], subView[i]);
}
}
} // namespace
} // namespace latinime