PHP Classes

File: test/js/test-fuzzy-nfa.js

Recommend this page to a friend!
  Packages of Nikos M.   Matchy   test/js/test-fuzzy-nfa.js   Download  
File: test/js/test-fuzzy-nfa.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Matchy
Perform exact or fuzzy searches in text strings
Author: By
Last change: v.4.0.0, almost complete

* php avoid strict equality potential failures
* update more tests
Date: 5 months ago
Size: 2,562 bytes
 

Contents

Class file image Download
"use strict"; const Matchy = require('../../src/js/Matchy.js'); const echo = console.log; function NFA(input, type = 'l') { return new Matchy.NFA(input, type); } function create_string(alphabet, n) { let s = ''; for (let i=0; i<n; ++i) { s += alphabet[Math.round(Math.random()*(alphabet.length-1))]; } return s; } function test_case(nfa, pattern, string, match, errors) { const found = nfa.match(string, 0, false, true); echo('fuzzynfa("'+pattern+'", "'+string+'") = '+found['match']+', errors '+found['errors']+' (expected '+match+', errors '+errors+')'); } function test() { let test; test = {pattern:'^(a+)(b+)$', nfa:NFA(NFA([NFA('', '^'), NFA(NFA('a'), '+'), NFA(NFA('b'), '+'), NFA('', '$')], ','), {total_errors:2,word_level:false})}; test_case(test.nfa, test.pattern, "aaabbbbb", 0, 0); // 0 errors test_case(test.nfa, test.pattern, "ababbbbb", 0, 1); // 1 errors test_case(test.nfa, test.pattern, "abababbb", 0, 2); // 2 errors test_case(test.nfa, test.pattern, "abababab", -1, 3); // 3 errors test_case(test.nfa, test.pattern, "aabababbbb", 0, 2); // 2 errors test_case(test.nfa, test.pattern, "baabaaabbb", 0, 2); // 2 errors echo(); test = {pattern:'(aaa)(bbb)', nfa:NFA(NFA([NFA('aaa'), NFA('bbb')], ','), {total_errors:1,word_level:true})}; test_case(test.nfa, test.pattern, "aaabbb", 0, 0); // 0 errors test_case(test.nfa, test.pattern, "bbbaaa", 0, 1); // 1 errors, deletion test_case(test.nfa, test.pattern, "bbb", 0, 1); // 1 errors, deletion test_case(test.nfa, test.pattern, "cbbb", 0, 1); // 1 errors, deletion or substitution test_case(test.nfa, test.pattern, "aacbbb", 0, 1); // 1 errors, deletion or substitution test_case(test.nfa, test.pattern, "aaacbbb", 0, 1); // 1 errors, insertion echo(); test = {pattern:'^(aaa)(bbb)$', nfa:NFA(NFA([NFA('', '^'), NFA('aaa'), NFA('bbb'), NFA('', '$')], ','), {total_errors:1,word_level:true,transpositions:true})}; test_case(test.nfa, test.pattern, "aaabbb", 0, 0); // 0 errors test_case(test.nfa, test.pattern, "bbbaaa", 0, 1); // 1 errors, transposition test_case(test.nfa, test.pattern, "bbb", 0, 1); // 1 errors, deletion test_case(test.nfa, test.pattern, "cbbb", 0, 1); // 1 errors, substitution test_case(test.nfa, test.pattern, "aacbbb", 0, 1); // 1 errors, substitution test_case(test.nfa, test.pattern, "aaacbbb", 0, 1); // 1 errors, insertion test_case(test.nfa, test.pattern, "cccbbb", 0, 1); // 1 errors, substitution echo(); } test();