import { expect } from "chai"; import { DPT5 } from "../src/DPT5" import { BufferLengthError } from "../src/errors/BufferLengthError"; import { InvalidValueError } from "../src/errors/InvalidValueError"; import { compareBuffers } from "./util" let bufferA = Buffer.from([65]) let bufferMax = Buffer.from([254]) let bufferEmpty = Buffer.from([]) let bufferBiggerSize = Buffer.from([1, 0]) describe("Test DPT005", (): void => { let dpt = new DPT5(); it("Decode buffer common", async function () { const value = dpt.decoder(bufferA) expect(value).is.equal(65); }); it("Decode buffer max", async function () { const value = dpt.decoder(bufferMax) expect(value).is.equal(254); }); it("Decode empty buffer", async function () { var testFunction = function () { const value = dpt.decoder(bufferEmpty) } expect(testFunction).to.throw(BufferLengthError); }); it("Decode oversized buffer", async function () { var testFunction = function () { const value = dpt.decoder(bufferBiggerSize) } expect(testFunction).to.throw(BufferLengthError); }); /* Encoder tests */ it("encode valid", async function () { expect(compareBuffers(dpt.encoder(65), bufferA)).is.true; expect(compareBuffers(dpt.encoder(254), bufferMax)).is.true; }); it("encode undefined", async function () { var testFunction = function () { const value = dpt.encoder(undefined) } expect(testFunction).to.throw(InvalidValueError); }); });