Ninja
|
00001 // Copyright 2011 Google Inc. All Rights Reserved. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); 00004 // you may not use this file except in compliance with the License. 00005 // You may obtain a copy of the License at 00006 // 00007 // http://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 // See the License for the specific language governing permissions and 00013 // limitations under the License. 00014 00015 #include "edit_distance.h" 00016 00017 #include "test.h" 00018 00019 TEST(EditDistanceTest, TestEmpty) { 00020 EXPECT_EQ(5, EditDistance("", "ninja")); 00021 EXPECT_EQ(5, EditDistance("ninja", "")); 00022 EXPECT_EQ(0, EditDistance("", "")); 00023 } 00024 00025 TEST(EditDistanceTest, TestMaxDistance) { 00026 const bool allow_replacements = true; 00027 for (int max_distance = 1; max_distance < 7; ++max_distance) { 00028 EXPECT_EQ(max_distance + 1, 00029 EditDistance("abcdefghijklmnop", "ponmlkjihgfedcba", 00030 allow_replacements, max_distance)); 00031 } 00032 } 00033 00034 TEST(EditDistanceTest, TestAllowReplacements) { 00035 bool allow_replacements = true; 00036 EXPECT_EQ(1, EditDistance("ninja", "njnja", allow_replacements)); 00037 EXPECT_EQ(1, EditDistance("njnja", "ninja", allow_replacements)); 00038 00039 allow_replacements = false; 00040 EXPECT_EQ(2, EditDistance("ninja", "njnja", allow_replacements)); 00041 EXPECT_EQ(2, EditDistance("njnja", "ninja", allow_replacements)); 00042 } 00043 00044 TEST(EditDistanceTest, TestBasics) { 00045 EXPECT_EQ(0, EditDistance("browser_tests", "browser_tests")); 00046 EXPECT_EQ(1, EditDistance("browser_test", "browser_tests")); 00047 EXPECT_EQ(1, EditDistance("browser_tests", "browser_test")); 00048 }