How to use closeTo method in chai

Best JavaScript code snippet using chai

TickSource.js

Source:TickSource.js Github

copy

Full Screen

...18 return Offline(function(){19 var source = new TickSource();20 source.start(0);21 return function(time){22 expect(source.ticks).to.be.closeTo(time, 0.1);23 };24 }, 0.5);25 });26 it("ticks return to 0 after stopped", function(){27 return Offline(function(){28 var source = new TickSource(2);29 source.start(0).stop(0.4);30 return function(time){31 if (time < 0.399){32 expect(source.ticks).to.be.closeTo(2*time, 0.01);33 } else if (time > 4){34 expect(source.ticks).to.be.equal(0);35 }36 };37 }, 0.5);38 });39 it("returns the paused ticks when paused", function(){40 return Offline(function(){41 var source = new TickSource(2);42 source.start(0).pause(0.4);43 var pausedTicks = -1;44 return function(time){45 if (time < 0.4){46 pausedTicks = source.ticks;47 expect(source.ticks).to.be.closeTo(2*time, 0.01);48 } else {49 expect(source.ticks).to.be.closeTo(pausedTicks, 0.01);50 }51 };52 }, 0.5);53 });54 it("ticks restart at 0 when started after stop", function(){55 var source = new TickSource(3);56 source.start(0).stop(1).start(2);57 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);58 expect(source.getTicksAtTime(0.5)).to.be.closeTo(1.5, 0.01);59 expect(source.getTicksAtTime(1)).to.be.closeTo(0, 0.01);60 expect(source.getTicksAtTime(2)).to.be.closeTo(0, 0.01);61 expect(source.getTicksAtTime(3)).to.be.closeTo(3, 0.01);62 source.dispose();63 });64 it("ticks remain the same after paused", function(){65 var source = new TickSource(3);66 source.start(0).pause(1);67 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);68 expect(source.getTicksAtTime(0.5)).to.be.closeTo(1.5, 0.01);69 expect(source.getTicksAtTime(1)).to.be.closeTo(3, 0.01);70 expect(source.getTicksAtTime(2)).to.be.closeTo(3, 0.01);71 expect(source.getTicksAtTime(3)).to.be.closeTo(3, 0.01);72 source.dispose();73 });74 it("ticks resume where they were paused", function(){75 var source = new TickSource(2);76 source.start(0).pause(1).start(2);77 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);78 expect(source.getTicksAtTime(0.5)).to.be.closeTo(1, 0.01);79 expect(source.getTicksAtTime(1)).to.be.closeTo(2, 0.01);80 expect(source.getTicksAtTime(2)).to.be.closeTo(2, 0.01);81 expect(source.getTicksAtTime(3)).to.be.closeTo(4, 0.01);82 expect(source.getTicksAtTime(4)).to.be.closeTo(6, 0.01);83 source.dispose();84 });85 it("ticks return to 0 after pause then stopped", function(){86 var source = new TickSource(2);87 source.start(0).pause(1).start(2).stop(3);88 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);89 expect(source.getTicksAtTime(0.5)).to.be.closeTo(1, 0.01);90 expect(source.getTicksAtTime(1)).to.be.closeTo(2, 0.01);91 expect(source.getTicksAtTime(2)).to.be.closeTo(2, 0.01);92 expect(source.getTicksAtTime(3)).to.be.closeTo(0, 0.01);93 expect(source.getTicksAtTime(4)).to.be.closeTo(0, 0.01);94 source.dispose();95 });96 it("handles multiple starts/stops", function(){97 var source = new TickSource(1);98 source.start(0).stop(0.3).start(0.4).stop(0.5).start(0.6);99 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);100 expect(source.getTicksAtTime(0.1)).to.be.closeTo(0.1, 0.01);101 expect(source.getTicksAtTime(0.2)).to.be.closeTo(0.2, 0.01);102 expect(source.getTicksAtTime(0.3)).to.be.closeTo(0, 0.01);103 expect(source.getTicksAtTime(0.4)).to.be.closeTo(0, 0.01);104 expect(source.getTicksAtTime(0.5)).to.be.closeTo(0, 0.01);105 expect(source.getTicksAtTime(0.6)).to.be.closeTo(0, 0.01);106 expect(source.getTicksAtTime(0.7)).to.be.closeTo(0.1, 0.01);107 expect(source.getTicksAtTime(0.8)).to.be.closeTo(0.2, 0.01);108 source.dispose();109 });110 it("can get ticks when started with an offset", function(){111 var source = new TickSource(1);112 source.start(0, 2).stop(3).start(5, 1);113 expect(source.getTicksAtTime(0)).to.be.closeTo(2, 0.01);114 expect(source.getTicksAtTime(1)).to.be.closeTo(3, 0.01);115 expect(source.getTicksAtTime(2)).to.be.closeTo(4, 0.01);116 expect(source.getTicksAtTime(3)).to.be.closeTo(0, 0.01);117 expect(source.getTicksAtTime(4)).to.be.closeTo(0, 0.01);118 expect(source.getTicksAtTime(5)).to.be.closeTo(1, 0.01);119 expect(source.getTicksAtTime(6)).to.be.closeTo(2, 0.01);120 source.dispose();121 });122 it("can invoke stop multiple times, takes the last invokation", function(){123 var source = new TickSource(1);124 source.start(0).stop(3).stop(2).stop(4);125 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);126 expect(source.getTicksAtTime(1)).to.be.closeTo(1, 0.01);127 expect(source.getTicksAtTime(2)).to.be.closeTo(2, 0.01);128 expect(source.getTicksAtTime(3)).to.be.closeTo(3, 0.01);129 expect(source.getTicksAtTime(4)).to.be.closeTo(0, 0.01);130 expect(source.getTicksAtTime(5)).to.be.closeTo(0, 0.01);131 expect(source.getTicksAtTime(6)).to.be.closeTo(0, 0.01);132 source.dispose();133 });134 it("can set multiple setTicksAtTime", function(){135 var source = new TickSource(1);136 source.start(0, 1).pause(3);137 source.setTicksAtTime(1, 4);138 source.stop(5).start(6);139 source.setTicksAtTime(2, 7);140 expect(source.getTicksAtTime(0)).to.be.closeTo(1, 0.01);141 expect(source.getTicksAtTime(1)).to.be.closeTo(2, 0.01);142 expect(source.getTicksAtTime(2)).to.be.closeTo(3, 0.01);143 expect(source.getTicksAtTime(3)).to.be.closeTo(4, 0.01);144 expect(source.getTicksAtTime(3.5)).to.be.closeTo(4, 0.01);145 expect(source.getTicksAtTime(4)).to.be.closeTo(1, 0.01);146 expect(source.getTicksAtTime(5)).to.be.closeTo(0, 0.01);147 expect(source.getTicksAtTime(6)).to.be.closeTo(0, 0.01);148 expect(source.getTicksAtTime(6.5)).to.be.closeTo(0.5, 0.01);149 expect(source.getTicksAtTime(7)).to.be.closeTo(2, 0.01);150 source.dispose();151 });152 it("can pass start offset", function(){153 var source = new TickSource(2);154 source.start(0, 2).pause(1).start(2, 1);155 expect(source.getTicksAtTime(0)).to.be.closeTo(2, 0.01);156 expect(source.getTicksAtTime(1)).to.be.closeTo(4, 0.01);157 expect(source.getTicksAtTime(2)).to.be.closeTo(1, 0.01);158 expect(source.getTicksAtTime(3)).to.be.closeTo(3, 0.01);159 expect(source.getTicksAtTime(4)).to.be.closeTo(5, 0.01);160 source.dispose();161 });162 it("can set ticks at any point", function(){163 var source = new TickSource(2);164 source.start(0, 2).pause(1).start(2);165 source.setTicksAtTime(10, 1.5);166 source.setTicksAtTime(2, 3.5);167 expect(source.getTicksAtTime(0)).to.be.closeTo(2, 0.01);168 expect(source.getTicksAtTime(1)).to.be.closeTo(4, 0.01);169 expect(source.getTicksAtTime(2)).to.be.closeTo(10, 0.01);170 expect(source.getTicksAtTime(3)).to.be.closeTo(12, 0.01);171 expect(source.getTicksAtTime(4)).to.be.closeTo(3, 0.01);172 expect(source.getTicksAtTime(5)).to.be.closeTo(5, 0.01);173 source.dispose();174 });175 it("get the time of the ticks", function(){176 var source = new TickSource(2);177 source.start(0, 2).pause(1).start(2);178 source.setTicksAtTime(10, 1.5);179 source.setTicksAtTime(2, 3.5);180 expect(source.getTimeOfTick(2, 0.9)).to.be.closeTo(0, 0.01);181 expect(source.getTimeOfTick(4, 0.9)).to.be.closeTo(1, 0.01);182 expect(source.getTimeOfTick(10, 3)).to.be.closeTo(2, 0.01);183 expect(source.getTimeOfTick(12, 3)).to.be.closeTo(3, 0.01);184 expect(source.getTimeOfTick(3, 4)).to.be.closeTo(4, 0.01);185 expect(source.getTimeOfTick(5, 4)).to.be.closeTo(5, 0.01);186 source.dispose();187 });188 it("can cancel scheduled events", function(){189 var source = new TickSource(1);190 source.start(0).stop(3);191 source.setTicksAtTime(10, 2);192 source.cancel(1);193 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);194 expect(source.getTicksAtTime(1)).to.be.closeTo(1, 0.01);195 expect(source.getTicksAtTime(2)).to.be.closeTo(2, 0.01);196 expect(source.getTicksAtTime(3)).to.be.closeTo(3, 0.01);197 expect(source.getTicksAtTime(4)).to.be.closeTo(4, 0.01);198 expect(source.getTicksAtTime(5)).to.be.closeTo(5, 0.01);199 expect(source.getTicksAtTime(6)).to.be.closeTo(6, 0.01);200 source.dispose();201 });202 });203 context("forEachTickBetween", function(){204 it("invokes a callback function when started", function(){205 var source = new TickSource(1);206 source.start(0);207 var wasCalled = false;208 source.forEachTickBetween(0, 2, function(){209 wasCalled = true;210 });211 expect(wasCalled).to.be.true;212 source.dispose();213 });214 it("does not invoke callback when not overlapping with tick", function(){215 var source = new TickSource(1);216 source.start(0);217 var wasCalled = false;218 source.forEachTickBetween(1.1, 2, function(){219 wasCalled = true;220 });221 expect(wasCalled).to.be.false;222 source.dispose();223 });224 it("iterates only at times when the state is 'started'", function(){225 var source = new TickSource(4);226 source.start(0.2).pause(2).start(3.5).stop(5);227 var iterations = 0;228 var expectedTimes = [1.2, 1.45, 1.7, 1.95, 3.5, 3.75, 4, 4.25, 4.5, 4.75];229 var expectedTicks = [4, 5, 6, 7, 7, 8, 9, 10, 11, 12];230 source.forEachTickBetween(1, 7, function(time, ticks){231 expect(time).to.be.closeTo(expectedTimes[iterations], 0.001);232 expect(ticks).to.equal(expectedTicks[iterations]);233 iterations++;234 });235 expect(iterations).to.equal(expectedTimes.length);236 source.dispose();237 });238 it("can start at time = 0", function(){239 var source = new TickSource(1);240 source.start(0);241 var iterations = 0;242 source.forEachTickBetween(0, 0.1, function(){243 iterations++;244 });245 expect(iterations).to.equal(1);246 source.dispose();247 });248 it("can throw an error in the callback but still invokes all loops", function(){249 var source = new TickSource(1);250 source.start(0);251 expect(function(){252 source.forEachTickBetween(0, 3, function(){253 throw new Error("should throw");254 });255 }).throws(Error);256 source.dispose();257 });258 it("iterates once per tick", function(){259 var source = new TickSource(1);260 source.start(0.5);261 var iterations = 0;262 source.forEachTickBetween(0, 2, function(){263 iterations++;264 });265 expect(iterations).to.equal(2);266 source.dispose();267 });268 it("passes time and tick into the callback", function(){269 var source = new TickSource(2);270 source.start(0.5);271 var iterations = 0;272 var times = [0.5, 1.0, 1.5];273 source.forEachTickBetween(0, 2, function(time, ticks){274 expect(times[ticks]).to.be.closeTo(time, 0.001);275 iterations++;276 });277 expect(iterations).to.equal(3);278 source.dispose();279 });280 it("ticks = 0 when restarted", function(){281 var source = new TickSource(1);282 source.start(0.5).stop(1).start(2);283 var iterations = 0;284 var expectedTicks = [0, 0, 1];285 var expectedTimes = [0.5, 2, 3];286 source.forEachTickBetween(0, 3.1, function(time, ticks){287 expect(time).to.be.closeTo(expectedTimes[iterations], 0.001);288 expect(ticks).to.equal(expectedTicks[iterations]);289 iterations++;290 });291 expect(iterations).to.equal(expectedTicks.length);292 source.dispose();293 });294 it("ticks resume after pause when restarted", function(){295 var source = new TickSource(1);296 source.start(0.5).pause(2).start(3);297 var iterations = 0;298 var expectedTicks = [0, 1, 2];299 var expectedTimes = [0.5, 1.5, 3];300 source.forEachTickBetween(0, 3.1, function(time, ticks){301 expect(time).to.be.closeTo(expectedTimes[iterations], 0.001);302 expect(ticks).to.equal(expectedTicks[iterations]);303 iterations++;304 });305 expect(iterations).to.equal(expectedTicks.length);306 source.dispose();307 });308 it("handles start and stop", function(){309 var source = new TickSource(2);310 source.start(0.5).stop(2);311 var iterations = 0;312 var times = [0.5, 1.0, 1.5];313 source.forEachTickBetween(0, 3, function(time, ticks){314 expect(times[ticks]).to.be.closeTo(time, 0.001);315 iterations++;316 });317 expect(iterations).to.equal(3);318 source.dispose();319 });320 it("handles multiple start and stop", function(){321 var source = new TickSource(2);322 source.start(0.5).stop(2).start(2.5).stop(4.1);323 var iterations = 0;324 var times = [0.5, 1.0, 1.5, 2.5, 3, 3.5, 4];325 source.forEachTickBetween(0, 10, function(time){326 expect(times[iterations]).to.be.closeTo(time, 0.001);327 iterations++;328 });329 expect(iterations).to.equal(times.length);330 source.dispose();331 });332 it("works with a frequency ramp", function(){333 var source = new TickSource(1);334 source.frequency.setValueAtTime(1, 0);335 source.frequency.linearRampToValueAtTime(4, 1);336 source.start(0.5);337 var iterations = 0;338 const times = [0.500, 0.833, 1.094, 1.344, 1.594, 1.844];339 source.forEachTickBetween(0, 2, function(time, ticks){340 expect(time).to.be.closeTo(times[ticks], 0.001);341 iterations++;342 });343 expect(iterations).to.equal(times.length);344 source.dispose();345 });346 it("can start with a tick offset", function(){347 var source = new TickSource(10);348 source.start(0.5, 5);349 var iterations = 0;350 source.forEachTickBetween(0, 2, function(time, ticks){351 expect(ticks).to.be.gte(5);352 iterations++;353 });354 expect(iterations).to.equal(15);355 source.dispose();356 });357 it("can handle multiple starts with tick offsets", function(){358 var source = new TickSource(1);359 source.start(0.5, 10).stop(2).start(3, 1);360 var iterations = 0;361 var expectedTimes = [0.5, 1.5, 3];362 var expectedTicks = [10, 11, 1];363 source.forEachTickBetween(0, 4, function(time, ticks){364 expect(time).to.be.closeTo(expectedTimes[iterations], 0.001);365 expect(ticks).to.equal(expectedTicks[iterations]);366 iterations++;367 });368 expect(iterations).to.equal(expectedTicks.length);369 source.dispose();370 });371 it("can set ticks after start", function(){372 var source = new TickSource(1);373 source.start(0.4, 3);374 source.setTicksAtTime(1, 1.4);375 source.setTicksAtTime(10, 3);376 var iterations = 0;377 var expectedTicks = [3, 1, 2, 10];378 source.forEachTickBetween(0, 4, function(time, ticks){379 expect(ticks).to.equal(expectedTicks[iterations]);380 iterations++;381 });382 expect(iterations).to.equal(expectedTicks.length);383 source.dispose();384 });385 it("can pass in the frequency", function(){386 var source = new TickSource(20);387 source.start(0.5);388 var iterations = 0;389 var lastTime = 0.5;390 source.forEachTickBetween(0.51, 2.01, function(time){391 expect(time - lastTime).to.be.closeTo(0.05, 0.001);392 lastTime = time;393 iterations++;394 });395 expect(iterations).to.equal(30);396 source.dispose();397 });398 it("can iterate from later in the timeline", function(){399 var source = new TickSource(1);400 source.start(0.2);401 var iterations = 0;402 source.forEachTickBetween(100, 101, function(time, ticks){403 expect(ticks).to.equal(100);404 expect(time).to.be.closeTo(100.2, 0.001);405 iterations++;406 });407 expect(iterations).to.equal(1);408 source.dispose();409 });410 it("always increments by 1", function(){411 var source = new TickSource(200);412 source.frequency.setValueAtTime(200, 0);413 source.frequency.linearRampToValueAtTime(1000, 4);414 source.start(0);415 var previousTick = -1;416 source.forEachTickBetween(0, 10, function(time, ticks){417 expect(ticks - previousTick).to.equal(1);418 previousTick = ticks;419 });420 source.dispose();421 });422 });423 context("Seconds", function(){424 it("get the elapsed time in seconds", function(){425 return Offline(function(){426 var source = new TickSource(1).start(0);427 return function(time){428 expect(source.seconds).to.be.closeTo(time, 0.01);429 };430 }, 2);431 });432 it("seconds is 0 before starting", function(){433 var source = new TickSource(1);434 expect(source.seconds).to.be.closeTo(0, 0.001);435 source.dispose();436 437 });438 it("can set the seconds", function(){439 var source = new TickSource(1);440 expect(source.seconds).to.be.closeTo(0, 0.001);441 source.dispose();442 443 });444 it("seconds pauses at last second count", function(){445 var source = new TickSource(1);446 source.start(0).pause(1);447 expect(source.getSecondsAtTime(0)).to.be.closeTo(0, 0.001);448 expect(source.getSecondsAtTime(1)).to.be.closeTo(1, 0.001);449 expect(source.getSecondsAtTime(2)).to.be.closeTo(1, 0.001);450 source.dispose();451 });452 it("can handle multiple pauses", function(){453 var source = new TickSource(1);454 source.start(0).pause(1).start(2).pause(3).start(4).stop(6);455 expect(source.getSecondsAtTime(0)).to.be.closeTo(0, 0.001);456 expect(source.getSecondsAtTime(1)).to.be.closeTo(1, 0.001);457 expect(source.getSecondsAtTime(2)).to.be.closeTo(1, 0.001);458 expect(source.getSecondsAtTime(2.5)).to.be.closeTo(1.5, 0.001);459 expect(source.getSecondsAtTime(3)).to.be.closeTo(2, 0.001);460 expect(source.getSecondsAtTime(4.5)).to.be.closeTo(2.5, 0.001);461 expect(source.getSecondsAtTime(5)).to.be.closeTo(3, 0.001);462 expect(source.getSecondsAtTime(6)).to.be.closeTo(0, 0.001);463 source.dispose();464 });465 it("get the elapsed time in seconds when starting in the future", function(){466 return Offline(function(){467 var source = new TickSource(1).start(0.1);468 return function(time){469 if (time < 0.1){470 expect(source.seconds).to.be.closeTo(0, 0.001);471 } else {472 expect(source.seconds).to.be.closeTo(time - 0.1, 0.01);473 }474 };475 }, 2);476 });477 it("handles multiple starts and stops", function(){478 var source = new TickSource(1).start(0).stop(0.5).start(1).stop(1.5);479 expect(source.getSecondsAtTime(0)).to.be.closeTo(0, 0.01);480 expect(source.getSecondsAtTime(0.4)).to.be.closeTo(0.4, 0.01);481 expect(source.getSecondsAtTime(0.5)).to.be.closeTo(0, 0.01);482 expect(source.getSecondsAtTime(0.9)).to.be.closeTo(0, 0.01);483 expect(source.getSecondsAtTime(1)).to.be.closeTo(0, 0.01);484 expect(source.getSecondsAtTime(1.4)).to.be.closeTo(0.4, 0.01);485 expect(source.getSecondsAtTime(1.5)).to.be.closeTo(0, 0.01);486 source.dispose();487 });488 });489 context("Frequency", function(){490 it("can automate frequency with setValueAtTime", function(){491 var source = new TickSource(1);492 source.start(0).stop(0.3).start(0.4).stop(0.5).start(0.6);493 source.frequency.setValueAtTime(2, 0.3);494 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);495 expect(source.getTicksAtTime(0.1)).to.be.closeTo(0.1, 0.01);496 expect(source.getTicksAtTime(0.2)).to.be.closeTo(0.2, 0.01);497 expect(source.getTicksAtTime(0.3)).to.be.closeTo(0, 0.01);498 expect(source.getTicksAtTime(0.4)).to.be.closeTo(0, 0.01);499 expect(source.getTicksAtTime(0.45)).to.be.closeTo(0.1, 0.01);500 expect(source.getTicksAtTime(0.5)).to.be.closeTo(0, 0.01);501 expect(source.getTicksAtTime(0.6)).to.be.closeTo(0, 0.01);502 expect(source.getTicksAtTime(0.7)).to.be.closeTo(0.2, 0.01);503 expect(source.getTicksAtTime(0.8)).to.be.closeTo(0.4, 0.01);504 source.dispose();505 });506 it("can automate frequency with linearRampToValueAtTime", function(){507 var source = new TickSource(1);508 source.start(0).stop(1).start(2);509 source.frequency.linearRampToValueAtTime(2, 2);510 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);511 expect(source.getTicksAtTime(0.5)).to.be.closeTo(0.56, 0.01);512 expect(source.getTicksAtTime(1)).to.be.closeTo(0, 0.01);513 expect(source.getTicksAtTime(2)).to.be.closeTo(0, 0.01);514 expect(source.getTicksAtTime(3)).to.be.closeTo(2, 0.01);515 source.dispose();516 });517 it("can automate frequency with exponentialRampToValueAtTime", function(){518 var source = new TickSource(1);519 source.start(0).stop(1).start(2).stop(5);520 source.frequency.exponentialRampToValueAtTime(4, 2);521 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);522 expect(source.getTicksAtTime(0.5)).to.be.closeTo(0.6, 0.01);523 expect(source.getTicksAtTime(1)).to.be.closeTo(0, 0.01);524 expect(source.getTicksAtTime(2)).to.be.closeTo(0, 0.01);525 expect(source.getTicksAtTime(3)).to.be.closeTo(4, 0.01);526 expect(source.getTicksAtTime(4)).to.be.closeTo(8, 0.01);527 source.dispose();528 });529 it("can automate frequency with setTargetAtTime", function(){530 var source = new TickSource(1);531 source.start(0).stop(1).start(2).stop(5);532 source.frequency.setTargetAtTime(2, 1, 0.5);533 expect(source.getTicksAtTime(0)).to.be.closeTo(0, 0.01);534 expect(source.getTicksAtTime(0.5)).to.be.closeTo(0.5, 0.01);535 expect(source.getTicksAtTime(1)).to.be.closeTo(0, 0.01);536 expect(source.getTicksAtTime(2)).to.be.closeTo(0, 0.01);537 expect(source.getTicksAtTime(3)).to.be.closeTo(1.86, 0.01);538 expect(source.getTicksAtTime(4)).to.be.closeTo(3.73, 0.01);539 expect(source.getTicksAtTime(5)).to.be.closeTo(0, 0.01);540 source.dispose();541 });542 });543 });...

