1 | // Copyright 2011 Google Inc. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | #include "edit_distance.h" |
16 | |
17 | #include "test.h" |
18 | |
19 | TEST(EditDistanceTest, TestEmpty) { |
20 | EXPECT_EQ(5, EditDistance("" , "ninja" )); |
21 | EXPECT_EQ(5, EditDistance("ninja" , "" )); |
22 | EXPECT_EQ(0, EditDistance("" , "" )); |
23 | } |
24 | |
25 | TEST(EditDistanceTest, TestMaxDistance) { |
26 | const bool allow_replacements = true; |
27 | for (int max_distance = 1; max_distance < 7; ++max_distance) { |
28 | EXPECT_EQ(max_distance + 1, |
29 | EditDistance("abcdefghijklmnop" , "ponmlkjihgfedcba" , |
30 | allow_replacements, max_distance)); |
31 | } |
32 | } |
33 | |
34 | TEST(EditDistanceTest, TestAllowReplacements) { |
35 | bool allow_replacements = true; |
36 | EXPECT_EQ(1, EditDistance("ninja" , "njnja" , allow_replacements)); |
37 | EXPECT_EQ(1, EditDistance("njnja" , "ninja" , allow_replacements)); |
38 | |
39 | allow_replacements = false; |
40 | EXPECT_EQ(2, EditDistance("ninja" , "njnja" , allow_replacements)); |
41 | EXPECT_EQ(2, EditDistance("njnja" , "ninja" , allow_replacements)); |
42 | } |
43 | |
44 | TEST(EditDistanceTest, TestBasics) { |
45 | EXPECT_EQ(0, EditDistance("browser_tests" , "browser_tests" )); |
46 | EXPECT_EQ(1, EditDistance("browser_test" , "browser_tests" )); |
47 | EXPECT_EQ(1, EditDistance("browser_tests" , "browser_test" )); |
48 | } |
49 | |