MCPcopy Index your code
hub / github.com/ampproject/amphtml / testContinuation

Function testContinuation

test/unit/test-motion.js:55–100  ·  view source on GitHub ↗
(maxVelocity, haltAfterTime)

Source from the content-addressed store, hash-verified

53 });
54
55 function testContinuation(maxVelocity, haltAfterTime) {
56 let resultX = null;
57 let resultY = null;
58 const motion = continueMotion(
59 contextNode,
60 141,
61 104,
62 maxVelocity,
63 maxVelocity,
64 (x, y) => {
65 resultX = x;
66 resultY = y;
67 return true;
68 },
69 vsync
70 );
71
72 expect(vsyncTasks.length).to.equal(1);
73 const mutator = vsyncTasks[0];
74 vsyncTasks = [];
75
76 resultX = resultY = null;
77 mutator(0, 0, {});
78 expect(resultX).to.be.closeTo(141, 1e-3);
79 expect(resultY).to.be.closeTo(104, 1e-3);
80
81 const values = [];
82 let time = 0;
83 let continuing = true;
84 do {
85 resultX = resultY = null;
86 clock.tick(100);
87 const prev = time;
88 time += 100;
89 continuing = mutator(time, time - prev, {});
90 if (resultX != null) {
91 expect(resultX - 141).to.be.closeTo(resultY - 104, 1e-3);
92 values.push(resultX - 141);
93 }
94 if (haltAfterTime && time >= haltAfterTime) {
95 motion.halt();
96 }
97 } while (continuing && time < 10000);
98 expect(continuing).to.equal(false);
99 return values;
100 }
101
102 it('should follow positive inertia', () => {
103 const values = testContinuation(0.665, 0);

Callers 1

test-motion.jsFile · 0.85

Calls 5

continueMotionFunction · 0.90
expectFunction · 0.85
tickMethod · 0.80
pushMethod · 0.45
haltMethod · 0.45

Tested by

no test coverage detected