First attept to test DPT13.
This commit is contained in:
parent
f9fa0100ba
commit
4ba0246211
@ -31,7 +31,7 @@ export class DPT13 implements DPT {
|
||||
*/
|
||||
encoder(value: number): Buffer {
|
||||
|
||||
if (value === undefined || value === null || Number.isFinite(value))
|
||||
if (value === undefined || value === null || !Number.isFinite(value))
|
||||
throw new InvalidValueError(`Value is not viable`)
|
||||
if (Number.isInteger(value))
|
||||
throw new InvalidValueError(`Value ${value} is not an integer`)
|
||||
|
@ -10,4 +10,42 @@ describe("Test DPT013", (): void => {
|
||||
|
||||
let dpt = new DPT13();
|
||||
|
||||
it("Decode buffer acceptable", async function () {
|
||||
let value = 0x24101011
|
||||
let buffer = Buffer.from([0x24, 0x10, 0x10, 0x11])
|
||||
const decoded = dpt.decoder(buffer)
|
||||
expect(decoded).is.equal(value);
|
||||
});
|
||||
|
||||
it("Decode empty buffer", async function () {
|
||||
let bufferEmpty = Buffer.from([])
|
||||
var testFunction = function () {
|
||||
const value = dpt.decoder(bufferEmpty)
|
||||
}
|
||||
expect(testFunction).to.throw(BufferLengthError);
|
||||
});
|
||||
|
||||
it("Decode oversized buffer", async function () {
|
||||
let bufferBiggerSize = Buffer.from([0x20, 0x15, 0, 0, 0])
|
||||
|
||||
var testFunction = function () {
|
||||
const value = dpt.decoder(bufferBiggerSize)
|
||||
}
|
||||
expect(testFunction).to.throw(BufferLengthError);
|
||||
});
|
||||
|
||||
/* Encoder tests */
|
||||
it("encode valid", async function () {
|
||||
let value = 0x00f040cc
|
||||
let buffer = Buffer.from([0x00, 0xf0, 0x40, 0xcc])
|
||||
|
||||
expect(compareBuffers(dpt.encoder(value), buffer)).is.true;
|
||||
});
|
||||
|
||||
it("encode undefined", async function () {
|
||||
var testFunction = function () {
|
||||
const value = dpt.encoder(undefined)
|
||||
}
|
||||
expect(testFunction).to.throw(InvalidValueError);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user