UNPKG

@a-s8h/liblevenshtein

Version:

Various utilities regarding Levenshtein transducers.

179 lines (176 loc) 4.14 kB
{levenshtein: {permutations}} = require '../../src/util/permutations' module.exports = 'There should be no permutations on an empty list': (test) -> test.deepEqual(permutations([]), []) test.done() 'The only permutation on a singleton list should be the same list': (test) -> test.deepEqual(permutations([1]), [[1]]) test.done() 'There should be 2-factorial, distinct permutations on a pair': (test) -> test.deepEqual(permutations([1,2]),[ [1,2] [2,1] ]) test.done() 'There should be 3-factorial, distinct permutations on a triple': (test) -> test.deepEqual(permutations([1..3]), [ [1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2] ]) test.done() 'There should be 4-factorial, distinct permutations on a quadruple': (test) -> test.deepEqual(permutations([1..4]), [ [1, 2, 3, 4] [1, 2, 4, 3] [1, 3, 2, 4] [1, 3, 4, 2] [1, 4, 3, 2] [1, 4, 2, 3] [2, 1, 3, 4] [2, 1, 4, 3] [2, 3, 1, 4] [2, 3, 4, 1] [2, 4, 3, 1] [2, 4, 1, 3] [3, 2, 1, 4] [3, 2, 4, 1] [3, 1, 2, 4] [3, 1, 4, 2] [3, 4, 1, 2] [3, 4, 2, 1] [4, 2, 3, 1] [4, 2, 1, 3] [4, 3, 2, 1] [4, 3, 1, 2] [4, 1, 3, 2] [4, 1, 2, 3] ]) test.done() 'There should be 5-factorial, distinct permutations on a 5-tuple': (test) -> test.deepEqual(permutations([1..5]), [ [1, 2, 3, 4, 5] [1, 2, 3, 5, 4] [1, 2, 4, 3, 5] [1, 2, 4, 5, 3] [1, 2, 5, 4, 3] [1, 2, 5, 3, 4] [1, 3, 2, 4, 5] [1, 3, 2, 5, 4] [1, 3, 4, 2, 5] [1, 3, 4, 5, 2] [1, 3, 5, 4, 2] [1, 3, 5, 2, 4] [1, 4, 3, 2, 5] [1, 4, 3, 5, 2] [1, 4, 2, 3, 5] [1, 4, 2, 5, 3] [1, 4, 5, 2, 3] [1, 4, 5, 3, 2] [1, 5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