utils test adapted to Uint8Array

This commit is contained in:
Wolfgang Hottgenroth 2017-08-10 13:11:43 +02:00
parent 098633af13
commit 83143ca8c2
3 changed files with 13 additions and 6 deletions

View File

@ -17,6 +17,10 @@ export namespace MeterbusLibLongFrame {
this._fixedDataHeader = new FixedDataHeader(this._telegram.slice(7, 19)) this._fixedDataHeader = new FixedDataHeader(this._telegram.slice(7, 19))
this._fixedDataHeader.parse() this._fixedDataHeader.parse()
} }
getJSON() : string {
return JSON.stringify(this)
}
} }
export class FixedDataHeader { export class FixedDataHeader {

View File

@ -179,6 +179,9 @@ describe('The Meterbus Library', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.signature) expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.signature)
.to.deep.equal(new Uint8Array([0,0])) .to.deep.equal(new Uint8Array([0,0]))
}) })
it('should print itself as json', () => {
console.log((telegram.frame as MeterbusLibLongFrame.LongFrame).getJSON())
})
}) })
}) })

View File

@ -8,21 +8,21 @@ const expect = chai.expect
describe('The Meterbus Library Utils', () => { describe('The Meterbus Library Utils', () => {
it('should convert a bcd to a number (10203)', () => { it('should convert a bcd to a number (10203)', () => {
expect(MeterbusLibUtils.bcd([1, 2, 3])).to.equal(10203) expect(MeterbusLibUtils.bcd(new Uint8Array([1, 2, 3]))).to.equal(10203)
}) })
it('should convert a bcd to a number (0010203)', () => { it('should convert a bcd to a number (0010203)', () => {
expect(MeterbusLibUtils.bcd([0, 1, 2, 3])).to.equal(10203) expect(MeterbusLibUtils.bcd(new Uint8Array([0, 1, 2, 3]))).to.equal(10203)
}) })
it('should convert a bcd to a number (0)', () => { it('should convert a bcd to a number (0)', () => {
expect(MeterbusLibUtils.bcd([0, 0, 0])).to.equal(0) expect(MeterbusLibUtils.bcd(new Uint8Array([0, 0, 0]))).to.equal(0)
}) })
it('should convert a bcd to a number (0)', () => { it('should convert a bcd to a number (0)', () => {
expect(MeterbusLibUtils.bcd([0, 0, 0, 0])).to.equal(0) expect(MeterbusLibUtils.bcd(new Uint8Array([0, 0, 0, 0]))).to.equal(0)
}) })
it('should convert a bcd to a number (99999999)', () => { it('should convert a bcd to a number (99999999)', () => {
expect(MeterbusLibUtils.bcd([0x99, 0x99, 0x99, 0x99])).to.equal(99999999) expect(MeterbusLibUtils.bcd(new Uint8Array([0x99, 0x99, 0x99, 0x99]))).to.equal(99999999)
}) })
it('should convert two number to manufacturer code', () => { it('should convert two number to manufacturer code', () => {
expect(MeterbusLibUtils.manufCode([0x2e, 0x19])).to.equal("FIN") expect(MeterbusLibUtils.manufCode(new Uint8Array([0x2e, 0x19]))).to.equal("FIN")
}) })
}) })