am 07315f94: Merge "Implement IntArrayView::skip()."

* commit '07315f94736fc34678e9ce41a44c1446e2436d3b':
  Implement IntArrayView::skip().
main
Keisuke Kuroyanagi 2014-08-28 03:29:55 +00:00 committed by Android Git Automerger
commit 67d0684355
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