|
1 |
| -import { test } from "node:test"; |
| 1 | +import { describe, it, test } from "node:test"; |
2 | 2 | import { Layout } from "@keybr/keyboard";
|
3 | 3 | import { Histogram } from "@keybr/textinput";
|
4 | 4 | import { assert } from "chai";
|
5 | 5 | import { Result, speedToTime, timeToSpeed } from "./result.ts";
|
6 | 6 | import { TextType } from "./texttype.ts";
|
7 | 7 |
|
8 |
| -test("validate", () => { |
9 |
| - assert.isFalse( |
10 |
| - new Result( |
11 |
| - /* layout= */ Layout.EN_US, |
12 |
| - /* textType= */ TextType.GENERATED, |
13 |
| - /* timeStamp= */ Date.parse("2001-02-03T03:05:06Z"), |
14 |
| - /* length= */ 9, |
15 |
| - /* time= */ 999, |
16 |
| - /* errors= */ 0, |
17 |
| - /* histogram= */ new Histogram([]), |
18 |
| - ).validate(), |
| 8 | +describe("validate", () => { |
| 9 | + const result = new Result( |
| 10 | + /* layout= */ Layout.EN_US, |
| 11 | + /* textType= */ TextType.GENERATED, |
| 12 | + /* timeStamp= */ Date.parse("2001-02-03T03:05:06Z"), |
| 13 | + /* length= */ 10, |
| 14 | + /* time= */ 1000, |
| 15 | + /* errors= */ 0, |
| 16 | + /* histogram= */ new Histogram([ |
| 17 | + { codePoint: 0x0061, hitCount: 11, missCount: 1, timeToType: 111 }, |
| 18 | + { codePoint: 0x0062, hitCount: 22, missCount: 2, timeToType: 222 }, |
| 19 | + { codePoint: 0x0063, hitCount: 33, missCount: 3, timeToType: 333 }, |
| 20 | + ]), |
19 | 21 | );
|
20 | 22 |
|
21 |
| - assert.isFalse( |
22 |
| - new Result( |
23 |
| - /* layout= */ Layout.EN_US, |
24 |
| - /* textType= */ TextType.GENERATED, |
25 |
| - /* timeStamp= */ Date.parse("2001-02-03T03:05:06Z"), |
26 |
| - /* length= */ 9, |
27 |
| - /* time= */ 999, |
28 |
| - /* errors= */ 0, |
29 |
| - /* histogram= */ new Histogram([ |
30 |
| - { codePoint: 0x0061, hitCount: 11, missCount: 1, timeToType: 111 }, |
31 |
| - { codePoint: 0x0062, hitCount: 22, missCount: 2, timeToType: 222 }, |
32 |
| - { codePoint: 0x0063, hitCount: 33, missCount: 3, timeToType: 333 }, |
33 |
| - ]), |
34 |
| - ).validate(), |
35 |
| - ); |
| 23 | + describe("using the default filter", () => { |
| 24 | + it("should accept a valid result", () => { |
| 25 | + assert.isTrue(result.validate()); |
| 26 | + assert.isTrue(result.validate({})); |
| 27 | + assert.isTrue(result.validate(Result.filter)); |
| 28 | + }); |
36 | 29 |
|
37 |
| - assert.isTrue( |
38 |
| - new Result( |
39 |
| - /* layout= */ Layout.EN_US, |
40 |
| - /* textType= */ TextType.GENERATED, |
41 |
| - /* timeStamp= */ Date.parse("2001-02-03T03:05:06Z"), |
42 |
| - /* length= */ 10, |
43 |
| - /* time= */ 1000, |
44 |
| - /* errors= */ 0, |
45 |
| - /* histogram= */ new Histogram([ |
46 |
| - { codePoint: 0x0061, hitCount: 11, missCount: 1, timeToType: 111 }, |
47 |
| - { codePoint: 0x0062, hitCount: 22, missCount: 2, timeToType: 222 }, |
48 |
| - { codePoint: 0x0063, hitCount: 33, missCount: 3, timeToType: 333 }, |
49 |
| - ]), |
50 |
| - ).validate(), |
51 |
| - ); |
| 30 | + it("should reject if the length is too short", () => { |
| 31 | + assert.isFalse( |
| 32 | + new Result( |
| 33 | + /* layout= */ result.layout, |
| 34 | + /* textType= */ result.textType, |
| 35 | + /* timeStamp= */ result.timeStamp, |
| 36 | + /* length= */ 9, |
| 37 | + /* time= */ result.time, |
| 38 | + /* errors= */ result.errors, |
| 39 | + /* histogram= */ result.histogram, |
| 40 | + ).validate(), |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should reject if the time is too short", () => { |
| 45 | + assert.isFalse( |
| 46 | + new Result( |
| 47 | + /* layout= */ result.layout, |
| 48 | + /* textType= */ result.textType, |
| 49 | + /* timeStamp= */ result.timeStamp, |
| 50 | + /* length= */ result.length, |
| 51 | + /* time= */ 999, |
| 52 | + /* errors= */ result.errors, |
| 53 | + /* histogram= */ result.histogram, |
| 54 | + ).validate(), |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + it("should reject if the complexity is too small", () => { |
| 59 | + assert.isFalse( |
| 60 | + new Result( |
| 61 | + /* layout= */ result.layout, |
| 62 | + /* textType= */ result.textType, |
| 63 | + /* timeStamp= */ result.timeStamp, |
| 64 | + /* length= */ result.length, |
| 65 | + /* time= */ result.time, |
| 66 | + /* errors= */ result.errors, |
| 67 | + /* histogram= */ new Histogram([]), |
| 68 | + ).validate(), |
| 69 | + ); |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + describe("using a custom filter", () => { |
| 74 | + it("should reject if the length is too short", () => { |
| 75 | + assert.isFalse(result.validate({ minLength: 100 })); |
| 76 | + }); |
| 77 | + |
| 78 | + it("should reject if the time is too short", () => { |
| 79 | + assert.isFalse(result.validate({ minTime: 60000 })); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should reject if the complexity is too small", () => { |
| 83 | + assert.isFalse(result.validate({ minComplexity: 10 })); |
| 84 | + }); |
| 85 | + |
| 86 | + it("should reject if the speed is too slow", () => { |
| 87 | + assert.isFalse(result.validate({ minSpeed: 1000 })); |
| 88 | + }); |
| 89 | + |
| 90 | + it("should reject if the speed is too fast", () => { |
| 91 | + assert.isFalse(result.validate({ maxSpeed: 1 })); |
| 92 | + }); |
| 93 | + }); |
52 | 94 | });
|
53 | 95 |
|
54 | 96 | test("serialize as JSON", () => {
|
|
0 commit comments