Update Aho Corasick benchmark

This commit is contained in:
SukkaW
2024-11-21 21:48:33 +08:00
parent 6747357d35
commit 200da7a2be
2 changed files with 100 additions and 11 deletions

View File

@@ -1,17 +1,33 @@
import { describe, it } from 'mocha';
import { expect } from 'expect';
import createKeywordFilter from './aho-corasick';
import { getFns } from './aho-corasick.bench';
describe('AhoCorasick', () => {
it('basic', () => {
let kwfilter = createKeywordFilter(['ap', 'an']);
expect(kwfilter('bananan')).toBe(true);
expect(kwfilter('apple')).toBe(true);
expect(kwfilter('melon')).toBe(false);
for (const test of ([
[
['ap', 'an'],
['bananan', 'apple', 'melon'],
[true, true, false]
],
[
['cdn', 'sukka'],
['bananan', 'apple', 'melon'],
[false, false, false]
]
] as const)) {
const kwtests = getFns(test[0]);
const fixtures = test[1];
const expected = test[2];
kwfilter = createKeywordFilter(['cdn', 'sukka']);
expect(kwfilter('bananan')).toBe(false);
expect(kwfilter('apple')).toBe(false);
expect(kwfilter('melon')).toBe(false);
});
for (const kwtest of kwtests) {
const fnName = kwtest[0];
const fn = kwtest[1];
it(fnName, () => {
for (let i = 0, len = fixtures.length; i < len; i++) {
expect(fn(fixtures[i])).toBe(expected[i]);
}
});
}
}
});