UNPKG

1.54 kBJavaScriptView Raw
1import { expect } from 'chai';
2
3import gestureLevenshtein from '../gestureLevenshtein';
4import moves from '../gestureMoves';
5
6
7const UPCARET = [ moves.UPRIGHT, moves.DOWNRIGHT ];
8const CIRCLE = [
9 moves.RIGHT,
10 moves.DOWNRIGHT,
11 moves.DOWN,
12 moves.DOWNLEFT,
13 moves.LEFT,
14 moves.UPLEFT,
15 moves.UP,
16 moves.UPRIGHT,
17 moves.RIGHT,
18];
19
20
21describe("gestureLevenshtein", () => {
22 it("should return a big number when an argument is an empty string", () => {
23 expect(gestureLevenshtein("", "1")).to.equal(10000);
24 expect(gestureLevenshtein("1", "")).to.equal(10000);
25 });
26
27 it("should return 0 when the arguments match", () => {
28 expect(gestureLevenshtein(UPCARET, UPCARET)).to.equal(0);
29 expect(gestureLevenshtein(CIRCLE, CIRCLE)).to.equal(0);
30 });
31
32 it("should return 0 when the arguments 'collapse' to be equal", () => {
33 // Collapse here meaning if we were to manually remove consecutive
34 // duplicates, the below value would collapse into "71".
35 const humanUpCaret = "777777771111111";
36 expect(gestureLevenshtein(UPCARET, humanUpCaret)).to.equal(0);
37
38 const humanCircle = "0111122222233445555666700000";
39 expect(gestureLevenshtein(CIRCLE, humanCircle)).to.equal(0);
40 });
41
42 it("should return correct values when arguments don't match", () => {
43 const humanUpCaret = "77777777001111111";
44 expect(gestureLevenshtein(UPCARET, humanUpCaret)).to.equal(2);
45
46 const humanCircle = "0001121112222122233344445555665666777770";
47 expect(gestureLevenshtein(CIRCLE, humanCircle)).to.equal(3);
48 });
49});