1 // Copyright 2014 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 "base/containers/adapters.h"
6
7 #include <vector>
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace {
12
TEST(AdaptersTest,Reversed)13 TEST(AdaptersTest, Reversed) {
14 std::vector<int> v;
15 v.push_back(3);
16 v.push_back(2);
17 v.push_back(1);
18 int j = 0;
19 for (int& i : base::Reversed(v)) {
20 EXPECT_EQ(++j, i);
21 i += 100;
22 }
23 EXPECT_EQ(103, v[0]);
24 EXPECT_EQ(102, v[1]);
25 EXPECT_EQ(101, v[2]);
26 }
27
TEST(AdaptersTest,ReversedArray)28 TEST(AdaptersTest, ReversedArray) {
29 int v[3] = {3, 2, 1};
30 int j = 0;
31 for (int& i : base::Reversed(v)) {
32 EXPECT_EQ(++j, i);
33 i += 100;
34 }
35 EXPECT_EQ(103, v[0]);
36 EXPECT_EQ(102, v[1]);
37 EXPECT_EQ(101, v[2]);
38 }
39
TEST(AdaptersTest,ReversedConst)40 TEST(AdaptersTest, ReversedConst) {
41 std::vector<int> v;
42 v.push_back(3);
43 v.push_back(2);
44 v.push_back(1);
45 const std::vector<int>& cv = v;
46 int j = 0;
47 for (int i : base::Reversed(cv)) {
48 EXPECT_EQ(++j, i);
49 }
50 }
51
52 } // namespace
53