Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

65 lines
1.7KB

  1. const expect = require('chai').expect;
  2. const utils = require('../src/utils');
  3. const BCD = utils.BCD;
  4. const BIT = utils.Bitman;
  5. describe("Utils Tests...", function(){
  6. describe("BCD Tests...", function(){
  7. it(".isValid()", function(){
  8. expect(BCD.isValid(0x01, 2)).to.be.true;
  9. expect(BCD.isValid(0x78, 2)).to.be.true;
  10. expect(BCD.isValid(0xF4, 2)).to.be.false;
  11. expect(BCD.isValid(0xF4, 1)).to.be.true;
  12. });
  13. it(".int2BCD()");
  14. it(".BCD2Int()", function(){
  15. expect(BCD.BCD2Int(0x10, 2)).to.equal(10);
  16. expect(BCD.BCD2Int(0x15, 1)).to.equal(5);
  17. expect(BCD.BCD2Int(0x144, 3)).to.equal(144);
  18. expect(BCD.BCD2Int(0x144, 2)).to.equal(44);
  19. expect(BCD.BCD2Int(0x12, 3)).to.equal(12);
  20. });
  21. it(".add()", function(){
  22. expect(BCD.add(0x05, 0x11, 2)).to.equal(0x16);
  23. expect(BCD.add(0x5, 0x11, 2)).to.equal(0x16);
  24. expect(BCD.add(0x111, 0x12, 3)).to.equal(0x123);
  25. expect(BCD.add(0x90, 0x11, 3)).to.equal(0x101);
  26. expect(BCD.add(0x90, 0x11, 2)).to.equal(0x01);
  27. });
  28. });
  29. describe("Bitman Tests...", function(){
  30. it(".isOn() 'true' test", function(){
  31. expect(BIT.isOn(parseInt("0010", 2), 1)).be.true;
  32. });
  33. it(".isOn() 'false' test", function(){
  34. expect(BIT.isOn(parseInt('0111', 2), 3)).be.false;
  35. });
  36. it(".set()", function(){
  37. let num = 1;
  38. num = BIT.set(num, 1);
  39. expect(num).to.equal(3);
  40. });
  41. it(".clear()", function(){
  42. let num = 15;
  43. num = BIT.clear(num, 2);
  44. expect(num).to.equal(11);
  45. });
  46. it(".toggle()", function(){
  47. let num = 9;
  48. num = BIT.toggle(num, 3);
  49. num = BIT.toggle(num, 2);
  50. expect(num).to.equal(5);
  51. });
  52. });
  53. });