Coverage > 90%
This commit is contained in:
parent
df8c52f112
commit
d5086d8293
@ -10,4 +10,46 @@ describe("Test DPT014", (): void => {
|
||||
|
||||
let dpt = new DPT14();
|
||||
|
||||
it("Decode buffer acceptable", async function () {
|
||||
let value = 3.123863134302025e-17
|
||||
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([75, 112, 64, 204])
|
||||
|
||||
expect(compareBuffers(dpt.encoder(value), buffer)).is.true;
|
||||
});
|
||||
|
||||
it("encode undefined", async function () {
|
||||
var testFunctionUndefined = function () {
|
||||
const value = dpt.encoder(undefined)
|
||||
}
|
||||
var testFunctionNull = function () {
|
||||
const value = dpt.encoder(null)
|
||||
}
|
||||
expect(testFunctionNull).to.throw(InvalidValueError);
|
||||
expect(testFunctionUndefined).to.throw(InvalidValueError);
|
||||
});
|
||||
});
|
@ -72,6 +72,37 @@ describe("Test DPT019", (): void => {
|
||||
expect(decoded.reliability).is.equal(value.reliability);
|
||||
});
|
||||
|
||||
it("Decode buffer DayOfWeek == 0", async function () {
|
||||
let value: DPT19Result = {
|
||||
dateTime: new Date(2021, 8, 27, 10, 11, 19, 0),
|
||||
dayOfWeek: 3,
|
||||
f: false,
|
||||
wd: false,
|
||||
nwd: false,
|
||||
ny: false,
|
||||
nd: false,
|
||||
ndow: false,
|
||||
nt: false,
|
||||
sst: false,
|
||||
internalClock: false,
|
||||
reliability: false
|
||||
}
|
||||
let buffer = Buffer.from([121, 9, 27, 10 + (3 << 5), 11, 19, 0, 0])
|
||||
const decoded = dpt.decoder(buffer)
|
||||
expect(decoded.dateTime.valueOf()).is.equal(value.dateTime.valueOf());
|
||||
expect(decoded.dayOfWeek).is.equal(value.dayOfWeek);
|
||||
expect(decoded.f).is.equal(value.f);
|
||||
expect(decoded.wd).is.equal(value.wd);
|
||||
expect(decoded.nwd).is.equal(value.nwd);
|
||||
expect(decoded.ny).is.equal(value.ny);
|
||||
expect(decoded.nd).is.equal(value.nd);
|
||||
expect(decoded.ndow).is.equal(value.ndow);
|
||||
expect(decoded.nt).is.equal(value.nt);
|
||||
expect(decoded.sst).is.equal(value.sst);
|
||||
expect(decoded.internalClock).is.equal(value.internalClock);
|
||||
expect(decoded.reliability).is.equal(value.reliability);
|
||||
});
|
||||
|
||||
it("Decode empty buffer", async function () {
|
||||
let bufferEmpty = Buffer.from([])
|
||||
var testFunction = function () {
|
||||
@ -135,6 +166,24 @@ describe("Test DPT019", (): void => {
|
||||
let buffer = Buffer.from([21, 11, 22, 234, 11, 19, 0, 0])
|
||||
|
||||
expect(compareBuffers(dpt.encoder(value), buffer)).is.true;
|
||||
|
||||
value = {
|
||||
dateTime: new Date(1921, 10, 22, 10, 11, 19, 0),
|
||||
dayOfWeek: 0,
|
||||
f: false,
|
||||
wd: false,
|
||||
nwd: false,
|
||||
ny: false,
|
||||
nd: false,
|
||||
ndow: false,
|
||||
nt: false,
|
||||
sst: false,
|
||||
internalClock: false,
|
||||
reliability: false
|
||||
}
|
||||
buffer = Buffer.from([21, 11, 22, 234, 11, 19, 0, 0])
|
||||
|
||||
expect(compareBuffers(dpt.encoder(value), buffer)).is.true;
|
||||
});
|
||||
|
||||
it("encode from Date", async function () {
|
||||
|
@ -29,6 +29,25 @@ describe("Test DPT237", (): void => {
|
||||
expect(decoded.convertorError).is.equal(value.convertorError);
|
||||
});
|
||||
|
||||
it("Decode buffer acceptable true", async function () {
|
||||
let value: DPT237Result = {
|
||||
readResponse: true,
|
||||
addressIndicator: true,
|
||||
daliAddress: 63,
|
||||
lampFailure: true,
|
||||
ballastFailure: true,
|
||||
convertorError: true
|
||||
}
|
||||
let buffer = Buffer.from([0xff, 0xff])
|
||||
const decoded = dpt.decoder(buffer)
|
||||
expect(decoded.readResponse).is.equal(value.readResponse);
|
||||
expect(decoded.addressIndicator).is.equal(value.addressIndicator);
|
||||
expect(decoded.daliAddress).is.equal(value.daliAddress);
|
||||
expect(decoded.lampFailure).is.equal(value.lampFailure);
|
||||
expect(decoded.ballastFailure).is.equal(value.ballastFailure);
|
||||
expect(decoded.convertorError).is.equal(value.convertorError);
|
||||
});
|
||||
|
||||
it("Decode empty buffer", async function () {
|
||||
let bufferEmpty = Buffer.from([])
|
||||
var testFunction = function () {
|
||||
@ -61,6 +80,20 @@ describe("Test DPT237", (): void => {
|
||||
expect(compareBuffers(dpt.encoder(value), buffer)).is.true;
|
||||
});
|
||||
|
||||
it("encode valid complement flags", async function () {
|
||||
let value: DPT237Result = {
|
||||
readResponse: false,
|
||||
addressIndicator: true,
|
||||
daliAddress: 31,
|
||||
lampFailure: true,
|
||||
ballastFailure: true,
|
||||
convertorError: false
|
||||
}
|
||||
let buffer = Buffer.from([0x03, 0x5f])
|
||||
|
||||
expect(compareBuffers(dpt.encoder(value), buffer)).is.true;
|
||||
});
|
||||
|
||||
it("encode undefined", async function () {
|
||||
var testFunction = function () {
|
||||
const value = dpt.encoder(undefined)
|
||||
@ -69,17 +102,30 @@ describe("Test DPT237", (): void => {
|
||||
});
|
||||
|
||||
it("encode invalid value", async function () {
|
||||
let value: DPT237Result = {
|
||||
readResponse: true,
|
||||
addressIndicator: false,
|
||||
daliAddress: 64,
|
||||
lampFailure: false,
|
||||
ballastFailure: false,
|
||||
convertorError: false
|
||||
}
|
||||
var testFunction = function () {
|
||||
var testFunctionUpperLimit = function () {
|
||||
const value: DPT237Result = {
|
||||
readResponse: true,
|
||||
addressIndicator: false,
|
||||
daliAddress: 64,
|
||||
lampFailure: false,
|
||||
ballastFailure: false,
|
||||
convertorError: false
|
||||
}
|
||||
const result = dpt.encoder(value)
|
||||
}
|
||||
expect(testFunction).to.throw(InvalidValueError);
|
||||
expect(testFunctionUpperLimit).to.throw(InvalidValueError);
|
||||
|
||||
var testFunctionLowerLimit = function () {
|
||||
const value: DPT237Result = {
|
||||
readResponse: true,
|
||||
addressIndicator: false,
|
||||
daliAddress: -1,
|
||||
lampFailure: false,
|
||||
ballastFailure: false,
|
||||
convertorError: false
|
||||
}
|
||||
const result = dpt.encoder(value)
|
||||
}
|
||||
expect(testFunctionLowerLimit).to.throw(InvalidValueError);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user