| module.exports = { | |||||
| BCD: require('./bcd.js'), | |||||
| Bitman: require('./bitman.js') | |||||
| }; | |||||
| const expect = require('chai').expect; | const expect = require('chai').expect; | ||||
| const sinon = require('sinon'); | const sinon = require('sinon'); | ||||
| const Clock = require('../src/common/clock.js'); | |||||
| const Clock = require('../src/clock.js'); | |||||
| describe("Clock Tests", function(){ | describe("Clock Tests", function(){ | ||||
| var count = 0; | var count = 0; |
| 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); | |||||
| }); | |||||
| }); | |||||
| const BIT = require('../src/utils/bitman.js'); | |||||
| const expect = require('chai').expect; | |||||
| describe("Testing utils/bitman ...", function(){ | |||||
| it(".isOn() 'true' test", function(){ | |||||
| expect(BIT.isOn(parseInt("0010", 2), 1)).be.true; | |||||
| }); | |||||
| it(".isOn() 'false' test", function(){ | |||||
| expect(BIT.isOn(parseInt('0111', 2), 3)).be.false; | |||||
| }); | |||||
| it(".set()", function(){ | |||||
| let num = 1; | |||||
| num = BIT.set(num, 1); | |||||
| expect(num).to.equal(3); | |||||
| }); | |||||
| it(".clear()", function(){ | |||||
| let num = 15; | |||||
| num = BIT.clear(num, 2); | |||||
| expect(num).to.equal(11); | |||||
| }); | |||||
| it(".toggle()", function(){ | |||||
| let num = 9; | |||||
| num = BIT.toggle(num, 3); | |||||
| num = BIT.toggle(num, 2); | |||||
| expect(num).to.equal(5); | |||||
| }); | |||||
| }); |
| const expect = require('chai').expect; | |||||
| const utils = require('../src/utils'); | |||||
| const BCD = utils.BCD; | |||||
| const BIT = utils.Bitman; | |||||
| describe("Utils Tests...", function(){ | |||||
| describe("BCD 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); | |||||
| }); | |||||
| }); | |||||
| describe("Bitman Tests...", function(){ | |||||
| it(".isOn() 'true' test", function(){ | |||||
| expect(BIT.isOn(parseInt("0010", 2), 1)).be.true; | |||||
| }); | |||||
| it(".isOn() 'false' test", function(){ | |||||
| expect(BIT.isOn(parseInt('0111', 2), 3)).be.false; | |||||
| }); | |||||
| it(".set()", function(){ | |||||
| let num = 1; | |||||
| num = BIT.set(num, 1); | |||||
| expect(num).to.equal(3); | |||||
| }); | |||||
| it(".clear()", function(){ | |||||
| let num = 15; | |||||
| num = BIT.clear(num, 2); | |||||
| expect(num).to.equal(11); | |||||
| }); | |||||
| it(".toggle()", function(){ | |||||
| let num = 9; | |||||
| num = BIT.toggle(num, 3); | |||||
| num = BIT.toggle(num, 2); | |||||
| expect(num).to.equal(5); | |||||
| }); | |||||
| }); | |||||
| }); |