blob: 3932e0422e530435e209f8fb3a8f027f28164081 [file] [log] [blame]
[email protected]04ca1bc2009-05-08 23:00:291// 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
3// found in the LICENSE file.
4
5#include "courgette/difference_estimator.h"
6
7#include <string>
8
9#include "testing/gtest/include/gtest/gtest.h"
10#include "courgette/region.h"
11
12using courgette::DifferenceEstimator;
13using courgette::Region;
14
15TEST(DifferenceEstimatorTest, TestSame) {
16 static const char kString1[] = "Hello world";
17 // kString2 is stack allocated to prevent string sharing.
18 const char kString2[] = "Hello world";
19 DifferenceEstimator difference_estimator;
20 DifferenceEstimator::Base* base =
21 difference_estimator.MakeBase(Region(kString1, sizeof(kString1)));
22 DifferenceEstimator::Subject* subject =
23 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2)));
[email protected]54f1b822009-07-18 03:28:4024 EXPECT_EQ(0U, difference_estimator.Measure(base, subject));
[email protected]04ca1bc2009-05-08 23:00:2925}
26
27TEST(DifferenceEstimatorTest, TestDifferent) {
28 static const char kString1[] = "Hello world";
29 static const char kString2[] = "Hello universe";
30 DifferenceEstimator difference_estimator;
31 DifferenceEstimator::Base* base =
32 difference_estimator.MakeBase(Region(kString1, sizeof(kString1)));
33 DifferenceEstimator::Subject* subject =
34 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2)));
[email protected]54f1b822009-07-18 03:28:4035 EXPECT_EQ(10U, difference_estimator.Measure(base, subject));
[email protected]04ca1bc2009-05-08 23:00:2936}
37
38TEST(DifferenceEstimatorTest, TestDifferentSuperstring) {
39 static const char kString1[] = "abcdabcdabcd";
40 static const char kString2[] = "abcdabcdabcdabcd";
41 DifferenceEstimator difference_estimator;
42 DifferenceEstimator::Base* base =
43 difference_estimator.MakeBase(Region(kString1, sizeof(kString1)-1));
44 DifferenceEstimator::Subject* subject =
45 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2)-1));
[email protected]54f1b822009-07-18 03:28:4046 EXPECT_EQ(1U, difference_estimator.Measure(base, subject));
[email protected]04ca1bc2009-05-08 23:00:2947}
48
49TEST(DifferenceEstimatorTest, TestDifferentSubstring) {
50 static const char kString1[] = "abcdabcdabcdabcd";
51 static const char kString2[] = "abcdabcdabcd";
52 DifferenceEstimator difference_estimator;
53 DifferenceEstimator::Base* base =
54 difference_estimator.MakeBase(Region(kString1, sizeof(kString1)-1));
55 DifferenceEstimator::Subject* subject =
56 difference_estimator.MakeSubject(Region(kString2, sizeof(kString2)-1));
[email protected]54f1b822009-07-18 03:28:4057 EXPECT_EQ(1U, difference_estimator.Measure(base, subject));
[email protected]04ca1bc2009-05-08 23:00:2958}