Clock.js 1005 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @author simonThiele / https://github.com/simonThiele
  3. */
  4. module( "Clock" );
  5. function mockPerformance() {
  6. self.performance = {
  7. deltaTime: 0,
  8. next: function( delta ) {
  9. this.deltaTime += delta;
  10. },
  11. now: function() {
  12. return this.deltaTime;
  13. }
  14. };
  15. }
  16. test( "clock with performance", function() {
  17. mockPerformance();
  18. var clock = new THREE.Clock();
  19. clock.start();
  20. self.performance.next(123);
  21. ok( clock.getElapsedTime() === 0.123 , "okay");
  22. self.performance.next(100);
  23. ok( clock.getElapsedTime() === 0.223 , "okay");
  24. clock.stop();
  25. self.performance.next(1000);
  26. ok( clock.getElapsedTime() === 0.223 , "don't update time if the clock was stopped");
  27. });
  28. test( "clock with date", function() {
  29. // remove the performance object so that clock takes Date()
  30. self.performance = undefined;
  31. var clock = new THREE.Clock();
  32. clock.start();
  33. // if a value was calculated, the clock took the alternative Date() object
  34. ok( clock.getElapsedTime() >= 0 , "okay");
  35. clock.stop();
  36. });