mirror of
https://github.com/SukkaW/Surge.git
synced 2026-02-04 04:42:32 +08:00
Update Aho Corasick benchmark
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user