Best JavaScript code snippet using fast-check-monorepo
SchedulerArbitrary.spec.ts
Source:SchedulerArbitrary.spec.ts
1import { SchedulerArbitrary } from '../../../../src/arbitrary/_internals/SchedulerArbitrary';2import { fakeRandom } from '../__test-helpers__/RandomHelpers';3import * as SchedulerImplemMock from '../../../../src/arbitrary/_internals/implementations/SchedulerImplem';4import { ScheduledTask } from '../../../../src/arbitrary/_internals/implementations/SchedulerImplem';5function beforeEachHook() {6 jest.resetModules();7 jest.restoreAllMocks();8}9beforeEach(beforeEachHook);10describe('SchedulerArbitrary', () => {11 describe('generate', () => {12 it('should instanciate a SchedulerImplem on generate and clone the random generator', () => {13 // Arrange14 const act = jest.fn();15 const { instance: mrng, clone } = fakeRandom(); // random received by generate (risk to be altered from the outside so we clone it)16 const { instance: mrng1, clone: clone1 } = fakeRandom(); // random used by the first taskScheduler17 const { instance: mrng2 } = fakeRandom(); // random used by the clone of taskScheduler is needed18 clone.mockReturnValueOnce(mrng1);19 clone1.mockReturnValueOnce(mrng2);20 const fakeScheduler = {} as SchedulerImplemMock.SchedulerImplem<unknown>;21 const SchedulerImplem = jest.spyOn(SchedulerImplemMock, 'SchedulerImplem');22 SchedulerImplem.mockReturnValue(fakeScheduler);23 // Act24 const arb = new SchedulerArbitrary(act);25 const g = arb.generate(mrng, undefined);26 // Assert27 expect(g.value).toBe(fakeScheduler);28 expect(SchedulerImplem).toHaveBeenCalledTimes(1);29 expect(SchedulerImplem).toHaveBeenCalledWith(30 act,31 expect.objectContaining({ clone: expect.any(Function), nextTaskIndex: expect.any(Function) })32 );33 expect(clone).toHaveBeenCalledTimes(1);34 expect(clone1).toHaveBeenCalledTimes(1);35 });36 it('should build a taskScheduler pulling random values out of the cloned instance of Random', () => {37 // Arrange38 const act = jest.fn();39 const scheduledTasks = [{}, {}, {}, {}, {}, {}, {}, {}] as ScheduledTask<unknown>[];40 const { instance: mrng, clone } = fakeRandom();41 const { instance: mrng1, clone: clone1, nextInt } = fakeRandom();42 const { instance: mrng2 } = fakeRandom();43 clone.mockReturnValueOnce(mrng1);44 clone1.mockReturnValueOnce(mrng2);45 const fakeScheduler = {} as SchedulerImplemMock.SchedulerImplem<unknown>;46 const SchedulerImplem = jest.spyOn(SchedulerImplemMock, 'SchedulerImplem');47 SchedulerImplem.mockReturnValue(fakeScheduler);48 const arb = new SchedulerArbitrary(act);49 arb.generate(mrng, undefined);50 // Act51 const taskScheduler = SchedulerImplem.mock.calls[0][1];52 taskScheduler.nextTaskIndex(scheduledTasks);53 // Assert54 expect(nextInt).toHaveBeenCalledTimes(1);55 expect(nextInt).toHaveBeenCalledWith(0, scheduledTasks.length - 1);56 });57 it('should build a taskScheduler that can be cloned and create the same values', () => {58 // Arrange59 const act = jest.fn();60 const scheduledTasks = [{}, {}, {}, {}, {}, {}, {}, {}] as ScheduledTask<unknown>[];61 const { instance: mrng, clone } = fakeRandom();62 const { instance: mrng1, clone: clone1, nextInt } = fakeRandom();63 const { instance: mrng2, clone: clone2, nextInt: nextIntBis } = fakeRandom();64 const { instance: mrng3 } = fakeRandom();65 clone.mockReturnValueOnce(mrng1);66 clone1.mockImplementationOnce(() => {67 expect(nextInt).not.toHaveBeenCalled(); // if we pulled values clone is not a clone of the source68 return mrng2;69 });70 clone2.mockImplementationOnce(() => {71 expect(nextIntBis).not.toHaveBeenCalled(); // if we pulled values clone is not a clone of the source72 return mrng3;73 });74 nextInt.mockReturnValueOnce(5).mockReturnValueOnce(2);75 nextIntBis.mockReturnValueOnce(5).mockReturnValueOnce(2);76 const fakeScheduler = {} as SchedulerImplemMock.SchedulerImplem<unknown>;77 const SchedulerImplem = jest.spyOn(SchedulerImplemMock, 'SchedulerImplem');78 SchedulerImplem.mockReturnValue(fakeScheduler);79 const arb = new SchedulerArbitrary(act);80 arb.generate(mrng, undefined);81 // Act82 const taskScheduler = SchedulerImplem.mock.calls[0][1];83 const v1 = taskScheduler.nextTaskIndex(scheduledTasks);84 const v2 = taskScheduler.nextTaskIndex(scheduledTasks);85 const taskScheduler2 = taskScheduler.clone();86 const u1 = taskScheduler2.nextTaskIndex(scheduledTasks);87 const u2 = taskScheduler2.nextTaskIndex(scheduledTasks);88 // Assert89 expect(nextInt).toHaveBeenCalledTimes(2);90 expect(nextInt).toHaveBeenCalledWith(0, scheduledTasks.length - 1);91 expect(nextIntBis).toHaveBeenCalledTimes(2);92 expect(nextIntBis).toHaveBeenCalledWith(0, scheduledTasks.length - 1);93 expect(v1).toBe(u1);94 expect(v2).toBe(u2);95 });96 });97 describe('canShrinkWithoutContext', () => {98 it('should return false for any Scheduler received without any context (even for SchedulerImplem)', () => {99 // Arrange100 const act = jest.fn();101 // Act102 const arb = new SchedulerArbitrary(act);103 const out = arb.canShrinkWithoutContext(104 new SchedulerImplemMock.SchedulerImplem(act, { clone: jest.fn(), nextTaskIndex: jest.fn() })105 );106 // Assert107 expect(out).toBe(false);108 });109 it('should return false even for its own values', () => {110 // Arrange111 const act = jest.fn();112 const { instance: mrng, clone } = fakeRandom();113 const { instance: mrng1, clone: clone1 } = fakeRandom();114 const { instance: mrng2 } = fakeRandom();115 clone.mockReturnValueOnce(mrng1);116 clone1.mockReturnValueOnce(mrng2);117 // Act118 const arb = new SchedulerArbitrary(act);119 const g = arb.generate(mrng, undefined);120 const out = arb.canShrinkWithoutContext(g.value);121 // Assert122 expect(out).toBe(false);123 });124 });125 describe('shrink', () => {126 it('should always shrink to nil', () => {127 // Arrange128 const act = jest.fn();129 const { instance: mrng, clone } = fakeRandom();130 const { instance: mrng1, clone: clone1 } = fakeRandom();131 const { instance: mrng2 } = fakeRandom();132 clone.mockReturnValueOnce(mrng1);133 clone1.mockReturnValueOnce(mrng2);134 // Act135 const arb = new SchedulerArbitrary(act);136 const { value, context } = arb.generate(mrng, undefined);137 const shrinks = [...arb.shrink(value, context)];138 // Assert139 expect(shrinks).toHaveLength(0);140 });141 });...
Random.spec.ts
Source:Random.spec.ts
1import * as prand from 'pure-rand';2import * as fc from 'fast-check';3import { Random } from '../../../../src/random/generator/Random';4const MAX_SIZE = 2048;5describe('Random', () => {6 describe('next', () => {7 it('Should produce values within 0 and 2 ** n - 1', () =>8 fc.assert(9 fc.property(fc.integer(), fc.nat(31), fc.nat(MAX_SIZE), (seed, n, num) => {10 const mrng = new Random(prand.xorshift128plus(seed));11 for (let idx = 0; idx !== num; ++idx) {12 const v = mrng.next(n);13 if (v < 0 || v > (((1 << n) - 1) | 0)) return false;14 }15 return true;16 })17 ));18 });19 describe('nextInt', () => {20 it('Should produce values within the range', () =>21 fc.assert(22 fc.property(fc.integer(), fc.integer(), fc.integer(), fc.nat(MAX_SIZE), (seed, a, b, num) => {23 const mrng = new Random(prand.xorshift128plus(seed));24 const min = a < b ? a : b;25 const max = a < b ? b : a;26 for (let idx = 0; idx !== num; ++idx) {27 const v = mrng.nextInt(min, max);28 if (min > v || max < v) return false;29 }30 return true;31 })32 ));33 it('Should produce the same sequences given same seeds', () =>34 fc.assert(35 fc.property(fc.integer(), fc.nat(MAX_SIZE), (seed, num) => {36 const mrng1 = new Random(prand.xorshift128plus(seed));37 const mrng2 = new Random(prand.xorshift128plus(seed));38 for (let idx = 0; idx !== num; ++idx) if (mrng1.nextInt() !== mrng2.nextInt()) return false;39 return true;40 })41 ));42 });43 describe('nextDouble', () => {44 it('Should produce values within 0 and 1', () =>45 fc.assert(46 fc.property(fc.integer(), fc.nat(MAX_SIZE), (seed, num) => {47 const mrng = new Random(prand.xorshift128plus(seed));48 for (let idx = 0; idx !== num; ++idx) {49 const v = mrng.nextDouble();50 if (v < 0 || v >= 1) return false;51 }52 return true;53 })54 ));55 });56 describe('clone', () => {57 it('Should produce the same sequences', () =>58 fc.assert(59 fc.property(fc.integer(), fc.nat(MAX_SIZE), (seed, num) => {60 const mrng1 = new Random(prand.xorshift128plus(seed));61 const mrng2 = mrng1.clone();62 for (let idx = 0; idx !== num; ++idx) if (mrng1.nextInt() !== mrng2.nextInt()) return false;63 return true;64 })65 ));66 });...
precache-manifest.a99a8ddda518a225e5f7c453d0da578f.js
Source:precache-manifest.a99a8ddda518a225e5f7c453d0da578f.js
1self.__precacheManifest = (self.__precacheManifest || []).concat([2 {3 "revision": "12b9f0c467289ba919ecda7b4bf138de",4 "url": "/momentum/index.html"5 },6 {7 "revision": "15d9853062c75fc8fb89",8 "url": "/momentum/static/css/2.4707e12a.chunk.css"9 },10 {11 "revision": "df4ebd00298a8f8b7b50",12 "url": "/momentum/static/css/main.502c1ce3.chunk.css"13 },14 {15 "revision": "15d9853062c75fc8fb89",16 "url": "/momentum/static/js/2.ff5c5240.chunk.js"17 },18 {19 "revision": "0749163b59fbee32225059cb60c18af6",20 "url": "/momentum/static/js/2.ff5c5240.chunk.js.LICENSE.txt"21 },22 {23 "revision": "df4ebd00298a8f8b7b50",24 "url": "/momentum/static/js/main.d1ef2ca8.chunk.js"25 },26 {27 "revision": "dd5edded77f39b117d48",28 "url": "/momentum/static/js/runtime-main.de89ae0f.js"29 },30 {31 "revision": "938e334e398ce45a293bb064c3e35b04",32 "url": "/momentum/static/media/aft1.938e334e.jpg"33 },34 {35 "revision": "c1672133f22c4ee5096076882b9f353e",36 "url": "/momentum/static/media/aft2.c1672133.jpg"37 },38 {39 "revision": "77544be1b392fe2073f7d6d3615acbec",40 "url": "/momentum/static/media/aft3.77544be1.jpg"41 },42 {43 "revision": "c91881efaec8674511252aac34f1043a",44 "url": "/momentum/static/media/aft4.c91881ef.jpg"45 },46 {47 "revision": "c8d50e6e14376fd136696e5c5a7875ab",48 "url": "/momentum/static/media/evng1.c8d50e6e.jpg"49 },50 {51 "revision": "6e660a2904d2f78f025f42f1392d0f7e",52 "url": "/momentum/static/media/evng2.6e660a29.jpg"53 },54 {55 "revision": "acf901568208f8ae0aa9329415534723",56 "url": "/momentum/static/media/evng3.acf90156.jpg"57 },58 {59 "revision": "799f7b9e89fa647b7e98c3c5c2167922",60 "url": "/momentum/static/media/evng4.799f7b9e.jpg"61 },62 {63 "revision": "776b02c6442a789314bcf2295e2ea357",64 "url": "/momentum/static/media/mrng1.776b02c6.jpg"65 },66 {67 "revision": "b30227c46d19e7e44502e9924ff40deb",68 "url": "/momentum/static/media/mrng2.b30227c4.jpg"69 },70 {71 "revision": "8d4bcf576881795706035b81f8729b1c",72 "url": "/momentum/static/media/mrng3.8d4bcf57.jpg"73 }...
Using AI Code Generation
1import { mrng2 } from 'fast-check-monorepo';2const mrng = mrng2();3console.log(mrng.nextInt());4{5 "dependencies": {6 }7}
Using AI Code Generation
1import * as fc from 'fast-check';2const mrng = fc.mrng2();3const next = mrng.nextInt();4const nextFloat = mrng.nextFloat();5const nextBoolean = mrng.nextBoolean();6const nextArray = mrng.nextArray(10);7const nextString = mrng.nextString(10);8const nextString = mrng.nextString(10, 20);9const nextString = mrng.nextString(10, 20, 'abc');10const nextString = mrng.nextString(10, 20, 'abc', true);11const nextString = mrng.nextString(10, 20, 'abc', true, true);12const nextString = mrng.nextString(10, 20, 'abc', true, true, true);13const nextString = mrng.nextString(10, 20, 'abc', true, true, true, true);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!