Full Screen

Full Screen

effect.js

Source:effect.js Github

copy

Full Screen

...50 {offset: 2}51 ]);52 });53 assert.equal(normalizedKeyframes.length, 4);54 assert.closeTo(normalizedKeyframes[0].offset, 0, 0.001);55 assert.closeTo(normalizedKeyframes[1].offset, 0.5, 0.001);56 assert.closeTo(normalizedKeyframes[2].offset, 0.75, 0.001);57 assert.closeTo(normalizedKeyframes[3].offset, 1, 0.001);58 });59 test('Normalize keyframes with some offsets not specified, but sorted by offset where specified. All specified offsets in [0, 1] range.', function() {60 var normalizedKeyframes;61 assert.doesNotThrow(function() {62 normalizedKeyframes = normalizeKeyframes([63 {left: '0px', offset: 0},64 {left: '10px'},65 {left: '20px'},66 {left: '30px', offset: 0.6},67 {left: '40px'},68 {left: '50px'}69 ]);70 });71 assert.equal(normalizedKeyframes.length, 6);72 assert.closeTo(normalizedKeyframes[0].offset, 0, 0.001);73 assert.equal(normalizedKeyframes[0].left, '0px');74 assert.closeTo(normalizedKeyframes[1].offset, 0.2, 0.001);75 assert.equal(normalizedKeyframes[1].left, '10px');76 assert.closeTo(normalizedKeyframes[2].offset, 0.4, 0.001);77 assert.equal(normalizedKeyframes[2].left, '20px');78 assert.closeTo(normalizedKeyframes[3].offset, 0.6, 0.001);79 assert.equal(normalizedKeyframes[3].left, '30px');80 assert.closeTo(normalizedKeyframes[4].offset, 0.8, 0.001);81 assert.equal(normalizedKeyframes[4].left, '40px');82 assert.closeTo(normalizedKeyframes[5].offset, 1, 0.001);83 assert.equal(normalizedKeyframes[5].left, '50px');84 });85 test('Normalize keyframes with no offsets specified.', function() {86 var normalizedKeyframes;87 assert.doesNotThrow(function() {88 normalizedKeyframes = normalizeKeyframes([89 {left: '0px'},90 {left: '10px'},91 {left: '20px'},92 {left: '30px'},93 {left: '40px'}94 ]);95 });96 assert.equal(normalizedKeyframes.length, 5);97 assert.closeTo(normalizedKeyframes[0].offset, 0, 0.001);98 assert.equal(normalizedKeyframes[0].left, '0px');99 assert.closeTo(normalizedKeyframes[1].offset, 0.25, 0.001);100 assert.equal(normalizedKeyframes[1].left, '10px');101 assert.closeTo(normalizedKeyframes[2].offset, 0.5, 0.001);102 assert.equal(normalizedKeyframes[2].left, '20px');103 assert.closeTo(normalizedKeyframes[3].offset, 0.75, 0.001);104 assert.equal(normalizedKeyframes[3].left, '30px');105 assert.closeTo(normalizedKeyframes[4].offset, 1, 0.001);106 assert.equal(normalizedKeyframes[4].left, '40px');107 });108 test('Normalize keyframes where a keyframe has an offset that is not a number.', function() {109 assert.throws(function() {110 normalizeKeyframes([111 {offset: 0},112 {offset: 'one'},113 {offset: 1}114 ]);115 });116 });117 test('Normalize keyframes where a keyframe has an offset that is a numeric string.', function() {118 var normalizedKeyframes;119 assert.doesNotThrow(function() {120 normalizedKeyframes = normalizeKeyframes([121 {offset: 0},122 {offset: '0.5'},123 {offset: 1}124 ]);125 });126 assert.equal(normalizedKeyframes.length, 3);127 assert.closeTo(normalizedKeyframes[0].offset, 0, 0.001);128 assert.closeTo(normalizedKeyframes[1].offset, 0.5, 0.001);129 assert.closeTo(normalizedKeyframes[2].offset, 1, 0.001);130 });131 test('Normalize keyframes where some keyframes have easings.', function() {132 var normalizedKeyframes;133 assert.doesNotThrow(function() {134 normalizedKeyframes = normalizeKeyframes([135 {left: '0px', easing: 'ease-in'},136 {left: '10px'},137 {left: '0px'}138 ]);139 });140 });141 test('Normalize keyframes with invalid specified easing.', function() {142 var normalizedKeyframes;143 assert.doesNotThrow(function() {144 normalizedKeyframes = normalizeKeyframes([145 {left: '0px', easing: 'easy-peasy'},146 {left: '10px'},147 {left: '0px'}148 ]);149 });150 assert.equal('' + normalizedKeyframes[0].easing, 'function (x) { return x; }');151 });152 test('Normalize keyframes where some properties are given non-string, non-number values.', function() {153 var normalizedKeyframes;154 assert.doesNotThrow(function() {155 normalizedKeyframes = normalizeKeyframes([156 {left: {}},157 {left: '100px'},158 {left: []}159 ]);160 });161 assert(normalizedKeyframes.length, 3);162 assert.equal(normalizedKeyframes[0].left, '[object Object]');163 assert.equal(normalizedKeyframes[1].left, '100px');164 assert.equal(normalizedKeyframes[2].left, '');165 });166 test('Normalize input that is not an array.', function() {167 assert.throws(function() {168 normalizeKeyframes(10);169 });170 });171 test('Normalize an empty array.', function() {172 var normalizedKeyframes;173 assert.doesNotThrow(function() {174 normalizedKeyframes = normalizeKeyframes([]);175 });176 assert.deepEqual(normalizedKeyframes, []);177 });178 test('Normalize null.', function() {179 var normalizedKeyframes;180 assert.doesNotThrow(function() {181 normalizedKeyframes = normalizeKeyframes(null);182 });183 assert.deepEqual(normalizedKeyframes, []);184 });185 test('Normalize shorthands.', function() {186 var normalizedKeyframes;187 assert.doesNotThrow(function() {188 normalizedKeyframes = normalizeKeyframes([{borderColor: 'purple green orange blue'}, {borderColor: 'red'}]);189 });190 assert.equal(normalizedKeyframes[0].borderTopColor, 'purple');191 assert.equal(normalizedKeyframes[0].borderRightColor, 'green');192 assert.equal(normalizedKeyframes[0].borderBottomColor, 'orange');193 assert.equal(normalizedKeyframes[0].borderLeftColor, 'blue');194 assert.equal(normalizedKeyframes[1].borderTopColor, 'red');195 assert.equal(normalizedKeyframes[1].borderRightColor, 'red');196 assert.equal(normalizedKeyframes[1].borderBottomColor, 'red');197 assert.equal(normalizedKeyframes[1].borderLeftColor, 'red');198 assert.doesNotThrow(function() {199 normalizedKeyframes = normalizeKeyframes([{font: 'italic bold 20pt / 200% serif'}, {font: 'italic normal bold 50pt serif'}]);200 });201 assert.equal(normalizedKeyframes[0].fontStyle, 'italic');202 assert.equal(normalizedKeyframes[0].fontVariant, 'normal');203 assert.equal(normalizedKeyframes[0].fontWeight, '700');204 assert.equal(normalizedKeyframes[0].fontSize, '20pt');205 assert.equal(normalizedKeyframes[0].lineHeight, '200%');206 assert.equal(normalizedKeyframes[0].fontFamily, 'serif');207 assert.equal(normalizedKeyframes[1].fontStyle, 'italic');208 assert.equal(normalizedKeyframes[1].fontVariant, 'normal');209 assert.equal(normalizedKeyframes[1].fontWeight, '700');210 assert.equal(normalizedKeyframes[1].fontSize, '50pt');211 assert.equal(normalizedKeyframes[1].lineHeight, 'normal');212 assert.equal(normalizedKeyframes[1].fontFamily, 'serif');213 });214 // Test makePropertySpecificKeyframeGroups.215 test('Make property specific keyframe groups for a simple effect with one property.', function() {216 var groups;217 assert.doesNotThrow(function() {218 groups = makePropertySpecificKeyframeGroups(normalizeKeyframes([219 {left: '0px'},220 {left: '200px', offset: 0.3},221 {left: '0px'}222 ]));223 });224 assert.equal(Object.getOwnPropertyNames(groups).length, 1);225 assert.equal(groups.left.length, 3);226 assert.closeTo(groups.left[0].offset, 0, 0.001);227 assert.equal(groups.left[0].value, '0px');228 assert.closeTo(groups.left[1].offset, 0.3, 0.001);229 assert.equal(groups.left[1].value, '200px');230 assert.closeTo(groups.left[2].offset, 1, 0.001);231 assert.equal(groups.left[2].value, '0px');232 });233 test('Make property specific keyframe groups for an effect with three properties.', function() {234 var groups;235 assert.doesNotThrow(function() {236 groups = makePropertySpecificKeyframeGroups(normalizeKeyframes([237 {left: '0px', top: '200px', opacity: 1},238 {left: '200px', top: '0px'},239 {left: '0px', top: '200px', opacity: 0},240 {top: '0px', opacity: 1},241 {left: '200px', top: '200px', opacity: 0}242 ]));243 });244 assert.equal(Object.getOwnPropertyNames(groups).length, 3);245 assert.equal(groups.left.length, 4);246 assert.closeTo(groups.left[0].offset, 0, 0.001);247 assert.equal(groups.left[0].value, '0px');248 assert.closeTo(groups.left[1].offset, 0.25, 0.001);249 assert.equal(groups.left[1].value, '200px');250 assert.closeTo(groups.left[2].offset, 0.5, 0.001);251 assert.equal(groups.left[2].value, '0px');252 assert.closeTo(groups.left[3].offset, 1, 0.001);253 assert.equal(groups.left[3].value, '200px');254 assert.equal(groups.top.length, 5);255 assert.closeTo(groups.top[0].offset, 0, 0.001);256 assert.equal(groups.top[0].value, '200px');257 assert.closeTo(groups.top[1].offset, 0.25, 0.001);258 assert.equal(groups.top[1].value, '0px');259 assert.closeTo(groups.top[2].offset, 0.5, 0.001);260 assert.equal(groups.top[2].value, '200px');261 assert.closeTo(groups.top[3].offset, 0.75, 0.001);262 assert.equal(groups.top[3].value, '0px');263 assert.closeTo(groups.top[4].offset, 1, 0.001);264 assert.equal(groups.top[4].value, '200px');265 assert.equal(groups.opacity.length, 4);266 assert.closeTo(groups.opacity[0].offset, 0, 0.001);267 assert.equal(groups.opacity[0].value, 1);268 assert.closeTo(groups.opacity[1].offset, 0.5, 0.001);269 assert.equal(groups.opacity[1].value, 0);270 assert.closeTo(groups.opacity[2].offset, 0.75, 0.001);271 assert.equal(groups.opacity[2].value, 1);272 assert.closeTo(groups.opacity[3].offset, 1, 0.001);273 assert.equal(groups.opacity[3].value, 0);274 });275 test('Make property specific keyframes when the offset of the last keyframe is specified but not equal to 1.', function() {276 assert.throws(function() {277 makePropertySpecificKeyframeGroups(normalizeKeyframes([278 {left: '0px', offset: 0},279 {left: '20px'},280 {left: '30px', offset: 0.9}281 ]));282 });283 });284 test('Make property specific keyframes when no properties are animated, and the offset of the last keyframe is specified but not equal to 1.', function() {285 var groups;286 assert.doesNotThrow(function() {287 groups = makePropertySpecificKeyframeGroups(normalizeKeyframes([288 {offset: 0},289 {},290 {offset: 0.9}291 ]));292 });293 assert.equal(Object.getOwnPropertyNames(groups).length, 0);294 });295 test('Make property specific keyframes when a property appears in some keyframes, but not in the last keyframe.', function() {296 assert.throws(function() {297 makePropertySpecificKeyframeGroups(normalizeKeyframes([298 {left: '0px', top: '0px'},299 {left: '10px', top: '10px'},300 {top: '20px'}301 ]));302 });303 });304 test('Make property specific keyframes when a property appears in some keyframes, but not in the first keyframe.', function() {305 assert.throws(function() {306 makePropertySpecificKeyframeGroups(normalizeKeyframes([307 {left: '0px'},308 {left: '10px', top: '10px'},309 {left: '20px', top: '20px'}310 ]));311 });312 });313 test('Make property specific keyframes where two properties are animated. One property in a keyframe with offset 1. One property in the last keyframe, with no offset.', function() {314 var groups;315 assert.doesNotThrow(function() {316 groups = makePropertySpecificKeyframeGroups(normalizeKeyframes([317 {left: '0px', top: '0px', offset: 0},318 {left: '20px', offset: 1},319 {top: '20px'}320 ]));321 });322 assert.equal(Object.getOwnPropertyNames(groups).length, 2);323 });324 test('Make property specific keyframes where two properties are animated. One property in a keyframe with offset 0. One property in the first keyframe, with no offset.', function() {325 var groups;326 assert.doesNotThrow(function() {327 groups = makePropertySpecificKeyframeGroups(normalizeKeyframes([328 {top: '0px'},329 {left: '0px', offset: 0},330 {left: '20px', top: '20px', offset: 1}331 ]));332 });333 assert.equal(Object.getOwnPropertyNames(groups).length, 2);334 });335 // Test per-keyframe easings.336 test('Apply keyframe easings.', function() {337 var target1 = document.createElement('div');338 var target2 = document.createElement('div');339 target1.style.position = 'absolute';340 target2.style.position = 'absolute';341 document.body.appendChild(target1);342 document.body.appendChild(target2);343 var player1 = target1.animate(344 [345 {left: '0px'},346 {left: '50px', offset: 0.25},347 {left: '0px'}348 ],349 {duration: 4000, fill: 'forwards'});350 var player2 = target2.animate(351 [352 {left: '0px', easing: 'ease-in'},353 {left: '50px', offset: 0.25},354 {left: '0px'}355 ],356 {duration: 4000, fill: 'forwards'});357 tick(0);358 assert.equal(leftAsNumber(target1), 0);359 assert.equal(leftAsNumber(target2), 0);360 tick(250);361 assert.closeTo(leftAsNumber(target1), 12.5, 1);362 assert.closeTo(leftAsNumber(target2), 4.65, 1);363 tick(500);364 assert.closeTo(leftAsNumber(target1), 25, 1);365 assert.closeTo(leftAsNumber(target2), 15.25, 1);366 tick(1000);367 assert.equal(leftAsNumber(target1), 50);368 assert.equal(leftAsNumber(target2), 50);369 tick(2500);370 assert.equal(leftAsNumber(target1), 25);371 assert.equal(leftAsNumber(target2), 25);372 tick(4000);373 assert.equal(leftAsNumber(target1), 0);374 assert.equal(leftAsNumber(target2), 0);375 });376 // Test makeInterpolations.377 test('Make interpolations for a simple effect with one property.', function() {378 var interpolations;379 assert.doesNotThrow(function() {380 interpolations = makeInterpolations(makePropertySpecificKeyframeGroups(normalizeKeyframes([381 {left: '0px'},382 {left: '200px', offset: 0.3},383 {left: '0px'}384 ])));385 });386 assert.equal(interpolations.length, 2);387 assert.closeTo(interpolations[0].startTime, 0, 0.001);388 assert.closeTo(interpolations[0].endTime, 0.3, 0.001);389 assert.equal(interpolations[0].property, 'left');390 assert.equal(typeof interpolations[0].interpolation, 'function');391 assert.closeTo(interpolations[1].startTime, 0.3, 0.001);392 assert.closeTo(interpolations[1].endTime, 1, 0.001);393 assert.equal(interpolations[1].property, 'left');394 assert.equal(typeof interpolations[1].interpolation, 'function');395 });396});397suite('effect-convertEffectInput', function() {398 setup(function() {399 this.target = document.createElement('div');400 this.target.style.position = 'absolute';401 document.documentElement.appendChild(this.target);402 });403 teardown(function() {404 if (this.target.parent)405 this.target.removeChild(this.target);406 });407 test('Convert effect input for a simple effect with one property.', function() {408 var effectFunction;409 assert.doesNotThrow(function() {410 effectFunction = webAnimationsMinifill.convertEffectInput([411 {left: '0px'},412 {left: '200px', offset: 0.3},413 {left: '100px'}414 ]);415 });416 effectFunction(this.target, 0);417 assert.closeTo(leftAsNumber(this.target), 0, 0.001);418 effectFunction(this.target, 0.075);419 assert.closeTo(leftAsNumber(this.target), 50, 0.001);420 effectFunction(this.target, 0.15);421 assert.closeTo(leftAsNumber(this.target), 100, 0.001);422 effectFunction(this.target, 0.65);423 assert.closeTo(leftAsNumber(this.target), 150, 0.001);424 effectFunction(this.target, 1);425 assert.closeTo(leftAsNumber(this.target), 100, 0.001);426 effectFunction(this.target, 2);427 assert.closeTo(leftAsNumber(this.target), -42.856, 0.01);428 });429 test('Convert effect input where one property is animated and the property has two keyframes at offset 1.', function() {430 var effectFunction;431 assert.doesNotThrow(function() {432 effectFunction = webAnimationsMinifill.convertEffectInput([433 {left: '0px', offset: 0},434 {left: '20px', offset: 1},435 {left: '30px'}436 ]);437 });438 effectFunction(this.target, 1);439 assert.equal(getComputedStyle(this.target).left, '30px');440 effectFunction(this.target, 2);441 assert.equal(getComputedStyle(this.target).left, '30px');...

