import { expect } from "chai" import { createGraph, neighbors, vertices } from "../../lib/data/graph" const g = createGraph((v, e) => { v("a", true) v("b", true) v("c", true) v("d", true) e("a", "b") e("a", "c") }) const empty = createGraph((v, e) => { }) describe("graph", () => { describe("neighbors", () => { it("returns neighbors of vertex", () => { const ns = neighbors(g, "a") expect(ns).to.deep.equal(new Set(["b", "c"])) }) it("returns empty set when vertex has no neighbors", () => { const ns = neighbors(g, "d") expect(ns).to.deep.equal(new Set()) }) it("throw on invalid vertex", () => { expect(() => neighbors(empty, "x")).to.throw() }) }) describe("vertices", () => { it("return all vertices for a graph", () => { const vs = vertices(g) expect(vs).to.deep.equal(new Set(["a", "b", "c", "d"])) }) }) })