Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: test/unittests/base/iterator-unittest.cc

Issue 810683003: [base] Add iterator_range helper class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/base/iterator.h ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project 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 "src/base/iterator.h"
6
7 #include <deque>
8
9 #include "test/unittests/test-utils.h"
10
11 namespace v8 {
12 namespace base {
13
14 TEST(IteratorTest, IteratorRangeEmpty) {
15 base::iterator_range<char*> r;
16 EXPECT_EQ(r.begin(), r.end());
17 EXPECT_EQ(r.end(), r.cend());
18 EXPECT_EQ(r.begin(), r.cbegin());
19 EXPECT_TRUE(r.empty());
20 EXPECT_EQ(0, r.size());
21 }
22
23
24 TEST(IteratorTest, IteratorRangeArray) {
25 int array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
26 base::iterator_range<int*> r1(&array[0], &array[10]);
27 for (auto i : r1) {
28 EXPECT_EQ(array[i], i);
29 }
30 EXPECT_EQ(10, r1.size());
31 EXPECT_FALSE(r1.empty());
32 for (size_t i = 0; i < arraysize(array); ++i) {
33 EXPECT_EQ(r1[i], array[i]);
34 }
35 base::iterator_range<int*> r2(&array[0], &array[0]);
36 EXPECT_EQ(0, r2.size());
37 EXPECT_TRUE(r2.empty());
38 for (auto i : array) {
39 EXPECT_EQ(r2.end(), std::find(r2.begin(), r2.end(), i));
40 }
41 }
42
43
44 TEST(IteratorTest, IteratorRangeDeque) {
45 typedef std::deque<unsigned> C;
46 C c;
47 c.push_back(1);
48 c.push_back(2);
49 c.push_back(2);
50 base::iterator_range<typename C::iterator> r(c.begin(), c.end());
51 EXPECT_EQ(3, r.size());
52 EXPECT_FALSE(r.empty());
53 EXPECT_TRUE(c.begin() == r.begin());
54 EXPECT_TRUE(c.end() == r.end());
55 EXPECT_EQ(0, std::count(r.begin(), r.end(), 0));
56 EXPECT_EQ(1, std::count(r.begin(), r.end(), 1));
57 EXPECT_EQ(2, std::count(r.begin(), r.end(), 2));
58 }
59
60 } // namespace base
61 } // namespace v8
OLDNEW
« no previous file with comments | « src/base/iterator.h ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698