Full Screen

Full Screen

TransformStatic.js

Source:TransformStatic.js Github

copy

Full Screen

...16 otherTransform.setFromMatrix(transform.worldTransform);17 const position = otherTransform.position;18 const scale = otherTransform.scale;19 const skew = otherTransform.skew;20 expect(position.x).to.be.closeTo(20, eps);21 expect(position.y).to.be.closeTo(10, eps);22 expect(scale.x).to.be.closeTo(2, eps);23 expect(scale.y).to.be.closeTo(3, eps);24 expect(skew.x).to.equal(0);25 expect(skew.y).to.equal(0);26 expect(otherTransform.rotation).to.be.closeTo(-5 * Math.PI / 6, eps);27 });28 it('should decompose mirror into skew', function ()29 {30 const eps = 1e-3;31 const transform = new PIXI.TransformStatic();32 const parent = new PIXI.TransformStatic();33 const otherTransform = new PIXI.TransformStatic();34 transform.position.set(20, 10);35 transform.scale.set(2, -3);36 transform.rotation = Math.PI / 6;37 transform.updateTransform(parent);38 otherTransform.setFromMatrix(transform.worldTransform);39 const position = otherTransform.position;40 const scale = otherTransform.scale;41 const skew = otherTransform.skew;42 expect(position.x).to.be.closeTo(20, eps);43 expect(position.y).to.be.closeTo(10, eps);44 expect(scale.x).to.be.closeTo(2, eps);45 expect(scale.y).to.be.closeTo(3, eps);46 expect(skew.x).to.be.closeTo(5 * Math.PI / 6, eps);47 expect(skew.y).to.be.closeTo(Math.PI / 6, eps);48 expect(otherTransform.rotation).to.equal(0);49 });50 it('should apply skew before scale, like in adobe animate and spine', function ()51 {52 // this example looks the same in CSS and in pixi, made with pixi-animate by @bigtimebuddy53 const eps = 1e-3;54 const transform = new PIXI.TransformStatic();55 const parent = new PIXI.TransformStatic();56 const otherTransform = new PIXI.TransformStatic();57 transform.position.set(387.8, 313.95);58 transform.scale.set(0.572, 4.101);59 transform.skew.set(-0.873, 0.175);60 transform.updateTransform(parent);61 const mat = transform.worldTransform;62 expect(mat.a).to.be.closeTo(0.563, eps);63 expect(mat.b).to.be.closeTo(0.100, eps);64 expect(mat.c).to.be.closeTo(-3.142, eps);65 expect(mat.d).to.be.closeTo(2.635, eps);66 expect(mat.tx).to.be.closeTo(387.8, eps);67 expect(mat.ty).to.be.closeTo(313.95, eps);68 otherTransform.setFromMatrix(transform.worldTransform);69 const position = otherTransform.position;70 const scale = otherTransform.scale;71 const skew = otherTransform.skew;72 expect(position.x).to.be.closeTo(387.8, eps);73 expect(position.y).to.be.closeTo(313.95, eps);74 expect(scale.x).to.be.closeTo(0.572, eps);75 expect(scale.y).to.be.closeTo(4.101, eps);76 expect(skew.x).to.be.closeTo(-0.873, eps);77 expect(skew.y).to.be.closeTo(0.175, eps);78 expect(otherTransform.rotation).to.be.equal(0);79 });80 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').assert;2assert.closeTo(1.5, 1, 0.5);3assert.closeTo(1.5, 1, 0.5, 'numbers are close');4var expect = require('chai').expect;5expect(1.5).to.be.closeTo(1, 0.5);6expect(1.5).to.be.closeTo(1, 0.5, 'numbers are close');7var should = require('chai').should();8(1.5).should.be.closeTo(1, 0.5);9(1.5).should.be.closeTo(1, 0.5, 'numbers are close');10var assert = require('chai').assert;11assert.closeTo(1.5, 1, 0.5);12assert.closeTo(1.5, 1, 0.5, 'numbers are close');13var expect = require('chai').expect;14expect(1.5).to.be.closeTo(1, 0.5);15expect(1.5).to.be.closeTo(1, 0.5, 'numbers are close');16var should = require('chai').should();17(1.5).should.be.closeTo(1, 0.5);18(1.5).should.be.closeTo(1, 0.5, 'numbers are close');19var assert = require('chai').assert;20assert.closeTo(1.5, 1, 0.5);21assert.closeTo(1.5, 1, 0.5, 'numbers are close');22var expect = require('chai').expect;23expect(1.5).to.be.closeTo(1, 0.5);24expect(1.5).to.be.closeTo(1, 0.5, 'numbers are close');

Full Screen

Using AI Code Generation

copy

Full Screen

1var chai = require('chai');2var expect = chai.expect;3describe('closeTo', function() {4 it('should return true', function() {5 expect(1.5).to.be.closeTo(1, 0.5);6 });7});8var chai = require('chai');9var expect = chai.expect;10describe('closeTo', function() {11 it('should return true', function() {12 expect(1.5).to.be.closeTo(1, 0.5);13 });14});15var chai = require('chai');16var expect = chai.expect;17describe('closeTo', function() {18 it('should return true', function() {19 expect(1.5).to.be.closeTo(1, 0.5);20 });21});22var chai = require('chai');23var expect = chai.expect;24describe('closeTo', function() {25 it('should return true', function() {26 expect(1.5).to.be.closeTo(1, 0.5);27 });28});29var chai = require('chai');30var expect = chai.expect;31describe('closeTo', function() {32 it('should return true', function() {33 expect(1.5).to.be.closeTo(1, 0.5);34 });35});36var chai = require('chai');37var expect = chai.expect;38describe('closeTo', function() {39 it('should return true', function() {40 expect(1.5).to.be.closeTo(1, 0.5);41 });42});43var chai = require('chai');44var expect = chai.expect;45describe('closeTo', function() {46 it('should return true', function() {47 expect(1.5).to.be.closeTo(1, 0.5);48 });49});50var chai = require('chai');51var expect = chai.expect;52describe('

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').assert;2var expect = require('chai').expect;3var should = require('chai').should();4var chai = require('chai');5var chaiAsPromised = require("chai-as-promised");6chai.use(chaiAsPromised);7chai.should();8chai.use(require('chai-things'));9chai.use(require('chai-subset'));10var sinon = require('sinon');11var sinonChai = require("sinon-chai");12chai.use(sinonChai);13describe('closeTo', function() {14 it('should test if the target is close to the value', function() {15 expect(1.5).to.be.closeTo(1, 0.5);16 expect(1.5).to.be.within(0.5, 1.5);17 expect(1.5).to.be.within(1, 2);18 expect(1.5).to.be.within(1.5, 2);19 expect(1.5).to.be.within(1, 1.5);20 expect(1.5).to.be.within(1, 1.5);21 expect(1.5).to.be.within(1.5, 2);22 });23});241 passing (14ms)

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = require('chai').expect;2describe('Test Suite', function() {3 it('Test Case', function() {4 expect(1.5).to.be.closeTo(1, 0.5);5 });6});71 passing (8ms)

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = require('chai').expect;2describe('closeTo method', function() {3 it('should return true if the number is close to the target', function() {4 expect(1.5).to.be.closeTo(1, 0.5);5 });6});7var expect = require('chai').expect;8describe('closeTo method', function() {9 it('should return true if the number is close to the target', function() {10 expect(1.5).to.be.closeTo(1, 0.5);11 });12});13var expect = require('chai').expect;14describe('closeTo method', function() {15 it('should return true if the number is close to the target', function() {16 expect(1.5).to.be.closeTo(1, 0.5);17 });18});19var expect = require('chai').expect;20describe('closeTo method', function() {21 it('should return true if the number is close to the target', function() {22 expect(1.5).to.be.closeTo(1, 0.5);23 });24});25var expect = require('chai').expect;26describe('closeTo method', function() {27 it('should return true if the number is close to the target', function() {28 expect(1.5).to.be.closeTo(1, 0.5);29 });30});31var expect = require('chai').expect;32describe('closeTo method', function() {33 it('should return true if the number is close to the target', function() {34 expect(1.5).to.be.closeTo(1, 0.5);35 });36});37var expect = require('chai').expect;38describe('closeTo method', function() {39 it('should return true if the number is close to the target', function() {40 expect(1.5).to.be.closeTo(1, 0.5

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = require('chai').expect;2var distance = require('../distance.js');3describe('distance', function() {4 it('returns the distance between two points', function() {5 var result = distance(0, 0, 1, 1);6 expect(result).to.be.closeTo(1.414, 0.001);7 });8});9function distance(x1, y1, x2, y2) {10 return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));11}12module.exports = distance;13var assert = require('chai').assert;14var distance = require('../distance.js');15describe('distance', function() {16 it('returns the distance between two points', function() {17 var result = distance(0, 0, 1, 1);18 assert.closeTo(result, 1.414, 0.001);19 });20});21function distance(x1, y1, x2, y2) {22 return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));23}24module.exports = distance;

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = require('chai').expect;2var assert = require('chai').assert;3describe('Test for closeTo method of chai', function() {4 it('should return true for closeTo method of chai', function() {5 expect(1.5).to.be.closeTo(1, 0.5);6 assert.closeTo(1.5, 1, 0.5);7 });8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('chai').assert;2const myApp = require('../app.js');3describe("App",function(){4 it("should return hello",function(){5 let result = myApp.sayHello();6 assert.equal(result,'hello');7 });8 it("should return type string",function(){9 let result = myApp.sayHello();10 assert.typeOf(result,'string');11 });12 it("should be greater than 5",function(){13 let result = myApp.addNumbers(5,5);14 assert.isAbove(result,5);15 });16 it("should return value within 5 of 10",function(){17 let result = myApp.addNumbers(5,5);18 assert.closeTo(result,10,5);19 });20 it("should return value within 5 of 10",function(){21 let result = myApp.addNumbers(5,5);22 assert.closeTo(result,10,5);23 });24 it("should return value within 5 of 10",function(){25 let result = myApp.addNumbers(5,5);26 assert.closeTo(result,10,5);27 });28 it("should return value within 5 of 10",function(){29 let result = myApp.addNumbers(5,5);30 assert.closeTo(result,10,5);31 });32 it("should return value within 5 of 10",function(){33 let result = myApp.addNumbers(5,5);34 assert.closeTo(result,10,5);35 });36 it("should return value within 5 of 10",function(){37 let result = myApp.addNumbers(5,5);38 assert.closeTo(result,10,5);39 });40 it("should return value within 5 of 10",function(){41 let result = myApp.addNumbers(5,5);42 assert.closeTo(result,10,5);43 });44 it("should return value within 5 of 10",function(){45 let result = myApp.addNumbers(5,5);46 assert.closeTo(result,10,5);47 });48 it("should return value within 5 of 10",function(){49 let result = myApp.addNumbers(5,5);50 assert.closeTo(result,10,5);51 });52 it("should return value within 5 of 10",function

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').assert;2var calc = require('../calc');3describe('Calc', function() {4 describe('add', function() {5 it('should return 4 when 2 and 2 are passed', function() {6 var result = calc.add(2, 2);7 assert.equal(result, 4);8 });9 });10 describe('subtract', function() {11 it('should return 2 when 4 and 2 are passed', function() {12 var result = calc.subtract(4, 2);13 assert.equal(result, 2);14 });15 });16 describe('multiply', function() {17 it('should return 8 when 4 and 2 are passed', function() {18 var result = calc.multiply(4, 2);19 assert.equal(result, 8);20 });21 });22 describe('divide', function() {23 it('should return 2 when 4 and 2 are passed', function() {24 var result = calc.divide(4, 2);25 assert.equal(result, 2);26 });27 });28});29var calc = {30 add: function(a, b) {31 return a + b;32 },33 subtract: function(a, b) {34 return a - b;35 },36 multiply: function(a, b) {37 return a * b;38 },39 divide: function(a, b) {40 return a / b;41 }42};43module.exports = calc;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run chai automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful