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.

39 lines
916B

  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 dt = speedTest(4000);
  25. expect(count).to.be.lt(4004);
  26. expect(dt).to.be.lt(1000);
  27. });
  28. it("4Mhz for approx. 1 second", function(){
  29. let dt = speedTest(4000000);
  30. expect(count).to.be.lt(4000004);
  31. expect(dt).to.be.lt(1000);
  32. });
  33. });