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 "ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.h" | 5 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.h" |
6 | 6 |
7 #include "testing/platform_test.h" | 7 #include "testing/platform_test.h" |
8 | 8 |
9 class TabSwitcherUtilsTest : public PlatformTest { | 9 class TabSwitcherUtilsTest : public PlatformTest { |
10 protected: | 10 protected: |
11 // Checks that the computed updates/deletions/insertions to go from |initial| | 11 // Checks that the computed updates/deletions/insertions to go from |initial| |
12 // to |final| correctly match the expected updates/deletions/insertions. | 12 // to |final| correctly match the expected updates/deletions/insertions. |
13 void TestLevenshtein(std::vector<size_t> const& initial, | 13 void TestLevenshtein(std::vector<size_t> const& initial, |
14 std::vector<size_t> const& final, | 14 std::vector<size_t> const& final, |
15 std::vector<size_t> const& expectedSubstitutions, | 15 std::vector<size_t> const& expectedSubstitutions, |
16 std::vector<size_t> const& expectedDeletions, | 16 std::vector<size_t> const& expectedDeletions, |
17 std::vector<size_t> const& expectedInsertions) { | 17 std::vector<size_t> const& expectedInsertions) { |
18 std::vector<size_t> substitutions; | 18 std::vector<size_t> substitutions; |
19 std::vector<size_t> deletions; | 19 std::vector<size_t> deletions; |
20 std::vector<size_t> insertions; | 20 std::vector<size_t> insertions; |
21 ios_internal::MinimalReplacementOperations(initial, final, &substitutions, | 21 TabSwitcherMinimalReplacementOperations(initial, final, &substitutions, |
22 &deletions, &insertions); | 22 &deletions, &insertions); |
23 EXPECT_EQ(substitutions, expectedSubstitutions); | 23 EXPECT_EQ(substitutions, expectedSubstitutions); |
24 EXPECT_EQ(deletions, expectedDeletions); | 24 EXPECT_EQ(deletions, expectedDeletions); |
25 EXPECT_EQ(insertions, expectedInsertions); | 25 EXPECT_EQ(insertions, expectedInsertions); |
26 } | 26 } |
27 }; | 27 }; |
28 | 28 |
29 TEST_F(TabSwitcherUtilsTest, TestLevenshteinEmptyVectors) { | 29 TEST_F(TabSwitcherUtilsTest, TestLevenshteinEmptyVectors) { |
30 std::vector<size_t> initial = {}; | 30 std::vector<size_t> initial = {}; |
31 std::vector<size_t> final = {}; | 31 std::vector<size_t> final = {}; |
32 std::vector<size_t> expectedSubstitutions = {}; | 32 std::vector<size_t> expectedSubstitutions = {}; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 TEST_F(TabSwitcherUtilsTest, | 117 TEST_F(TabSwitcherUtilsTest, |
118 TestLevenshteinPreferInsertionsAndDeletionsOverSubstitutions) { | 118 TestLevenshteinPreferInsertionsAndDeletionsOverSubstitutions) { |
119 std::vector<size_t> initial = {0, 1}; | 119 std::vector<size_t> initial = {0, 1}; |
120 std::vector<size_t> final = {1, 2}; | 120 std::vector<size_t> final = {1, 2}; |
121 std::vector<size_t> expectedSubstitutions = {}; | 121 std::vector<size_t> expectedSubstitutions = {}; |
122 std::vector<size_t> expectedDeletions = {0}; | 122 std::vector<size_t> expectedDeletions = {0}; |
123 std::vector<size_t> expectedInsertions = {1}; | 123 std::vector<size_t> expectedInsertions = {1}; |
124 TestLevenshtein(initial, final, expectedSubstitutions, expectedDeletions, | 124 TestLevenshtein(initial, final, expectedSubstitutions, expectedDeletions, |
125 expectedInsertions); | 125 expectedInsertions); |
126 } | 126 } |
OLD | NEW |