[Pkg-javascript-commits] [node-fast-levenshtein] 01/04: Import Upstream version 2.0.5
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Tue Oct 11 10:25:30 UTC 2016
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-fast-levenshtein.
commit 0f77e464f95d07dbdb8c937d4a626ce394bfc2e8
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date: Tue Oct 11 15:24:25 2016 +0530
Import Upstream version 2.0.5
---
.gitignore | 4 ++
.travis.yml | 13 ++++
CONTRIBUTING.md | 22 +++++++
Gruntfile.js | 80 +++++++++++++++++++++++
LICENSE.md | 25 ++++++++
README.md | 104 ++++++++++++++++++++++++++++++
benchmark/speed.js | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++
bower.json | 30 +++++++++
levenshtein.js | 102 ++++++++++++++++++++++++++++++
levenshtein.min.js | 2 +
package.json | 39 ++++++++++++
test/mocha.opts | 2 +
test/tests.js | 127 +++++++++++++++++++++++++++++++++++++
test/text1.txt | 1 +
test/text2.txt | 1 +
15 files changed, 734 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0cc2c66
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.iml
+.idea/
+node_modules/
+npm-debug.log
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..ae442c6
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,13 @@
+language: node_js
+
+node_js:
+ - 0.12
+ - 5.0
+ - stable
+
+script:
+ - "npm run build"
+
+notifications:
+ email:
+ - ram at hiddentao.com
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..6662682
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,22 @@
+# Contribute to fast-levenshtein
+
+This guide guidelines for those wishing to contribute to fast-levenshtein.
+
+## Contributor license agreement
+
+By submitting code as an individual or as an entity you agree that your code is [licensed the same as fast-levenshtein](https://github.com/hiddentao/fast-levenshtein/blob/master/LICENSE.md).
+
+## Issues and pull requests
+
+Issues and merge requests should be in English and contain appropriate language for audiences of all ages.
+
+We will only accept a merge requests which meets the following criteria:
+
+* Includes proper tests and all tests pass (unless it contains a test exposing a bug in existing code)
+* Can be merged without problems (if not please use: `git rebase master`)
+* Does not break any existing functionality
+* Fixes one specific issue or implements one specific feature (do not combine things, send separate merge requests if needed)
+* Keeps the code base clean and well structured
+* Contains functionality we think other users will benefit from too
+* Doesn't add unnessecary configuration options since they complicate future changes
+
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..1b9dd08
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,80 @@
+module.exports = function(grunt) {
+
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+
+ mochaTest: {
+ files: ['test/*.js']
+ },
+ mochaTestConfig: {
+ options: {
+ reporter: 'spec',
+ ui: 'exports'
+ }
+ },
+
+ jshint: {
+ options: {
+ "bitwise": false,
+ "camelcase": false,
+ "curly": false,
+ "eqeqeq": true,
+ "forin": true,
+ "immed": true,
+ "indent": 2,
+ "latedef": false,
+ "newcap": true,
+ "noarg": true,
+ "noempty": false,
+ "nonew": true,
+ "plusplus": false,
+ "quotmark": false,
+ "undef": true,
+ "unused": true,
+ "strict": true,
+ "trailing": false,
+
+ "boss": true,
+ "laxcomma": true,
+ "multistr": true,
+ "sub": true,
+ "supernew": true,
+
+ "browser": true,
+ "node": true,
+ "worker": true,
+ "predef": [
+ 'define', 'require', 'setImmediate', 'Intl'
+ ]
+ },
+ files: ['levenshtein.js']
+ },
+
+ uglify: {
+ options: {
+ banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %>. Copyright <%= pkg.author %> */\n'
+ },
+ build: {
+ src: 'levenshtein.js',
+ dest: 'levenshtein.min.js'
+ }
+ },
+
+ benchmarkConfig: {
+ speed: {
+ src: ['benchmark/speed.js']
+ }
+ },
+ });
+
+ require('load-grunt-tasks')(grunt);
+ grunt.renameTask('benchmark', 'benchmarkConfig');
+
+ grunt.registerTask('build', ['jshint', 'uglify', 'mochaTest']);
+
+ grunt.registerTask('default', ['build']);
+
+ grunt.registerTask('benchmark', ['npm-install:levenshtein-edit-distance:levenshtein:natural:levenshtein-component:levenshtein-deltas', 'benchmarkConfig']);
+};
+
+
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..6212406
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,25 @@
+(MIT License)
+
+Copyright (c) 2013 [Ramesh Nair](http://www.hiddentao.com/)
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a778995
--- /dev/null
+++ b/README.md
@@ -0,0 +1,104 @@
+# fast-levenshtein - Levenshtein algorithm in Javascript
+
+[![Build Status](https://secure.travis-ci.org/hiddentao/fast-levenshtein.png)](http://travis-ci.org/hiddentao/fast-levenshtein)
+[![NPM module](https://badge.fury.io/js/fast-levenshtein.png)](https://badge.fury.io/js/fast-levenshtein)
+[![NPM downloads](https://img.shields.io/npm/dm/fast-levenshtein.svg?maxAge=2592000)](https://www.npmjs.com/package/fast-levenshtein)
+[![Follow on Twitter](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/hiddentao)
+
+An efficient Javascript implementation of the [Levenshtein algorithm](http://en.wikipedia.org/wiki/Levenshtein_distance) with locale-specific collator support.
+
+## Features
+
+* Works in node.js and in the browser.
+* Better performance than other implementations by not needing to store the whole matrix ([more info](http://www.codeproject.com/Articles/13525/Fast-memory-efficient-Levenshtein-algorithm)).
+* Locale-sensitive string comparisions if needed.
+* Comprehensive test suite and performance benchmark.
+* Small: <1 KB minified and gzipped
+
+## Installation
+
+### node.js
+
+Install using [npm](http://npmjs.org/):
+
+```bash
+$ npm install fast-levenshtein
+```
+
+### Browser
+
+Using bower:
+
+```bash
+$ bower install fast-levenshtein
+```
+
+If you are not using any module loader system then the API will then be accessible via the `window.Levenshtein` object.
+
+## Examples
+
+**Default usage**
+
+```javascript
+var levenshtein = require('fast-levenshtein');
+
+var distance = levenshtein.get('back', 'book'); // 2
+var distance = levenshtein.get('我愛你', '我叫你'); // 1
+```
+
+**Locale-sensitive string comparisons**
+
+It supports using [Intl.Collator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator) for locale-sensitive string comparisons:
+
+```javascript
+var levenshtein = require('fast-levenshtein');
+
+levenshtein.get('mikailovitch', 'Mikhaïlovitch', { useCollator: true});
+// 1
+```
+
+## Building and Testing
+
+To build the code and run the tests:
+
+```bash
+$ npm install -g grunt-cli
+$ npm install
+$ npm run build
+```
+
+## Performance
+
+_Thanks to [Titus Wormer](https://github.com/wooorm) for [encouraging me](https://github.com/hiddentao/fast-levenshtein/issues/1) to do this._
+
+Benchmarked against other node.js levenshtein distance modules (on Macbook Air 2012, Core i7, 8GB RAM):
+
+```bash
+Running suite Implementation comparison [benchmark/speed.js]...
+>> levenshtein-edit-distance x 234 ops/sec ±3.02% (73 runs sampled)
+>> levenshtein-component x 422 ops/sec ±4.38% (83 runs sampled)
+>> levenshtein-deltas x 283 ops/sec ±3.83% (78 runs sampled)
+>> natural x 255 ops/sec ±0.76% (88 runs sampled)
+>> levenshtein x 180 ops/sec ±3.55% (86 runs sampled)
+>> fast-levenshtein x 1,792 ops/sec ±2.72% (95 runs sampled)
+Benchmark done.
+Fastest test is fast-levenshtein at 4.2x faster than levenshtein-component
+```
+
+You can run this benchmark yourself by doing:
+
+```bash
+$ npm install
+$ npm run build
+$ npm run benchmark
+```
+
+## Contributing
+
+If you wish to submit a pull request please update and/or create new tests for any changes you make and ensure the grunt build passes.
+
+See [CONTRIBUTING.md](https://github.com/hiddentao/fast-levenshtein/blob/master/CONTRIBUTING.md) for details.
+
+## License
+
+MIT - see [LICENSE.md](https://github.com/hiddentao/fast-levenshtein/blob/master/LICENSE.md)
diff --git a/benchmark/speed.js b/benchmark/speed.js
new file mode 100644
index 0000000..2564430
--- /dev/null
+++ b/benchmark/speed.js
@@ -0,0 +1,182 @@
+var fastLevenshtein = require('../levenshtein.min').get,
+ levenshtein = require('levenshtein'),
+ levenshteinEditDistance = require('levenshtein-edit-distance'),
+ levenshteinComponent = require('levenshtein-component'),
+ levenshteinDeltas = require('levenshtein-deltas'),
+ natural = require('natural').LevenshteinDistance;
+
+
+
+/* The first 100 words from Letterpress: https://github.com/atebits/Words */
+source = Array(11).join([
+ 'aa',
+ 'aah',
+ 'aahed',
+ 'aahing',
+ 'aahs',
+ 'aal',
+ 'aalii',
+ 'aaliis',
+ 'aals',
+ 'aardvark',
+ 'aardvarks',
+ 'aardwolf',
+ 'aardwolves',
+ 'aargh',
+ 'aarrgh',
+ 'aarrghh',
+ 'aarti',
+ 'aartis',
+ 'aas',
+ 'aasvogel',
+ 'aasvogels',
+ 'ab',
+ 'aba',
+ 'abac',
+ 'abaca',
+ 'abacas',
+ 'abaci',
+ 'aback',
+ 'abacs',
+ 'abacterial',
+ 'abactinal',
+ 'abactinally',
+ 'abactor',
+ 'abactors',
+ 'abacus',
+ 'abacuses',
+ 'abaft',
+ 'abaka',
+ 'abakas',
+ 'abalone',
+ 'abalones',
+ 'abamp',
+ 'abampere',
+ 'abamperes',
+ 'abamps',
+ 'aband',
+ 'abanded',
+ 'abanding',
+ 'abandon',
+ 'abandoned',
+ 'abandonedly',
+ 'abandonee',
+ 'abandonees',
+ 'abandoner',
+ 'abandoners',
+ 'abandoning',
+ 'abandonment',
+ 'abandonments',
+ 'abandons',
+ 'abandonware',
+ 'abandonwares',
+ 'abands',
+ 'abapical',
+ 'abas',
+ 'abase',
+ 'abased',
+ 'abasedly',
+ 'abasement',
+ 'abasements',
+ 'abaser',
+ 'abasers',
+ 'abases',
+ 'abash',
+ 'abashed',
+ 'abashedly',
+ 'abashes',
+ 'abashing',
+ 'abashless',
+ 'abashment',
+ 'abashments',
+ 'abasia',
+ 'abasias',
+ 'abasing',
+ 'abask',
+ 'abatable',
+ 'abate',
+ 'abated',
+ 'abatement',
+ 'abatements',
+ 'abater',
+ 'abaters',
+ 'abates',
+ 'abating',
+ 'abatis',
+ 'abatises',
+ 'abator',
+ 'abators',
+ 'abattis',
+ 'abattises',
+ 'abattoir',
+ 'abattoirs'
+].join('|')).split('|');
+
+
+
+/**
+ * The actual test loop.
+ * @param {Function} fn Levenshtein distance function.
+ */
+var loop = function(fn) {
+ var iterator = -1,
+ previousValue = '',
+ value,
+ dist;
+
+ while (value = source[++iterator]) {
+ dist = fn(previousValue, value);
+ previousValue = value;
+ }
+};
+
+
+/** @type {Object} Test config */
+module.exports = {
+ name: 'Implementation comparison',
+ onComplete: function() {
+ console.log('Benchmark done.');
+ },
+ tests: [
+ {
+ name: 'levenshtein-edit-distance',
+ fn: function() {
+ loop(levenshteinEditDistance);
+ }
+ },
+ {
+ name: 'levenshtein-component',
+ fn: function() {
+ loop(levenshteinComponent);
+ }
+ },
+ {
+ name: 'levenshtein-deltas',
+ fn: function() {
+ loop(function(v1,v2) {
+ return new levenshteinDeltas.Lev(v1,v2).distance();
+ });
+ }
+ },
+ {
+ name: 'natural',
+ fn: function() {
+ loop(natural);
+ }
+ },
+ {
+ name: 'levenshtein',
+ fn: function() {
+ loop(levenshtein);
+ }
+ },
+ {
+ name: 'fast-levenshtein',
+ fn: function() {
+ loop(fastLevenshtein);
+ }
+ },
+ ]
+};
+
+
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..32d253f
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,30 @@
+{
+ "name": "fast-levenshtein",
+ "version": "1.1.3",
+ "homepage": "https://github.com/hiddentao/fast-levenshtein",
+ "authors": [
+ "Ramesh Nair <ram at hiddentao.com>"
+ ],
+ "description": "Efficient implementation of Levenshtein algorithm with asynchronous callback support",
+ "main": "levenshtein.js",
+ "moduleType": [
+ "amd",
+ "globals",
+ "node"
+ ],
+ "keywords": [
+ "levenshtein",
+ "distance",
+ "string"
+ ],
+ "license": "MIT",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "bower_components",
+ "test",
+ "tests",
+ "benchmark",
+ "Gruntfile.js"
+ ]
+}
diff --git a/levenshtein.js b/levenshtein.js
new file mode 100644
index 0000000..404a315
--- /dev/null
+++ b/levenshtein.js
@@ -0,0 +1,102 @@
+(function() {
+ 'use strict';
+
+ var collator;
+ try {
+ collator = (typeof Intl !== "undefined" && typeof Intl.Collator !== "undefined") ? Intl.Collator("generic", { sensitivity: "base" }) : null;
+ } catch (err){
+ console.log("Collator could not be initialized and wouldn't be used");
+ }
+ // arrays to re-use
+ var prevRow = [],
+ str2Char = [];
+
+ /**
+ * Based on the algorithm at http://en.wikipedia.org/wiki/Levenshtein_distance.
+ */
+ var Levenshtein = {
+ /**
+ * Calculate levenshtein distance of the two strings.
+ *
+ * @param str1 String the first string.
+ * @param str2 String the second string.
+ * @param [options] Additional options.
+ * @param [options.useCollator] Use `Intl.Collator` for locale-sensitive string comparison.
+ * @return Integer the levenshtein distance (0 and above).
+ */
+ get: function(str1, str2, options) {
+ var useCollator = (options && collator && options.useCollator);
+
+ var str1Len = str1.length,
+ str2Len = str2.length;
+
+ // base cases
+ if (str1Len === 0) return str2Len;
+ if (str2Len === 0) return str1Len;
+
+ // two rows
+ var curCol, nextCol, i, j, tmp;
+
+ // initialise previous row
+ for (i=0; i<str2Len; ++i) {
+ prevRow[i] = i;
+ str2Char[i] = str2.charCodeAt(i);
+ }
+ prevRow[str2Len] = str2Len;
+
+ // calculate current row distance from previous row
+ for (i=0; i<str1Len; ++i) {
+ nextCol = i + 1;
+
+ for (j=0; j<str2Len; ++j) {
+ curCol = nextCol;
+
+ // substution
+ var strCmp = useCollator ? (0 === collator.compare(str1.charAt(i), String.fromCharCode(str2Char[j]))) : str1.charCodeAt(i) === str2Char[j];
+
+ nextCol = prevRow[j] + ( strCmp ? 0 : 1 );
+
+ // insertion
+ tmp = curCol + 1;
+ if (nextCol > tmp) {
+ nextCol = tmp;
+ }
+ // deletion
+ tmp = prevRow[j + 1] + 1;
+ if (nextCol > tmp) {
+ nextCol = tmp;
+ }
+
+ // copy current col value into previous (in preparation for next iteration)
+ prevRow[j] = curCol;
+ }
+
+ // copy last col value into previous (in preparation for next iteration)
+ prevRow[j] = nextCol;
+ }
+
+ return nextCol;
+ }
+
+ };
+
+ // amd
+ if (typeof define !== "undefined" && define !== null && define.amd) {
+ define(function() {
+ return Levenshtein;
+ });
+ }
+ // commonjs
+ else if (typeof module !== "undefined" && module !== null && typeof exports !== "undefined" && module.exports === exports) {
+ module.exports = Levenshtein;
+ }
+ // web worker
+ else if (typeof self !== "undefined" && typeof self.postMessage === 'function' && typeof self.importScripts === 'function') {
+ self.Levenshtein = Levenshtein;
+ }
+ // browser main thread
+ else if (typeof window !== "undefined" && window !== null) {
+ window.Levenshtein = Levenshtein;
+ }
+}());
+
diff --git a/levenshtein.min.js b/levenshtein.min.js
new file mode 100644
index 0000000..3d36404
--- /dev/null
+++ b/levenshtein.min.js
@@ -0,0 +1,2 @@
+/*! fast-levenshtein 2016-09-27. Copyright Ramesh Nair <ram at hiddentao.com> (http://www.hiddentao.com/) */
+!function(){"use strict";var a;try{a="undefined"!=typeof Intl&&"undefined"!=typeof Intl.Collator?Intl.Collator("generic",{sensitivity:"base"}):null}catch(b){console.log("Collator could not be initialized and wouldn't be used")}var c=[],d=[],e={get:function(b,e,f){var g=f&&a&&f.useCollator,h=b.length,i=e.length;if(0===h)return i;if(0===i)return h;var j,k,l,m,n;for(l=0;i>l;++l)c[l]=l,d[l]=e.charCodeAt(l);for(c[i]=i,l=0;h>l;++l){for(k=l+1,m=0;i>m;++m){j=k;var o=g?0===a.compare(b.charAt(l),S [...]
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..e8b99c0
--- /dev/null
+++ b/package.json
@@ -0,0 +1,39 @@
+{
+ "name": "fast-levenshtein",
+ "version": "2.0.5",
+ "description": "Efficient implementation of Levenshtein algorithm with locale-specific collator support.",
+ "main": "levenshtein.js",
+ "files": [
+ "levenshtein.js"
+ ],
+ "scripts": {
+ "build": "grunt build",
+ "prepublish": "npm run build",
+ "benchmark": "grunt benchmark",
+ "test": "mocha"
+ },
+ "devDependencies": {
+ "chai": "~1.5.0",
+ "grunt": "~0.4.1",
+ "grunt-benchmark": "~0.2.0",
+ "grunt-cli": "^1.2.0",
+ "grunt-contrib-jshint": "~0.4.3",
+ "grunt-contrib-uglify": "~0.2.0",
+ "grunt-mocha-test": "~0.2.2",
+ "grunt-npm-install": "~0.1.0",
+ "load-grunt-tasks": "~0.6.0",
+ "lodash": "^4.0.1",
+ "mocha": "~1.9.0"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/hiddentao/fast-levenshtein.git"
+ },
+ "keywords": [
+ "levenshtein",
+ "distance",
+ "string"
+ ],
+ "author": "Ramesh Nair <ram at hiddentao.com> (http://www.hiddentao.com/)",
+ "license": "MIT"
+}
diff --git a/test/mocha.opts b/test/mocha.opts
new file mode 100644
index 0000000..a8ccfb4
--- /dev/null
+++ b/test/mocha.opts
@@ -0,0 +1,2 @@
+--ui exports
+--reporter spec
diff --git a/test/tests.js b/test/tests.js
new file mode 100644
index 0000000..c11c4df
--- /dev/null
+++ b/test/tests.js
@@ -0,0 +1,127 @@
+var _ = require('lodash'),
+ chai = require('chai'),
+ fs = require('fs'),
+ levenshtein = require('../levenshtein.min');
+
+var expect = chai.expect,
+ assert = chai.assert;
+
+
+/**
+ * Create test functions.
+ * @return Object
+ */
+var createTests = function(str1, str2, expectedLength, options) {
+ options = _.extend({}, {
+ description: null
+ }, options);
+
+ if (!options.description) {
+ options.description = (0 === str1.length ? '(empty)' : str1) + ' <-> ' + (0 === str2.length ? '(empty)' : str2);
+ }
+
+ var ret = {};
+
+ ret[options.description + ' (len: ' + expectedLength + ')'] = function() {
+ expect(levenshtein.get(str1, str2, options)).to.eql(expectedLength);
+ };
+
+ return ret;
+};
+
+
+// ----- Basic tests ----- //
+
+(function() {
+
+ var tests = {},
+ str = 'hello',
+ str1 = str,
+ str2 = str,
+ i;
+
+ // equal strings
+ _.extend(tests, createTests('hello', 'hello', 0));
+
+ // inserts
+ for (i=0; i<=str.length; ++i) {
+ str1 = str.substr(0,i);
+ str2 = str;
+
+ _.extend(tests, createTests(str1, str2, str.length - i));
+ }
+
+ // deletes
+ for (i=str.length-1; i>=0; --i) {
+ str1 = str;
+ str2 = str.substr(0,i);
+
+ _.extend(tests, createTests(str1, str2, str.length - i));
+ }
+
+ // substitutions
+ _.extend(tests, createTests("a", "b", 1 ));
+ _.extend(tests, createTests("ab", "ac", 1 ));
+ _.extend(tests, createTests("ac", "bc", 1 ));
+ _.extend(tests, createTests("abc", "axc", 1 ));
+ _.extend(tests, createTests("xabxcdxxefxgx", "1ab2cd34ef5g6", 6 ));
+
+ // many ops
+ _.extend(tests, createTests('xabxcdxxefxgx', 'abcdefg', 6));
+ _.extend(tests, createTests('javawasneat', 'scalaisgreat', 7));
+ _.extend(tests, createTests("example", "samples", 3));
+ _.extend(tests, createTests("forward", "drawrof", 6));
+ _.extend(tests, createTests("sturgeon", "urgently", 6 ));
+ _.extend(tests, createTests("levenshtein", "frankenstein", 6 ));
+ _.extend(tests, createTests("distance", "difference", 5 ));
+ _.extend(tests, createTests("distance", "eistancd", 2 ));
+
+ // non-latin
+ _.extend(tests, createTests('你好世界', '你好', 2, {
+ description: 'non-latin'
+ }));
+ _.extend(tests, createTests('因為我是中國人所以我會說中文', '因為我是英國人所以我會說英文', 2, {
+ description: 'non-latin'
+ }));
+
+ // collation (see https://github.com/hiddentao/fast-levenshtein/issues/7)
+ _.extend(tests, createTests('mikailovitch', 'Mikhaïlovitch', 3, {
+ description: 'collator OFF'
+ }));
+ _.extend(tests, createTests('mikailovitch', 'Mikhaïlovitch', 1, {
+ useCollator: true,
+ description: 'collator ON'
+ }));
+
+ // long text
+ _.extend(tests, createTests(
+ 'Morbi interdum ultricies neque varius condimentum. Donec volutpat turpis interdum metus ultricies vulputate. Duis ultricies rhoncus sapien, sit amet fermentum risus imperdiet vitae. Ut et lectus',
+ 'Duis erat dolor, cursus in tincidunt a, lobortis in odio. Cras magna sem, pharetra et iaculis quis, faucibus quis tellus. Suspendisse dapibus sapien in justo cursus',
+ 143,
+ {
+ description: 'long text'
+ }
+ ));
+
+ exports['Basic'] = tests;
+})();
+
+// ------ Huge tests ----- //
+
+var text1 = fs.readFileSync(__dirname + '/text1.txt', 'utf-8'),
+ text2 = fs.readFileSync(__dirname + '/text2.txt', 'utf-8');
+
+exports['Huge'] = {
+ 'default': function() {
+ var startTime = new Date().valueOf();
+
+ var distance = levenshtein.get(text1, text2);
+
+ var timeElapsed = new Date().valueOf() - startTime;
+
+ console.log(timeElapsed + ' ms');
+
+ expect(distance).to.eql(194);
+ },
+};
+
diff --git a/test/text1.txt b/test/text1.txt
new file mode 100644
index 0000000..4833682
--- /dev/null
+++ b/test/text1.txt
@@ -0,0 +1 @@
+Duis mollis rhoncus turpis. Proin ut nunc eget urna molestie dictum. Cras mollis nibh quis eros faucibus posuere vehicula diam rutrum. Morbi mattis orci vel ante dignissim sollicitudin. Aenean quis enim orci. Integer vehicula elementum porta. Nullam massa mauris, ornare eget ullamcorper eget, consequat at dolor. Integer cursus pellentesque velit in semper. Donec sem turpis, tristique vitae egestas nec, varius sit amet ipsum. Nullam scelerisque est eu arcu vulputate varius. Integer vel gr [...]
\ No newline at end of file
diff --git a/test/text2.txt b/test/text2.txt
new file mode 100644
index 0000000..ca15f41
--- /dev/null
+++ b/test/text2.txt
@@ -0,0 +1 @@
+Duis mollis rhoncus turpis. Proin ut nunc eget urna molestie dictum. Cras mollis nibh quis eros faucibus posuere vehicula diam rutrum. Morbi mattis orci vel ante dignissim sollicitudin. Aenean quis enim orci. Integer vehicula elementum porta. Nullam massa mauris, ornare eget ullamcorper eget, consequat at dolor. Integer cursus pellentesque velit in semper. Donec sem turpis, tristique vitae egestas nec, varius sit amet ipsum. Nullam scelerisque est eu arcu vulputate varius. Integer vel gr [...]
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-fast-levenshtein.git
More information about the Pkg-javascript-commits
mailing list