Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
942B

  1. const expect = require('chai').expect;
  2. const BCD = require('../src/utils/bcd.js');
  3. describe("BCD Utils Tests...", function(){
  4. it(".isValid()", function(){
  5. expect(BCD.isValid(0x01, 2)).to.be.true;
  6. expect(BCD.isValid(0x78, 2)).to.be.true;
  7. expect(BCD.isValid(0xF4, 2)).to.be.false;
  8. expect(BCD.isValid(0xF4, 1)).to.be.true;
  9. });
  10. it(".int2BCD()");
  11. it(".BCD2Int()", function(){
  12. expect(BCD.BCD2Int(0x10, 2)).to.equal(10);
  13. expect(BCD.BCD2Int(0x15, 1)).to.equal(5);
  14. expect(BCD.BCD2Int(0x144, 3)).to.equal(144);
  15. expect(BCD.BCD2Int(0x144, 2)).to.equal(44);
  16. expect(BCD.BCD2Int(0x12, 3)).to.equal(12);
  17. });
  18. it(".add()", function(){
  19. expect(BCD.add(0x05, 0x11, 2)).to.equal(0x16);
  20. expect(BCD.add(0x5, 0x11, 2)).to.equal(0x16);
  21. expect(BCD.add(0x111, 0x12, 3)).to.equal(0x123);
  22. expect(BCD.add(0x90, 0x11, 3)).to.equal(0x101);
  23. expect(BCD.add(0x90, 0x11, 2)).to.equal(0x01);
  24. });
  25. });