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.

74 lines
1.8KB

  1. const expect = require('chai').expect;
  2. const sinon = require('sinon');
  3. const Clock = require('../src/clock.js');
  4. describe("Clock Tests", function(){
  5. var count = 0;
  6. var count2 = 0;
  7. var tick = ()=>{count += 1;};
  8. var tick2 = () =>{count2 += 1;};
  9. var clk = (new Clock()).clk(tick);
  10. var clk2 = (new Clock(2)).clk(tick).clk(tick2, 1);
  11. function speedTest(hz, c){
  12. c = (c) ? c : 1;
  13. let stime = Date.now();
  14. let ltime = stime;
  15. let dt = 0;
  16. let _clk = (c === 1) ? clk : clk2;
  17. _clk.hz = hz;
  18. while (count < hz && dt < 1000){
  19. let ctime = Date.now();
  20. let _dt = ctime - ltime;
  21. if (_dt > 0){
  22. ltime = ctime;
  23. _clk.tick(_dt);
  24. }
  25. dt = Date.now() - stime;
  26. }
  27. return dt;
  28. }
  29. it("4hz for approx. 1 second", function(){
  30. let dt = speedTest(4);
  31. expect(count).to.equal(4);
  32. expect(dt).to.be.gt(750);
  33. });
  34. it("4Khz for approx. 1 second", function(){
  35. count = 0;
  36. let ts = 4000;
  37. let d = ts * 0.01;
  38. let dt = speedTest(ts);
  39. expect(count).to.be.gt(ts - d);
  40. expect(count).to.be.lt(ts + d);
  41. expect(dt).to.be.gt(990);
  42. expect(dt).to.be.lt(1010);
  43. });
  44. it("4Mhz for approx. 1 second", function(){
  45. count = 0;
  46. let ts = 4000000;
  47. let d = ts * 0.01;
  48. let dt = speedTest(ts);
  49. expect(count).to.be.gt(ts - d);
  50. expect(count).to.be.lt(ts + d);
  51. expect(dt).to.be.gt(990);
  52. expect(dt).to.be.lt(1010);
  53. });
  54. it("4khz w/two layers for approx. 1 second", function(){
  55. count = 0;
  56. count2 = 0;
  57. let ts = 4000;
  58. let d = ts * 0.01;
  59. let dt = speedTest(ts, 2);
  60. expect(count).to.be.gt((ts*0.5) - dt);
  61. expect(count).to.be.lt((ts*0.5) + dt);
  62. expect(count2).to.be.gt((ts*0.5) - dt);
  63. expect(count2).to.be.lt((ts*0.5) + dt);
  64. expect(dt).to.be.gt(990);
  65. expect(dt).to.be.lt(1010);
  66. });
  67. });