import { Trie } from "./trie";

describe("Trie", () => {
  it("adds words from instantiation", () => {
    const trie = new Trie(["AAA_BBB_CCC"]);
    const { children: { AAA: root } } = trie.getRoot();

    expect(root.data).toBe("AAA");
    expect(root.children["BBB"].data).toBe("BBB");
    expect(root.children["BBB"].isComplete).toBe(false);
    expect(root.children["BBB"].children["CCC"].data).toBe("CCC");
    expect(root.children["BBB"].children["CCC"].isComplete).toBe(true);
  });

  it("adds words with add method", () => {
    const trie = new Trie();
    trie.add("AAA_BBB_CCC");
    const { children: { AAA: root } } = trie.getRoot();

    expect(root.data).toBe("AAA");
    expect(root.children["BBB"].data).toBe("BBB");
    expect(root.children["BBB"].children["CCC"].data).toBe("CCC");
  });
});
