Best JavaScript code snippet using fast-check-monorepo
NumberKeyMap.ts
Source:NumberKeyMap.ts
1/**2 * @Dictionary.ts3 * @author sodaChen mail:asframe@qq.com4 * @version 1.05 * <br> Copyright (c) 2012-present, asframe.com6 * <br>Program Name:ASFrameTS7 * <br>Date:2017/1/198 */9namespace asf10{11 /**12 * numberä½ä¸ºkeyçåå
¸å¯¹è±¡ï¼æ¯ææ°ååvalueçç»å®ï¼åªæ¯ænumber对象ä½ä¸ºkeyãå
é¨ä½¿ç¨äºArrayæ¥å®ç°ãæ¯ä¸ªæ°åkeyæ¯ä¸æ ã13 * 使ç¨è¿ä¸ªæ°ç»ç容å¨å¯¹è±¡å¿
须注æï¼å®¹å¨æ¯æ°ç»ï¼ä½æ¯æçä¸è¡¨ä¸é¢å¯è½æ¯nullæè
undefind14 */15 export class NumberKeyMap<V> implements IMap< Number, V>16 {17 /** éåçé¿åº¦(éå
é¨æ°ç»é¿åº¦) **/18 public length:number;19 /**20 * numbereyæ¯æ°ç»çä¸æ ï¼å¯¹åºçæ¯value21 */22 private $keyValues: V[];23 public constructor()24 {25 this.clear();26 }27 put(k:number, v: V): void28 {29 let value:V = this.$keyValues[k];30 if (!value)31 {32 //keyä¸è¡¨æ²¡æ对åºçvuleï¼é¿åº¦æå¢å 33 this.length++;34 }35 //ç´æ¥åæ¾36 this.$keyValues[k] = v;37 }38 get(k:number): V39 {40 return this.$keyValues[k];41 }42 remove(k:any): V43 {44 var v: V = this.$keyValues[k];45 if(v)46 {47 this.$keyValues.splice(k, 1);48 this.length--;49 }50 return v;51 }52 indexOf(key:number): number53 {54 if(this.$keyValues[key])55 return key;56 return -1;57 }58 /**59 * å¦ææ¤æ å°æªå
å«é®-å¼æ å°å
³ç³»ï¼åè¿å true.60 * @return å¦ææ¤æ å°æªå
å«é®-å¼æ å°å
³ç³»ï¼åè¿å true.61 */62 isEmpty(): boolean63 {64 return this.length == 0;65 }66 /**67 * å¦ææ¤æ å°å
å«æå®é®çæ å°å
³ç³»ï¼åè¿å true.68 * @param numberey æµè¯å¨æ¤æ å°ä¸æ¯å¦åå¨çé®.69 * @return å¦ææ¤æ å°å
å«æå®é®çæ å°å
³ç³»ï¼åè¿å true.70 */71 hasKey(key:number): boolean72 {73 if(this.$keyValues[key])74 return true;75 return false;76 }77 /**78 * å¦æ该æ å°å°ä¸ä¸ªæå¤ä¸ªé®æ å°å°æå®å¼ï¼åè¿å true.79 * @param numberey æµè¯å¨è¯¥æ å°ä¸æ¯å¦åå¨çå¼80 * @return å¦æ该æ å°å°ä¸ä¸ªæå¤ä¸ªé®æ å°å°æå®å¼ï¼åè¿å true.81 */82 hasValue(value: V):boolean83 {84 return this.$keyValues.indexOf(value) != -1;85 }86 size(): number87 {88 return this.length;89 }90 keys(copy: boolean = true):number[]91 {92 let keyValues:V[] = this.$keyValues;93 let len: number = keyValues.length;94 let ary:number[] = [];95 for(let i: number = 0; i < len; i++)96 {97 if(keyValues[i])98 ary.push(i);99 }100 return ary;101 }102 values(copy: boolean = true): V[]103 {104 let keyValues:V[] = this.$keyValues;105 let len: number = keyValues.length;106 let values:V[] = [];107 for(let i: number = 0; i < len; i++)108 {109 if(keyValues[i])110 values.push(keyValues[i]);111 }112 return values;113 }114 forEach(fun:Function,thisObj:Object): void115 {116 let keyValues:V[] = this.$keyValues;117 let len: number = keyValues.length;118 for (let i: number = 0; i < len; i++)119 {120 if(keyValues[i])121 fun.call(thisObj,keyValues[i]);122 }123 }124 forKeyValue(fun:Function,thisObj:Object): void125 {126 let keyValues:V[] = this.$keyValues;127 let len: number = keyValues.length;128 for (let i: number = 0; i < len; i++)129 {130 if(keyValues[i])131 fun.call(thisObj,i,keyValues[i]);132 }133 }134 /**135 * @inheritDoc136 */137 getContainer(): Object138 {139 return this.$keyValues;140 }141 clear(): void142 {143 this.length = 0;144 this.$keyValues = [];145 }146 destroy(o?: any): void147 {148 let keyValues:V[] = this.$keyValues;149 let len: number = keyValues.length;150 for (let i: number = 0; i < len; i++)151 {152 if(keyValues[i])153 DestroyUtils.destroy(keyValues[i]);154 }155 delete this.$keyValues;156 }157 }...
testValidateRsaKeypair.js
Source:testValidateRsaKeypair.js
1const util = require('../helpers/util');2const { LOCKBOX } = require('../helpers/data');3const Challenge = artifacts.require('Challenge');4describe('validateRsaKeypair', () => {5 let challenge;6 before(async () => {7 challenge = await Challenge.deployed();8 });9 contract('Challenge', () => {10 const keyValues = util.decomposeRSAKey(LOCKBOX.requestPublicKey, LOCKBOX.requestPrivateKey);11 it('correctly validates a valid key', async () => {12 const isValid = await challenge.validateRsaKeypairTestOnly([keyValues.n, keyValues.e], [keyValues.d, keyValues.p, keyValues.q, keyValues.qInv]);13 expect(isValid).to.equal(true);14 });15 it('errors on too-large prime values', async () => {16 await util.expectThrow(17 challenge.validateRsaKeypairTestOnly([keyValues.n, keyValues.e], [keyValues.d, keyValues.n, keyValues.q, keyValues.qInv]),18 'prime is incorrect size',19 );20 await util.expectThrow(21 challenge.validateRsaKeypairTestOnly([keyValues.n, keyValues.e], [keyValues.d, keyValues.p, keyValues.n, keyValues.qInv]),22 'prime is incorrect size',23 );24 });25 it('detects non-prime p and q', async () => {26 await util.expectThrow(27 challenge.validateRsaKeypairTestOnly([keyValues.n, keyValues.e], [keyValues.d, util.numberToSolidityBigNumHex(keyValues.p - 1), util.numberToSolidityBigNumHex(keyValues.q - 1), keyValues.qInv]),28 'invalid keypair',29 );30 await util.expectThrow(31 challenge.validateRsaKeypairTestOnly([keyValues.n, keyValues.e], [keyValues.d, util.numberToSolidityBigNumHex(keyValues.p - 1), keyValues.q, keyValues.qInv]),32 'invalid keypair',33 );34 // TODO: uncomment this test when the is_prime issue in BigNumber is fixed35 // await util.expectThrow(36 // challenge.validateRsaKeypairTestOnly([keyValues.n, keyValues.e], [keyValues.d, keyValues.p, util.numberToSolidityBigNumHex(keyValues.q-1), keyValues.qInv]),37 // 'invalid keypair'38 // )39 });40 it('detects invalid e', async () => {41 await util.expectThrow(42 challenge.validateRsaKeypairTestOnly([keyValues.n, util.numberToSolidityBigNumHex(1)], [keyValues.d, keyValues.p, keyValues.q, keyValues.qInv]),43 'invalid keypair',44 );45 await util.expectThrow(46 challenge.validateRsaKeypairTestOnly([keyValues.n, util.numberToSolidityBigNumHex(65536)], [keyValues.d, keyValues.p, keyValues.q, keyValues.qInv]),47 'invalid keypair',48 );49 });50 it('detects invalid d', async () => {51 await util.expectThrow(52 challenge.validateRsaKeypairTestOnly([keyValues.n, keyValues.e], [util.numberToSolidityBigNumHex(2034895729038475), keyValues.p, keyValues.q, keyValues.qInv]),53 'invalid keypair',54 );55 });56 it('detects invalid n', async () => {57 await util.expectThrow(58 challenge.validateRsaKeypairTestOnly([util.numberToSolidityBigNumHex(927384658237), keyValues.e], [keyValues.d, keyValues.p, keyValues.q, keyValues.qInv]),59 'invalid keypair',60 );61 });62 it('detects invalid qInv', async () => {63 await util.expectThrow(64 challenge.validateRsaKeypairTestOnly([keyValues.n, keyValues.e], [keyValues.d, keyValues.p, keyValues.q, util.numberToSolidityBigNumHex(2098347593)]),65 'not an inverse',66 );67 });68 });...
testMultiKey.js
Source:testMultiKey.js
1var MultiKeyStore = require('..');2var i;3var item;4var keyNames;5var keyValues;6var result;7var store;8var walker;9console.log('====== create store =======');10keyNames = ['city', 'name'];11store = new MultiKeyStore(keyNames);12console.log('====== add items =======');13item = {14 name: 'bob'15 , city: 'nyc'16 , data: 'this is bob in nyc'17};18store.addItem(item);19item = {20 name: 'sam'21 , city: 'nyc'22 , data: 'this is sam in nyc'23};24store.addItem(item);25item = {26 name: 'sally'27 , city: 'sf'28 , data: 'this is sally in nyc'29};30store.addItem(item);31store.addItem(item);32item = {33 name: 'sue'34 , city: 'sf'35 , data: 'this is sue in sf'36};37store.addItem(item);38console.log('\n====== walk =======');39walker = store.getWalker();40i = 0;41while (item = walker.getNextItem()) {42 console.log(i, item);43 i += 1;44 if (i > 5) {45 process.exit(); 46 }47}48console.log('\n====== getItemForKeyValues =======');49keyValues = {city: 'sf', name: 'sue'};50item = store.getItemForKeyValues(keyValues);51console.log(keyValues, '==>', item);52keyValues = {city: 'nyc', name: 'sam'};53item = store.getItemForKeyValues(keyValues);54console.log(keyValues, '==>', item);55keyValues = {city: 'sf', name: 'sam'};56item = store.getItemForKeyValues(keyValues);57console.log(keyValues, '==>', item);58console.log('\n====== removeItemWithKeyValues =======');59keyValues = {city: 'sf', name: 'sam'};60result = store.removeItemWithKeyValues(keyValues);61console.log('delete', keyValues, '==>', result);62keyValues = {city: 'sf', name: 'sue'};63result = store.removeItemWithKeyValues(keyValues);64console.log('delete', keyValues, '==>', result);65keyValues = {city: 'sf', name: 'sue'};66item = store.getItemForKeyValues(keyValues);67console.log('get', keyValues, '==>', item);68keyValues = {city: 'nyc', name: 'sam'};69result = store.removeItemWithKeyValues(keyValues);70console.log('delete', keyValues, '==>', result);71keyValues = {city: 'nyc', name: 'bob'};72result = store.removeItemWithKeyValues(keyValues);73console.log('delete', keyValues, '==>', result);74console.log('\n====== walk =======');75walker.reset();76i = 0;77while (item = walker.getNextItem()) {78 console.log(i, item);79 i += 1;80 if (i > 5) {81 process.exit(); 82 }...
Using AI Code Generation
1import { keyValues } from 'fast-check';2const arb = keyValues({ a: string(), b: string() });3fc.assert(4 fc.property(arb, (obj) => {5 return true;6 })7);
Using AI Code Generation
1import { keyValues } from 'fast-check/lib/check/arbitrary/MapArbitrary';2const mapArbitrary = keyValues(3 fc.integer(),4 fc.string()5);6fc.assert(7 fc.property(8 (map) => {9 expect(map).toBeInstanceOf(Map);10 for (let [key, value] of map) {11 expect(typeof key).toBe('number');12 expect(typeof value).toBe('string');13 }14 }15);
Using AI Code Generation
1const fc = require('fast-check');2const { generate } = require('fast-check-monorepo');3const keyValues = generate.keyValues;4const gen = fc.array(keyValues(fc.string(), fc.integer()));5fc.assert(fc.property(gen, (obj) => {6 Object.keys(obj).length > 0;7}));8const fc = require('fast-check');9const { generate } = require('fast-check-monorepo');10const keyValues = generate.keyValues;11const gen = fc.array(keyValues(fc.string(), fc.integer()));12fc.assert(fc.property(gen, (obj) => {13 Object.keys(obj).length > 0;14}));15const fc = require('fast-check');16const { generate } = require('fast-check-monorepo');17const keyValues = generate.keyValues;18const gen = fc.array(keyValues(fc.string(), fc.integer()));19fc.assert(fc.property(gen, (obj) => {20 Object.keys(obj).length > 0;21}));22const fc = require('fast-check');23const { generate } = require('fast-check-monorepo');24const keyValues = generate.keyValues;25const gen = fc.array(keyValues(fc.string(), fc.integer()));26fc.assert(fc.property(gen, (obj) => {27 Object.keys(obj).length > 0;28}));29const fc = require('fast-check');30const { generate } = require('fast-check-monorepo');31const keyValues = generate.keyValues;32const gen = fc.array(keyValues(fc.string(), fc.integer()));33fc.assert(fc.property(gen, (obj) => {34 Object.keys(obj).length > 0;35}));36const fc = require('fast-check');37const { generate } = require('fast-check-monorepo');38const keyValues = generate.keyValues;39const gen = fc.array(keyValues(fc.string(), fc.integer()));40fc.assert(fc.property(gen, (obj) => {41 Object.keys(obj).length > 0;42}));
Using AI Code Generation
1const { keyValues } = require('fast-check-monorepo');2const { assert } = require('chai');3const { isDeepStrictEqual } = require('util');4describe('keyValues', () => {5 it('should use the keyValues method', () => {6 assert(isDeepStrictEqual(keyValues({ a: 1, b: 2 }), [['a', 1], ['b', 2]]));7 });8});9{10 "scripts": {11 },12 "dependencies": {13 }14}
Using AI Code Generation
1const {keyValues} = require('fast-check');2keyValues({3 a: fc.integer(),4 b: fc.integer()5}).forEach(console.log);6{ a: 1, b: 2 }7{ a: 1, b: 3 }8{ a: 1, b: 4 }9{ a: 1, b: 5 }10{ a: 2, b: 2 }11{ a: 2, b: 3 }12{ a: 2, b: 4 }13{ a: 2, b: 5 }14{ a: 3, b: 2 }15{ a: 3, b: 3 }16{ a: 3, b: 4 }17{ a: 3, b: 5 }18{ a: 4, b: 2 }19{ a: 4, b: 3 }20{ a: 4, b: 4 }21{ a: 4, b: 5 }22{ a: 5, b: 2 }23{ a: 5, b: 3 }24{ a: 5, b: 4 }25{ a: 5, b: 5 }
Using AI Code Generation
1const keyValue = require('fast-check-monorepo/keyValues');2const {check} = require('fast-check');3check(keyValue(),(keyValues) => {4 return true;5});6const keyValue = require('fast-check-monorepo/keyValue');7const {check} = require('fast-check');8check(keyValue(),(keyValue) => {9 return true;10});11const key = require('fast-check-monorepo/key');12const {check} = require('fast-check');13check(key(),(key) => {14 return true;15});16const value = require('fast-check-monorepo/value');17const {check} = require('fast-check');18check(value(),(value) => {19 return true;20});21const array = require('fast-check-monorepo/array');22const {check} = require('fast-check');23check(array(),(array) => {24 return true;25});26const boolean = require('fast-check-monorepo/boolean');27const {check} = require('fast-check');28check(boolean(),(boolean) => {29 return true;30});31const date = require('fast-check-monorepo/date');32const {check} = require('fast-check');33check(date(),(date) => {34 return true;35});36const float = require('fast-check-monorepo/float');37const {check} = require('fast-check');38check(float(),(float) => {39 return true;40});
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!!