OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "cc/base/tiling_data.h" | 10 #include "cc/base/tiling_data.h" |
11 #include "cc/test/geometry_test_utils.h" | 11 #include "cc/test/geometry_test_utils.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 namespace { | 15 namespace { |
16 | 16 |
17 void TestSpiralIterate(int source_line_number, | 17 void TestSpiralIterate(int source_line_number, |
18 const TilingData& tiling_data, | 18 const TilingData& tiling_data, |
19 const gfx::Rect& consider, | 19 const gfx::Rect& consider, |
20 const gfx::Rect& ignore, | 20 const gfx::Rect& ignore, |
21 const gfx::Rect& center, | 21 const gfx::Rect& center, |
22 const std::vector<std::pair<int, int>>& expected) { | 22 const std::vector<std::pair<int, int>>& expected) { |
23 std::vector<std::pair<int, int>> actual_forward; | 23 std::vector<std::pair<int, int>> actual_forward; |
24 for (TilingData::SpiralDifferenceIterator it(&tiling_data, consider, ignore, | 24 for (TilingData::SpiralDifferenceIterator it(&tiling_data, consider, ignore, |
25 center); | 25 center, false); |
26 it; ++it) { | 26 it; ++it) { |
27 actual_forward.push_back(it.index()); | 27 actual_forward.push_back(it.index()); |
28 } | 28 } |
29 | 29 |
30 EXPECT_EQ(expected.size(), actual_forward.size()) << "error from line " | 30 EXPECT_EQ(expected.size(), actual_forward.size()) << "error from line " |
31 << source_line_number; | 31 << source_line_number; |
32 for (size_t i = 0; i < std::min(expected.size(), actual_forward.size()); | 32 for (size_t i = 0; i < std::min(expected.size(), actual_forward.size()); |
33 ++i) { | 33 ++i) { |
34 EXPECT_EQ(expected[i].first, actual_forward[i].first) | 34 EXPECT_EQ(expected[i].first, actual_forward[i].first) |
35 << "i: " << i << " error from line: " << source_line_number; | 35 << "i: " << i << " error from line: " << source_line_number; |
36 EXPECT_EQ(expected[i].second, actual_forward[i].second) | 36 EXPECT_EQ(expected[i].second, actual_forward[i].second) |
37 << "i: " << i << " error from line: " << source_line_number; | 37 << "i: " << i << " error from line: " << source_line_number; |
38 } | 38 } |
39 | 39 |
40 std::vector<std::pair<int, int>> actual_reverse; | 40 std::vector<std::pair<int, int>> actual_reverse; |
41 for (TilingData::ReverseSpiralDifferenceIterator it(&tiling_data, consider, | 41 for (TilingData::ReverseSpiralDifferenceIterator it(&tiling_data, consider, |
42 ignore, center); | 42 ignore, center, false); |
43 it; ++it) { | 43 it; ++it) { |
44 actual_reverse.push_back(it.index()); | 44 actual_reverse.push_back(it.index()); |
45 } | 45 } |
46 | 46 |
47 std::vector<std::pair<int, int>> reversed_expected = expected; | 47 std::vector<std::pair<int, int>> reversed_expected = expected; |
48 std::reverse(reversed_expected.begin(), reversed_expected.end()); | 48 std::reverse(reversed_expected.begin(), reversed_expected.end()); |
49 EXPECT_EQ(reversed_expected.size(), actual_reverse.size()) | 49 EXPECT_EQ(reversed_expected.size(), actual_reverse.size()) |
50 << "error from line " << source_line_number; | 50 << "error from line " << source_line_number; |
51 for (size_t i = 0; | 51 for (size_t i = 0; |
52 i < std::min(reversed_expected.size(), actual_reverse.size()); ++i) { | 52 i < std::min(reversed_expected.size(), actual_reverse.size()); ++i) { |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 expected.clear(); | 689 expected.clear(); |
690 expected.push_back(std::make_pair(0, 0)); | 690 expected.push_back(std::make_pair(0, 0)); |
691 | 691 |
692 TestSpiralIterate(__LINE__, smaller_tiling, consider, ignore, center, | 692 TestSpiralIterate(__LINE__, smaller_tiling, consider, ignore, center, |
693 expected); | 693 expected); |
694 } | 694 } |
695 | 695 |
696 } // namespace | 696 } // namespace |
697 | 697 |
698 } // namespace cc | 698 } // namespace cc |
OLD | NEW |