|
|
@@ -0,0 +1,35 @@ |
|
|
|
const expect = require('chai').expect; |
|
|
|
const BCD = require('../src/utils/bcd.js'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe("BCD Utils Tests...", function(){ |
|
|
|
it(".isValid()", function(){ |
|
|
|
expect(BCD.isValid(0x01, 2)).to.be.true; |
|
|
|
expect(BCD.isValid(0x78, 2)).to.be.true; |
|
|
|
expect(BCD.isValid(0xF4, 2)).to.be.false; |
|
|
|
expect(BCD.isValid(0xF4, 1)).to.be.true; |
|
|
|
}); |
|
|
|
|
|
|
|
it(".int2BCD()"); |
|
|
|
|
|
|
|
it(".BCD2Int()", function(){ |
|
|
|
expect(BCD.BCD2Int(0x10, 2)).to.equal(10); |
|
|
|
expect(BCD.BCD2Int(0x15, 1)).to.equal(5); |
|
|
|
expect(BCD.BCD2Int(0x144, 3)).to.equal(144); |
|
|
|
expect(BCD.BCD2Int(0x144, 2)).to.equal(44); |
|
|
|
expect(BCD.BCD2Int(0x12, 3)).to.equal(12); |
|
|
|
}); |
|
|
|
|
|
|
|
it(".add()", function(){ |
|
|
|
expect(BCD.add(0x05, 0x11, 2)).to.equal(0x16); |
|
|
|
expect(BCD.add(0x5, 0x11, 2)).to.equal(0x16); |
|
|
|
expect(BCD.add(0x111, 0x12, 3)).to.equal(0x123); |
|
|
|
expect(BCD.add(0x90, 0x11, 3)).to.equal(0x101); |
|
|
|
expect(BCD.add(0x90, 0x11, 2)).to.equal(0x01); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|