Clock.tests.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * @author simonThiele / https://github.com/simonThiele
  3. * @author TristanVALCKE / https://github.com/Itee
  4. */
  5. /* global QUnit */
  6. import { Clock } from '../../../../src/core/Clock';
  7. export default QUnit.module( 'Core', () => {
  8. QUnit.module( 'Clock', () => {
  9. function mockPerformance() {
  10. self.performance = {
  11. deltaTime: 0,
  12. next: function ( delta ) {
  13. this.deltaTime += delta;
  14. },
  15. now: function () {
  16. return this.deltaTime;
  17. }
  18. };
  19. }
  20. // INSTANCING
  21. QUnit.todo( "Instancing", ( assert ) => {
  22. assert.ok( false, "everything's gonna be alright" );
  23. } );
  24. // PUBLIC STUFF
  25. QUnit.todo( "start", ( assert ) => {
  26. assert.ok( false, "everything's gonna be alright" );
  27. } );
  28. QUnit.todo( "stop", ( assert ) => {
  29. assert.ok( false, "everything's gonna be alright" );
  30. } );
  31. QUnit.todo( "getElapsedTime", ( assert ) => {
  32. assert.ok( false, "everything's gonna be alright" );
  33. } );
  34. QUnit.todo( "getDelta", ( assert ) => {
  35. assert.ok( false, "everything's gonna be alright" );
  36. } );
  37. // OTHERS
  38. QUnit.test( "clock with performance", ( assert ) => {
  39. if ( typeof performance === 'undefined' ) {
  40. assert.expect( 0 );
  41. return;
  42. }
  43. mockPerformance();
  44. var clock = new Clock( false );
  45. clock.start();
  46. self.performance.next( 123 );
  47. assert.numEqual( clock.getElapsedTime(), 0.123, "okay" );
  48. self.performance.next( 100 );
  49. assert.numEqual( clock.getElapsedTime(), 0.223, "okay" );
  50. clock.stop();
  51. self.performance.next( 1000 );
  52. assert.numEqual( clock.getElapsedTime(), 0.223, "don't update time if the clock was stopped" );
  53. } );
  54. } );
  55. } );