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);
    });
  });
});