aho-corasick.test.ts 759 B

123456789101112131415161718192021222324252627282930313233
  1. import { describe, it } from 'mocha';
  2. import { expect } from 'expect';
  3. import { getFns } from './aho-corasick.bench';
  4. describe('AhoCorasick', () => {
  5. for (const test of ([
  6. [
  7. ['ap', 'an'],
  8. ['bananan', 'apple', 'melon'],
  9. [true, true, false]
  10. ],
  11. [
  12. ['cdn', 'sukka'],
  13. ['bananan', 'apple', 'melon'],
  14. [false, false, false]
  15. ]
  16. ] as const)) {
  17. const kwtests = getFns(test[0]);
  18. const fixtures = test[1];
  19. const expected = test[2];
  20. for (const kwtest of kwtests) {
  21. const fnName = kwtest[0];
  22. const fn = kwtest[1];
  23. it(fnName, () => {
  24. for (let i = 0, len = fixtures.length; i < len; i++) {
  25. expect(fn(fixtures[i])).toBe(expected[i]);
  26. }
  27. });
  28. }
  29. }
  30. });