| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "courgette/difference_estimator.h" | 5 #include "courgette/difference_estimator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "courgette/region.h" | 10 #include "courgette/region.h" |
| 11 | 11 |
| 12 using courgette::DifferenceEstimator; | 12 using courgette::DifferenceEstimator; |
| 13 using courgette::Region; | 13 using courgette::Region; |
| 14 | 14 |
| 15 TEST(DifferenceEstimatorTest, TestSame) { | 15 TEST(DifferenceEstimatorTest, TestSame) { |
| 16 static const char kString1[] = "Hello world"; | 16 static const char kString1[] = "Hello world"; |
| 17 // kString2 is stack allocated to prevent string sharing. | 17 // kString2 is stack allocated to prevent string sharing. |
| 18 const char kString2[] = "Hello world"; | 18 const char kString2[] = "Hello world"; |
| 19 DifferenceEstimator difference_estimator; | 19 DifferenceEstimator difference_estimator; |
| 20 DifferenceEstimator::Base* base = | 20 DifferenceEstimator::Base* base = |
| 21 difference_estimator.MakeBase(Region(kString1, sizeof(kString1))); | 21 difference_estimator.MakeBase(Region(kString1, sizeof(kString1))); |
| 22 DifferenceEstimator::Subject* subject = | 22 DifferenceEstimator::Subject* subject = |
| 23 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2))); | 23 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2))); |
| 24 EXPECT_EQ(0, difference_estimator.Measure(base, subject)); | 24 EXPECT_EQ(0U, difference_estimator.Measure(base, subject)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 TEST(DifferenceEstimatorTest, TestDifferent) { | 27 TEST(DifferenceEstimatorTest, TestDifferent) { |
| 28 static const char kString1[] = "Hello world"; | 28 static const char kString1[] = "Hello world"; |
| 29 static const char kString2[] = "Hello universe"; | 29 static const char kString2[] = "Hello universe"; |
| 30 DifferenceEstimator difference_estimator; | 30 DifferenceEstimator difference_estimator; |
| 31 DifferenceEstimator::Base* base = | 31 DifferenceEstimator::Base* base = |
| 32 difference_estimator.MakeBase(Region(kString1, sizeof(kString1))); | 32 difference_estimator.MakeBase(Region(kString1, sizeof(kString1))); |
| 33 DifferenceEstimator::Subject* subject = | 33 DifferenceEstimator::Subject* subject = |
| 34 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2))); | 34 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2))); |
| 35 EXPECT_EQ(10, difference_estimator.Measure(base, subject)); | 35 EXPECT_EQ(10U, difference_estimator.Measure(base, subject)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 TEST(DifferenceEstimatorTest, TestDifferentSuperstring) { | 38 TEST(DifferenceEstimatorTest, TestDifferentSuperstring) { |
| 39 static const char kString1[] = "abcdabcdabcd"; | 39 static const char kString1[] = "abcdabcdabcd"; |
| 40 static const char kString2[] = "abcdabcdabcdabcd"; | 40 static const char kString2[] = "abcdabcdabcdabcd"; |
| 41 DifferenceEstimator difference_estimator; | 41 DifferenceEstimator difference_estimator; |
| 42 DifferenceEstimator::Base* base = | 42 DifferenceEstimator::Base* base = |
| 43 difference_estimator.MakeBase(Region(kString1, sizeof(kString1)-1)); | 43 difference_estimator.MakeBase(Region(kString1, sizeof(kString1)-1)); |
| 44 DifferenceEstimator::Subject* subject = | 44 DifferenceEstimator::Subject* subject = |
| 45 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2)-1)); | 45 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2)-1)); |
| 46 EXPECT_EQ(1, difference_estimator.Measure(base, subject)); | 46 EXPECT_EQ(1U, difference_estimator.Measure(base, subject)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 TEST(DifferenceEstimatorTest, TestDifferentSubstring) { | 49 TEST(DifferenceEstimatorTest, TestDifferentSubstring) { |
| 50 static const char kString1[] = "abcdabcdabcdabcd"; | 50 static const char kString1[] = "abcdabcdabcdabcd"; |
| 51 static const char kString2[] = "abcdabcdabcd"; | 51 static const char kString2[] = "abcdabcdabcd"; |
| 52 DifferenceEstimator difference_estimator; | 52 DifferenceEstimator difference_estimator; |
| 53 DifferenceEstimator::Base* base = | 53 DifferenceEstimator::Base* base = |
| 54 difference_estimator.MakeBase(Region(kString1, sizeof(kString1)-1)); | 54 difference_estimator.MakeBase(Region(kString1, sizeof(kString1)-1)); |
| 55 DifferenceEstimator::Subject* subject = | 55 DifferenceEstimator::Subject* subject = |
| 56 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2)-1)); | 56 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2)-1)); |
| 57 EXPECT_EQ(1, difference_estimator.Measure(base, subject)); | 57 EXPECT_EQ(1U, difference_estimator.Measure(base, subject)); |
| 58 } | 58 } |
| OLD | NEW |