OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/base/tiling_data.h" | 5 #include "cc/base/tiling_data.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "cc/test/geometry_test_utils.h" | 10 #include "cc/test/geometry_test_utils.h" |
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 TilingData data(gfx::Size(100, 100), gfx::Size(), false); | 1367 TilingData data(gfx::Size(100, 100), gfx::Size(), false); |
1368 TestDiff(data, gfx::Rect(100, 100), gfx::Rect(5, 5), 0); | 1368 TestDiff(data, gfx::Rect(100, 100), gfx::Rect(5, 5), 0); |
1369 } | 1369 } |
1370 | 1370 |
1371 void TestSpiralIterate(int source_line_number, | 1371 void TestSpiralIterate(int source_line_number, |
1372 const TilingData& tiling_data, | 1372 const TilingData& tiling_data, |
1373 const gfx::Rect& consider, | 1373 const gfx::Rect& consider, |
1374 const gfx::Rect& ignore, | 1374 const gfx::Rect& ignore, |
1375 const gfx::Rect& center, | 1375 const gfx::Rect& center, |
1376 const std::vector<std::pair<int, int>>& expected) { | 1376 const std::vector<std::pair<int, int>>& expected) { |
1377 std::vector<std::pair<int, int>> actual; | 1377 std::vector<std::pair<int, int>> actual_forward; |
1378 for (TilingData::SpiralDifferenceIterator it( | 1378 for (TilingData::SpiralDifferenceIterator it( |
1379 &tiling_data, consider, ignore, center); | 1379 &tiling_data, consider, ignore, center); |
1380 it; | 1380 it; |
1381 ++it) { | 1381 ++it) { |
1382 actual.push_back(it.index()); | 1382 actual_forward.push_back(it.index()); |
1383 } | 1383 } |
1384 | 1384 |
1385 EXPECT_EQ(expected.size(), actual.size()) << "error from line " | 1385 EXPECT_EQ(expected.size(), actual_forward.size()) << "error from line " |
1386 << source_line_number; | 1386 << source_line_number; |
1387 for (size_t i = 0; i < std::min(expected.size(), actual.size()); ++i) { | 1387 for (size_t i = 0; i < std::min(expected.size(), actual_forward.size()); |
1388 EXPECT_EQ(expected[i].first, actual[i].first) | 1388 ++i) { |
| 1389 EXPECT_EQ(expected[i].first, actual_forward[i].first) |
1389 << "i: " << i << " error from line: " << source_line_number; | 1390 << "i: " << i << " error from line: " << source_line_number; |
1390 EXPECT_EQ(expected[i].second, actual[i].second) | 1391 EXPECT_EQ(expected[i].second, actual_forward[i].second) |
| 1392 << "i: " << i << " error from line: " << source_line_number; |
| 1393 } |
| 1394 |
| 1395 std::vector<std::pair<int, int>> actual_reverse; |
| 1396 for (TilingData::ReverseSpiralDifferenceIterator it( |
| 1397 &tiling_data, consider, ignore, center); |
| 1398 it; |
| 1399 ++it) { |
| 1400 actual_reverse.push_back(it.index()); |
| 1401 } |
| 1402 |
| 1403 std::vector<std::pair<int, int>> reversed_expected = expected; |
| 1404 std::reverse(reversed_expected.begin(), reversed_expected.end()); |
| 1405 EXPECT_EQ(reversed_expected.size(), actual_reverse.size()) |
| 1406 << "error from line " << source_line_number; |
| 1407 for (size_t i = 0; |
| 1408 i < std::min(reversed_expected.size(), actual_reverse.size()); |
| 1409 ++i) { |
| 1410 EXPECT_EQ(reversed_expected[i].first, actual_reverse[i].first) |
| 1411 << "i: " << i << " error from line: " << source_line_number; |
| 1412 EXPECT_EQ(reversed_expected[i].second, actual_reverse[i].second) |
1391 << "i: " << i << " error from line: " << source_line_number; | 1413 << "i: " << i << " error from line: " << source_line_number; |
1392 } | 1414 } |
1393 } | 1415 } |
1394 | 1416 |
1395 TEST(TilingDataTest, SpiralDifferenceIteratorNoIgnoreFullConsider) { | 1417 TEST(TilingDataTest, SpiralDifferenceIteratorNoIgnoreFullConsider) { |
1396 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false); | 1418 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false); |
1397 gfx::Rect consider(30, 30); | 1419 gfx::Rect consider(30, 30); |
1398 gfx::Rect ignore; | 1420 gfx::Rect ignore; |
1399 std::vector<std::pair<int, int>> expected; | 1421 std::vector<std::pair<int, int>> expected; |
1400 | 1422 |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 expected.push_back(std::make_pair(2, 2)); | 1953 expected.push_back(std::make_pair(2, 2)); |
1932 expected.push_back(std::make_pair(2, 1)); | 1954 expected.push_back(std::make_pair(2, 1)); |
1933 expected.push_back(std::make_pair(2, 0)); | 1955 expected.push_back(std::make_pair(2, 0)); |
1934 | 1956 |
1935 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); | 1957 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); |
1936 } | 1958 } |
1937 | 1959 |
1938 } // namespace | 1960 } // namespace |
1939 | 1961 |
1940 } // namespace cc | 1962 } // namespace cc |
OLD | NEW |