Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

45 lines
1.0KB

  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.lt(1000);
  30. });
  31. it("4Mhz for approx. 1 second", function(){
  32. let ts = 4000000;
  33. let d = ts * 0.01;
  34. let dt = speedTest(ts);
  35. expect(count).to.be.gt(ts - d);
  36. expect(count).to.be.lt(ts + d);
  37. expect(dt).to.be.lt(1000);
  38. });
  39. });