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.

47 lines
1.1KB

  1. const expect = require('chai').expect;
  2. const sinon = require('sinon');
  3. const Clock = require('../src/common/clock.js');
  4. describe("Clock Tests", function(){
  5. var count = 0;
  6. var tick = ()=>{count += 1;};
  7. var clk = (new Clock()).clk(tick);
  8. function speedTest(hz){
  9. let stime = (new Date()).getTime();
  10. let dt = 0;
  11. clk.hz = hz;
  12. while (count < hz && dt < 1000){
  13. clk.tick();
  14. dt = ((new Date()).getTime()) - stime;
  15. }
  16. return dt;
  17. }
  18. it("4hz for approx. 1 second", function(){
  19. let dt = speedTest(4);
  20. expect(count).to.equal(4);
  21. expect(dt).to.be.gt(750);
  22. });
  23. it("4Khz for approx. 1 second", function(){
  24. let ts = 4000;
  25. let d = ts * 0.01;
  26. let dt = speedTest(ts);
  27. expect(count).to.be.gt(ts - d);
  28. expect(count).to.be.lt(ts + d);
  29. expect(dt).to.be.gt(990);
  30. expect(dt).to.be.lt(1010);
  31. });
  32. it("4Mhz for approx. 1 second", function(){
  33. let ts = 4000000;
  34. let d = ts * 0.01;
  35. let dt = speedTest(ts);
  36. expect(count).to.be.gt(ts - d);
  37. expect(count).to.be.lt(ts + d);
  38. expect(dt).to.be.gt(990);
  39. expect(dt).to.be.lt(1010);
  40. });
  41. });