summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Kinetic.html
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2014-08-12 21:56:44 +0200
committerChris Schlaeger <chris@linux.com>2014-08-12 21:56:44 +0200
commitea346a785dc1b3f7c156f6fc33da634e1f1a627b (patch)
treeaf67530553d20b6e82ad60fd79593e9c4abf5565 /misc/openlayers/tests/Kinetic.html
parent59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff)
downloadpostrunner-0.0.4.zip
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/tests/Kinetic.html')
-rw-r--r--misc/openlayers/tests/Kinetic.html132
1 files changed, 132 insertions, 0 deletions
diff --git a/misc/openlayers/tests/Kinetic.html b/misc/openlayers/tests/Kinetic.html
new file mode 100644
index 0000000..ba50b53
--- /dev/null
+++ b/misc/openlayers/tests/Kinetic.html
@@ -0,0 +1,132 @@
+<html>
+<head>
+ <script src="OLLoader.js"></script>
+ <script type="text/javascript">
+
+ function test_Kinetic (t) {
+ t.plan(17);
+ var finish = false;
+ var results = {
+ 110: {x: -2.7, y: -3.6, end: false},
+ 120: {x: -2.1, y: -2.8, end: false},
+ 130: {x: -1.5, y: -2.0, end: false},
+ 140: {x: -0.9, y: -1.2, end: false},
+ 150: {x: -0.3, y: -0.4, end: true}
+ };
+
+ var originalGetTime = Date.prototype.getTime;
+ Date.prototype.getTime = function() { return 0 };
+
+ var interval = 10; // arbitrary value for tests
+
+ var originalLoopAnimation = OpenLayers.Animation.start;
+ OpenLayers.Animation.start = function(callback) {
+ while (!finish) {
+ var time = new Date().getTime();
+ Date.prototype.getTime = function() { return time+interval };
+ callback();
+ }
+ };
+
+ var kinetic = new OpenLayers.Kinetic({
+ deceleration: 0.01
+ });
+ kinetic.begin();
+ kinetic.update({x:0, y:0});
+
+ Date.prototype.getTime = function() { return 100 };
+ var measure = kinetic.end({x:30, y:40});
+
+ t.eq(measure.speed, 0.5, "correct speed");
+ t.eq(measure.theta, Math.PI - Math.atan(40/30), "correct angle");
+
+ // fake timer id
+ kinetic.timerId = 0;
+ kinetic.move(measure, function(x, y, end) {
+ var result = results[new Date().getTime()];
+ t.eq(Math.round(x * 1000) / 1000, result.x, "correct x");
+ t.eq(Math.round(y * 1000) / 1000, result.y, "correct y");
+ t.eq(end, result.end, "correct end");
+ finish = end;
+ });
+
+ Date.prototype.getTime = originalGetTime;
+ OpenLayers.Animation.start = originalLoopAnimation;
+ }
+
+ function test_Angle (t) {
+ t.plan(8);
+ var results = [
+ {speed: 0.5, theta: Math.round((Math.PI - Math.atan(40/30)) * 1000000) / 1000000},
+ {speed: 0.5, theta: Math.round((Math.PI + Math.atan(40/30)) * 1000000) / 1000000},
+ {speed: 0.5, theta: Math.round((- Math.atan(40/30)) * 1000000) / 1000000},
+ {speed: 0.5, theta: Math.round((Math.atan(40/30)) * 1000000) / 1000000}
+ ];
+
+ var originalGetTime = Date.prototype.getTime;
+ Date.prototype.getTime = function() { return 0 };
+
+ var kinetic = new OpenLayers.Kinetic();
+ kinetic.begin();
+ kinetic.update({x:0, y:0});
+
+ Date.prototype.getTime = function() { return 100 };
+ var measure = kinetic.end({x:30, y:40});
+
+ t.eq(measure.speed, results[0].speed, "correct speed");
+ t.eq(Math.round(measure.theta * 1000000) / 1000000,
+ results[0].theta, "correct angle");
+
+
+ var originalGetTime = Date.prototype.getTime;
+ Date.prototype.getTime = function() { return 0 };
+
+ var kinetic = new OpenLayers.Kinetic();
+ kinetic.begin();
+ kinetic.update({x:0, y:0});
+
+ Date.prototype.getTime = function() { return 100 };
+ var measure = kinetic.end({x:30, y:-40});
+
+ t.eq(measure.speed, results[1].speed, "correct speed");
+ t.eq(Math.round(measure.theta * 1000000) / 1000000,
+ results[1].theta, "correct angle");
+
+
+ var originalGetTime = Date.prototype.getTime;
+ Date.prototype.getTime = function() { return 0 };
+
+ var kinetic = new OpenLayers.Kinetic();
+ kinetic.begin();
+ kinetic.update({x:0, y:0});
+
+ Date.prototype.getTime = function() { return 100 };
+ var measure = kinetic.end({x:-30, y:-40});
+
+ t.eq(measure.speed, results[2].speed, "correct speed");
+ t.eq(Math.round(measure.theta * 1000000) / 1000000,
+ results[2].theta, "correct angle");
+
+ var originalGetTime = Date.prototype.getTime;
+ Date.prototype.getTime = function() { return 0 };
+
+ var kinetic = new OpenLayers.Kinetic();
+ kinetic.begin();
+ kinetic.update({x:0, y:0});
+
+ Date.prototype.getTime = function() { return 100 };
+ var measure = kinetic.end({x:-30, y:40});
+
+ t.eq(measure.speed, results[3].speed, "correct speed");
+ t.eq(Math.round(measure.theta * 1000000) / 1000000,
+ results[3].theta, "correct angle");
+
+ Date.prototype.getTime = originalGetTime;
+ }
+ </script>
+</head>
+<body>
+ <div id="map" style="width: 600px; height: 300px;"/>
+ <div style="display: none;"><div id="invisimap"></div></div>
+</body>
+</html>