aboutsummaryrefslogtreecommitdiff
path: root/test/content/usecases/HintKeyProducer.test.ts
blob: a4ad4dea2e93ee91812dad6ca16e773ca46d107f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { HintKeyRepositoryImpl } from "../../../src/content/repositories/HintKeyRepository";

describe("HintKeyProducerImpl class", () => {
  describe("#produce", () => {
    it("produce incremented keys", () => {
      const charset = "abc";
      const sequences = [
        "a",
        "b",
        "c",
        "aa",
        "ab",
        "ac",
        "ba",
        "bb",
        "bc",
        "ca",
        "cb",
        "cc",
        "aaa",
        "aab",
        "aac",
        "aba",
      ];

      const sut = new HintKeyRepositoryImpl();
      sut.reset(charset);
      for (let i = 0; i < sequences.length; ++i) {
        expect(sut.produce()).toEqual(sequences[i]);
      }
    });
  });

  describe("#reset", () => {
    it("resets charset", () => {
      const sut = new HintKeyRepositoryImpl();

      sut.reset("ab");
      expect(sut.produce()).toEqual("a");
      expect(sut.produce()).toEqual("b");

      sut.reset("xy");
      expect(sut.produce()).toEqual("x");
      expect(sut.produce()).toEqual("y");
    });
    it("throws an exception on empty charset", () => {
      const sut = new HintKeyRepositoryImpl();
      expect(() => sut.reset("")).toThrow(TypeError);
    });
  });
});