Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: pkg/analysis_services/test/correction/levenshtein_test.dart

Issue 417263003: Use a Levenshtein calculating algorithm with a threshold. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_services/lib/src/correction/levenshtein.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library test.services.correction.levenshtein; 8 library test.services.correction.levenshtein;
9 9
10 import 'package:analysis_services/src/correction/levenshtein.dart'; 10 import 'package:analysis_services/src/correction/levenshtein.dart';
11 import 'package:analysis_testing/reflective_tests.dart';
11 import 'package:unittest/unittest.dart'; 12 import 'package:unittest/unittest.dart';
12 13
13 14
14 main() { 15 main() {
15 groupSep = ' | '; 16 groupSep = ' | ';
16 test('getLevenshteinDistance', () { 17 runReflectiveTests(LevenshteinTest);
17 expect(getLevenshteinDistance('test', 'test'), equals(0));
18 expect(getLevenshteinDistance('String', 'Stirng'), equals(2));
19 expect(getLevenshteinDistance('', ''), equals(0));
20 expect(getLevenshteinDistance('kitten', 'sitting'), equals(3));
21 expect(getLevenshteinDistance('Saturday', 'Sunday'), equals(3));
22 expect(
23 getLevenshteinDistance('Saturday', 'sunday', caseSensitive: false),
24 equals(3));
25 expect(
26 getLevenshteinDistance('SaturDay', 'sunday', caseSensitive: false),
27 equals(3));
28 expect(getLevenshteinDistance('', 'fewfe'), equals(5));
29 expect(getLevenshteinDistance('fewfe', ''), equals(5));
30 });
31 } 18 }
19
20 @ReflectiveTestCase()
21 class LevenshteinTest {
22 void test_different_caseInsensitive() {
23 expect(levenshtein('Saturday', 'sunday', 5, caseSensitive: false), 3);
24 expect(levenshtein('SaturDay', 'sunday', 5, caseSensitive: false), 3);
25 }
26
27 void test_different_onThreshold() {
28 expect(levenshtein('', 'abcde', 5), 5);
29 expect(levenshtein('abcde', '', 5), 5);
30 }
31
32 void test_different_overThreshold() {
33 expect(levenshtein('', 'abcde', 2), LEVENSHTEIN_MAX);
34 expect(levenshtein('abcde', '', 2), LEVENSHTEIN_MAX);
35 }
36
37 void test_different_overThreshold_length() {
38 expect(levenshtein('a', 'abcdefgh', 5), LEVENSHTEIN_MAX);
39 expect(levenshtein('abcdefgh', 'a', 5), LEVENSHTEIN_MAX);
40 }
41
42 void test_different_underThreshold() {
43 expect(levenshtein('String', 'Stirng', 5), 2);
44 expect(levenshtein('kitten', 'sitting', 5), 3);
45 expect(levenshtein('Saturday', 'Sunday', 5), 3);
46 }
47
48 void test_negativeThreshold() {
49 expect(() {
50 levenshtein('', '', -5);
51 }, throws);
52 }
53
54 void test_null() {
55 expect(() {
56 levenshtein('', null, 5);
57 }, throws);
58 expect(() {
59 levenshtein(null, '', 5);
60 }, throws);
61 }
62
63 void test_same() {
64 expect(levenshtein('', '', 5), 0);
65 expect(levenshtein('test', 'test', 5), 0);
66 }
67
68 void test_same_caseInsensitive() {
69 expect(levenshtein('test', 'Test', 5, caseSensitive: false), 0);
70 }
71 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/lib/src/correction/levenshtein.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698