| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <memory> | |
| 6 #include <vector> | |
| 7 | |
| 8 #include "components/ntp_snippets/inner_iterator.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 int ii[] = {0, 1, 2, 3, 4}; | |
| 14 | |
| 15 class InnerIteratorTest : public testing::Test { | |
| 16 protected: | |
| 17 using ListType = std::vector<int*>; | |
| 18 | |
| 19 void SetUp() override { | |
| 20 ints_.push_back(&ii[0]); | |
| 21 ints_.push_back(&ii[1]); | |
| 22 ints_.push_back(&ii[2]); | |
| 23 ints_.push_back(&ii[3]); | |
| 24 ints_.push_back(&ii[4]); | |
| 25 } | |
| 26 | |
| 27 ListType ints_; | |
| 28 }; | |
| 29 | |
| 30 TEST_F(InnerIteratorTest, Create) { | |
| 31 ntp_snippets::InnerIterator<ListType::iterator, int> x(ints_.begin()); | |
| 32 EXPECT_EQ(0, *x); | |
| 33 } | |
| 34 TEST_F(InnerIteratorTest, PreIncrement) { | |
| 35 ntp_snippets::InnerIterator<ListType::iterator, int> x(ints_.begin()); | |
| 36 EXPECT_EQ(1, *(++x)); | |
| 37 EXPECT_EQ(1, *x); | |
| 38 } | |
| 39 TEST_F(InnerIteratorTest, PostIncrement) { | |
| 40 ntp_snippets::InnerIterator<ListType::iterator, int> x(ints_.begin()); | |
| 41 EXPECT_EQ(0, *(x++)); | |
| 42 EXPECT_EQ(1, *x); | |
| 43 } | |
| 44 TEST_F(InnerIteratorTest, Add) { | |
| 45 ntp_snippets::InnerIterator<ListType::iterator, int> x(ints_.begin()); | |
| 46 EXPECT_EQ(2, *(x + 2)); | |
| 47 EXPECT_EQ(0, *x); | |
| 48 } | |
| 49 TEST_F(InnerIteratorTest, Sub) { | |
| 50 ntp_snippets::InnerIterator<ListType::iterator, int> x(ints_.end()); | |
| 51 EXPECT_EQ(2, *(x - 3)); | |
| 52 EXPECT_EQ(4, *(--x)); | |
| 53 } | |
| 54 TEST_F(InnerIteratorTest, PreDecrement) { | |
| 55 ntp_snippets::InnerIterator<ListType::iterator, int> x(ints_.end()); | |
| 56 EXPECT_EQ(4, *(--x)); | |
| 57 EXPECT_EQ(4, *x); | |
| 58 } | |
| 59 TEST_F(InnerIteratorTest, PostDecrement) { | |
| 60 ntp_snippets::InnerIterator<ListType::iterator, int> x(ints_.end()); | |
| 61 EXPECT_EQ(4, *(--x)); | |
| 62 EXPECT_EQ(4, *(x--)); | |
| 63 EXPECT_EQ(3, *x); | |
| 64 } | |
| 65 TEST_F(InnerIteratorTest, Equality) { | |
| 66 ntp_snippets::InnerIterator<ListType::iterator, int> x(ints_.begin()); | |
| 67 ntp_snippets::InnerIterator<ListType::iterator, int> y(ints_.end()); | |
| 68 x += 2; | |
| 69 y -= 3; | |
| 70 EXPECT_EQ(x, y); | |
| 71 } | |
| 72 | |
| 73 } // namespace | |
| OLD | NEW |