Răsfoiți Sursa

add unit tests for clock

simonThiele 10 ani în urmă
părinte
comite
d73576afd4
2 a modificat fișierele cu 53 adăugiri și 0 ștergeri
  1. 52 0
      test/unit/core/Clock.js
  2. 1 0
      test/unit/unittests_three.html

+ 52 - 0
test/unit/core/Clock.js

@@ -0,0 +1,52 @@
+/**
+ * @author simonThiele / https://github.com/simonThiele
+ */
+
+module( "Clock" );
+
+function mockPerformance() {
+  self.performance = {
+    deltaTime: 0,
+
+    next: function( delta ) {
+      this.deltaTime += delta;
+    },
+
+    now: function() {
+      return this.deltaTime;
+    }
+  };
+}
+
+test( "clock with performance", function() {
+  mockPerformance();
+
+  var clock = new THREE.Clock();
+
+  clock.start();
+
+  self.performance.next(123);
+  ok( clock.getElapsedTime() === 0.123 , "okay");
+
+  self.performance.next(100);
+  ok( clock.getElapsedTime() === 0.223 , "okay");
+
+  clock.stop();
+
+  self.performance.next(1000);
+  ok( clock.getElapsedTime() === 0.223 , "don't update time if the clock was stopped");
+});
+
+test( "clock with date", function() {
+  // remove the performance object so that clock takes Date()
+  self.performance = undefined;
+
+  var clock = new THREE.Clock();
+
+  clock.start();
+
+  // if a value was calculated, the clock took the alternative Date() object
+  ok( clock.getElapsedTime() >= 0 , "okay");
+
+  clock.stop();
+});

+ 1 - 0
test/unit/unittests_three.html

@@ -24,6 +24,7 @@
 
   <script src="core/BufferAttribute.js"></script>
   <script src="core/BufferGeometry.js"></script>
+  <script src="core/Clock.js"></script>
   <script src="core/Object3D.js"></script>
 
   <script src="math/Constants.js"></script>