How to use resolvedComparator method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

uniqueArray.spec.ts

Source:uniqueArray.spec.ts Github

copy

Full Screen

...265 const selected = resolvedSelector(v); // either v (integer in 0..sampleSize) or an integer (by construct of selector)266 sampledSelectedValues.add(selected);267 selectorEnabled = selectorEnabled || sampledSelectedValues.size >= requestedMin;268 if (!comparatorEnabled && comparator !== undefined) {269 if (sampledSelectedAndComparedValues.every((p) => !resolvedComparator(p, selected))) {270 // Selected is "different" from all the other known values271 sampledSelectedAndComparedValues.push(selected);272 comparatorEnabled = comparatorEnabled || sampledSelectedAndComparedValues.length >= requestedMin;273 selectorEnabled = selectorEnabled || comparatorEnabled; // comparator enabled unlocks selector too274 }275 }276 }277 return {278 minLength: withMin ? min : undefined,279 maxLength: withMax ? min + gap : undefined,280 selector: selectorEnabled ? selector : undefined,281 comparator: comparatorEnabled ? comparator : undefined,282 };283 });284 const isCorrect = (value: number[], extra: Extra) => {285 if (extra.minLength !== undefined) {286 expect(value.length).toBeGreaterThanOrEqual(extra.minLength);287 }288 if (extra.maxLength !== undefined) {289 expect(value.length).toBeLessThanOrEqual(extra.maxLength);290 }291 for (const v of value) {292 expect(typeof v).toBe('number');293 }294 const resolvedSelector = resolveSelectorFunction(extra.selector);295 const resolvedComparator = resolveComparatorFunction(extra.comparator);296 const alreadySeen: unknown[] = [];297 for (const v of value) {298 const selected = resolvedSelector(v);299 const matchingEntry = alreadySeen.some((e) => resolvedComparator(e, selected));300 expect(matchingEntry).toBe(false);301 alreadySeen.push(selected);302 }303 };304 const integerUpTo10000AndNaNOrMinusZero = new FakeIntegerArbitrary(-2, 10000).map(305 (v) => (v === -2 ? Number.NaN : v === -1 ? -0 : v),306 (v) => {307 if (typeof v !== 'number' || v === -1 || v === -2) throw new Error('');308 return Object.is(v, Number.NaN) ? -2 : Object.is(v, -0) ? -1 : v;309 }310 );311 const uniqueArrayBuilder = (extra: Extra) => uniqueArray(integerUpTo10000AndNaNOrMinusZero, extra);312 it('should produce the same values given the same seed', () => {313 assertProduceSameValueGivenSameSeed(uniqueArrayBuilder, { extraParameters });...

Full Screen

Full Screen

selectors.js

Source:selectors.js Github

copy

Full Screen

1import _ from 'lodash'2import { createSelector } from 'reselect'3import { $ships, $shipTypes } from './master-data.js'4import { filters } from './ship-filters'5import {6 expedInfoList,7 applyIncomeModifier,8 computeResupplyInfo,9 onResourceValue,10 resourceProperties,11 allExpedIdList,12} from './exped-info'13import { defExpedConfig } from './store/reducer/exped-configs'14import { i18nInstances } from './i18n'15const shipListSelector = state => state.shipList16const expedConfigsSelector = state => state.expedConfigs17const uiSelector = state => state.ui18const languageSelector = state => state.language19const currentTabSelector = createSelector(20 uiSelector,21 ui => ui.currentTab)22const dlcLabUISelector = createSelector(23 uiSelector,24 ui => ui.dlcLab)25const shipResupplyCost = ship => {26 // "after marriage modifier":27 // - if there's no consumption before marriage, no consumption applied after marriage either.28 // - consumption is applied with 0.85 and then floor is taken, with a minimum cost of 129 const applyAfterMarriage =30 v => (v === 0) ? 0 : Math.max(1, Math.floor(v*0.85))31 const modifier = ship.ring ? applyAfterMarriage : _.identity32 return (fuelCostFactor, ammoCostFactor) => {33 const fuelCost = Math.floor( ship.maxFuel * fuelCostFactor )34 const ammoCost = Math.floor( ship.maxAmmo * ammoCostFactor )35 return {36 fuelCost: modifier(fuelCost),37 ammoCost: modifier(ammoCost),38 }39 }40}41const shipDetailListSelector = createSelector(42 shipListSelector,43 shipList => {44 const shipToDetail = ship => {45 const {ring, rosterId} = ship46 const masterId = ship.id47 const $ship = $ships[masterId]48 if (!$ship)49 return null50 const stype = $ship.api_stype51 const shipName = $ship.api_name52 const typeName = $shipTypes[stype].api_name53 const maxFuel = $ship.api_fuel_max54 const maxAmmo = $ship.api_bull_max55 return {56 masterId,57 rosterId,58 stype,59 typeName,60 shipName,61 ring,62 computeCost: shipResupplyCost({ring,maxFuel,maxAmmo}),63 }64 }65 const shipDetailList = _.compact(shipList.map(shipToDetail))66 return shipDetailList67 })68const shipCostListByFilterSelector = createSelector(69 shipDetailListSelector,70 shipDetailList => {71 const mkPair = filterInfo => {72 const {id,func} = filterInfo73 const filteredShipList = shipDetailList74 .filter(func)75 return [id, filteredShipList]76 }77 const shipCostListByFilter = _.fromPairs(filters.map(mkPair))78 return shipCostListByFilter79 })80const scan = (xs, acc, zero) => {81 const ys = new Array(xs.length+1)82 ys[0] = zero83 for (let i=0; i<xs.length; ++i) {84 ys[i+1] = acc(ys[i],xs[i])85 }86 return ys87}88/*89 costModel is a function:90 - costModel(<CostPercent>)(<ShipType>,<Count>) = <ActualCost>91 - CostPercent: {fuelPercent, ammoPercent}, where both fuelPercent and ammoPercent92 are integers between 0~100 (inclusive)93 - ShipType: ship filter id94 - Count: an integer >= 095 - ActualCost:96 - {fuelCost, ammoCost} (might include other fields like 'fleet')97 - or null if the number of qualified ships is not sufficient98 TODO:99 - consider memoize if necessary100 */101const costModelSelector = createSelector(102 shipCostListByFilterSelector,103 shipCostListByFilter => {104 // filterId is ShipType.105 const costModel = ({fuelPercent, ammoPercent}) => (filterId,count) => {106 const fuelCostFactor = fuelPercent / 100107 const ammoCostFactor = ammoPercent / 100108 // sort by cost lowest cost109 const shipCostListWithDup =110 shipCostListByFilter[filterId]111 .map(s => {112 const {fuelCost, ammoCost} = s.computeCost(fuelCostFactor,ammoCostFactor)113 return {...s, fuelCost, ammoCost, fleet: [s]}114 })115 .sort((x,y) => (x.fuelCost+x.ammoCost) - (y.fuelCost+y.ammoCost))116 // remove duplication117 const shipCostList = []118 {119 const masterIdSet = new Set()120 for (let i=0; i<shipCostListWithDup.length; ++i) {121 const ship = shipCostListWithDup[i]122 if (masterIdSet.has(ship.masterId))123 continue124 shipCostList.push(ship)125 masterIdSet.add(ship.masterId)126 }127 }128 const plusCost = (x,y) => ({129 fuelCost: x.fuelCost + y.fuelCost,130 ammoCost: x.ammoCost + y.ammoCost,131 fleet: [...x.fleet, ...y.fleet],132 })133 const accumulatedCostList = scan(134 shipCostList,135 plusCost,136 {fuelCost: 0, ammoCost: 0, fleet: []})137 return accumulatedCostList.length > count ? accumulatedCostList[count] : null138 }139 return costModel140 })141const tableUISelector = createSelector(142 uiSelector,143 ui => ui.table)144const plannerSelector = createSelector(145 uiSelector,146 ui => ui.planner)147const plannerConfigSelector = createSelector(148 plannerSelector,149 planner => planner.config)150const plannerResultsSelector = createSelector(151 plannerSelector,152 planner => planner.results)153const expedViewSortFunctionSelector = createSelector(154 tableUISelector,155 tableControl => {156 const sortSpec = tableControl.sort157 const idGetter = expedView => expedView.id158 const timeGetter = expedView => expedView.info.time159 const resourceGetter = rp =>160 expedView => {161 const v = expedView.showResource[rp]162 return v === null ? -Infinity : v163 }164 const getterToComparator = (getter, flip=false) =>165 (x,y) => {166 const xVal = getter(x)167 const yVal = getter(y)168 return flip ? yVal-xVal : xVal-yVal169 }170 const idComparator = getterToComparator(idGetter)171 /* eslint-disable indent */172 const comparator =173 sortSpec.method === 'id' ?174 idComparator :175 sortSpec.method === 'time' ?176 getterToComparator(timeGetter) :177 resourceProperties.includes(sortSpec.method) ?178 getterToComparator(resourceGetter(sortSpec.method),true) :179 console.error(`unknown sort method: ${sortSpec.method}`)180 /* eslint-enable indent */181 // use idComparator as tiebreaker182 const resolvedComparator = (x,y) => {183 const result = comparator(x,y)184 return result === 0 ? idComparator(x,y) : result185 }186 return xs => {187 let ys = [...xs]188 ys = ys.sort(resolvedComparator)189 if (sortSpec.reversed)190 ys = ys.reverse()191 return ys192 }193 })194const makeExpedIncomeSelector = expedId => createSelector(195 expedConfigsSelector,196 costModelSelector,197 (expedConfigs, costModel) => {198 const id = expedId199 const info = expedInfoList.find(ei => ei.id === id)200 if (!info) {201 return {202 basic: null, gross: null, net: null, resupplyInfo: null,203 }204 }205 const {cost} = info206 const costModelPartial = costModel(cost)207 const basic = info.resource208 // TODO: serves as a tmp fix209 const config = expedConfigs[expedId] || defExpedConfig210 const gross =211 applyIncomeModifier(config.modifier)(basic)212 const resupplyInfo =213 computeResupplyInfo(config.cost)(info,costModelPartial)214 const applyResupply = (val, rp) => {215 if (rp === 'fuel' || rp === 'ammo') {216 if (!resupplyInfo || resupplyInfo.cost === null)217 return null218 return val - resupplyInfo.cost[rp]219 } else {220 return val221 }222 }223 const net = onResourceValue(applyResupply)(gross)224 return {225 basic,226 gross,227 net,228 resupplyInfo,229 }230 })231const expedIncomesSelector = createSelector(232 allExpedIdList.map(makeExpedIncomeSelector),233 (...incomes) => _.fromPairs(_.zip(allExpedIdList,incomes)))234// expedition info for viewing on exped table UI235const expedInfoViewListSelector = createSelector(236 expedConfigsSelector,237 tableUISelector,238 expedIncomesSelector,239 expedViewSortFunctionSelector,240 (expedConfigs, tableControl, expedIncomes, sortFunc) => {241 const incomeViewMethod = tableControl.view.income242 const divideMethod = tableControl.view.divide243 const expedInfoViewList = expedInfoList.map(info => {244 const {id} = info245 const config = expedConfigs[id] || defExpedConfig246 const expedIncome = expedIncomes[id]247 const {resupplyInfo} = expedIncome248 const showResourceTotal =249 ['basic','gross','net'].includes(incomeViewMethod) ?250 expedIncome[incomeViewMethod] :251 console.error(`unknown income view method: ${incomeViewMethod}`)252 const resourceDivide = val =>253 val === null ? null : (val*60/info.time)254 /* eslint-disable indent */255 const showResource =256 divideMethod === 'total' ?257 showResourceTotal :258 divideMethod === 'hourly' ?259 onResourceValue(resourceDivide)(showResourceTotal) :260 console.error(`unknown divide method: ${divideMethod}`)261 /* eslint-enable indent */262 return {263 id,264 info,265 config,266 showResource,267 resupplyInfo,268 }269 })270 return sortFunc(expedInfoViewList)271 })272// provide `tr` and `trN` function according to language273const translateSelector = createSelector(274 languageSelector,275 lang => {276 const i18nInst = i18nInstances[lang]277 const tr = i18nInst.__.bind(i18nInst)278 const trN = i18nInst.__n.bind(i18nInst)279 return {tr, trN}280 })281const costPickerSelector = createSelector(282 uiSelector,283 ui => ui.costPicker)284const shipListUISelector = createSelector(285 uiSelector,286 ui => ui.shipList)287export {288 shipDetailListSelector,289 shipCostListByFilterSelector,290 costModelSelector,291 expedConfigsSelector,292 uiSelector,293 currentTabSelector,294 dlcLabUISelector,295 tableUISelector,296 plannerConfigSelector,297 plannerResultsSelector,298 makeExpedIncomeSelector,299 expedIncomesSelector,300 expedInfoViewListSelector,301 languageSelector,302 translateSelector,303 costPickerSelector,304 shipListSelector,305 shipListUISelector,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { resolvedComparator } from 'fast-check-monorepo';2import { resolvedComparator } from 'fast-check';3import { resolvedComparator } from 'fast-check-monorepo/src/comparator/ResolvedComparator';4import { resolvedComparator } from 'fast-check/src/comparator/ResolvedComparator';5import { resolvedComparator } from 'fast-check-monorepo/src/comparator/ResolvedComparator.js';6import { resolvedComparator } from 'fast-check/src/comparator/ResolvedComparator.js';7import { resolvedComparator } from 'fast-check-monorepo/dist/comparator/ResolvedComparator';8import { resolvedComparator } from 'fast-check/dist/comparator/ResolvedComparator';9import { resolvedComparator } from 'fast-check-monorepo/dist/comparator/ResolvedComparator.js';10import { resolvedComparator } from 'fast-check/dist/comparator/ResolvedComparator.js';11import { resolvedComparator } from 'fast-check-monorepo/lib/comparator/ResolvedComparator';12import { resolvedComparator } from 'fast-check/lib/comparator/ResolvedComparator';13import { resolvedComparator } from 'fast-check-monorepo/lib/comparator/ResolvedComparator.js';14import { resolvedComparator } from 'fast-check/lib/comparator/ResolvedComparator.js';15import { resolvedComparator } from 'fast-check-monorepo/es/comparator/ResolvedComparator';16import { resolvedComparator } from 'fast-check/es/comparator/ResolvedComparator';17import { resolvedComparator } from 'fast-check-monorepo/es/comparator/ResolvedComparator.js';18import { resolvedComparator } from 'fast-check/es/comparator/ResolvedComparator.js';

Full Screen

Using AI Code Generation

copy

Full Screen

1const resolvedComparator = require('fast-check').resolvedComparator;2const fc = require('fast-check');3const compare = (a, b) => {4 if (a === b) {5 return 0;6 }7 if (a < b) {8 return -1;9 }10 return 1;11};12const compareWithResolvedComparator = (a, b) =>13 resolvedComparator(compare, a, b);14const compareWithResolvedComparatorAndReverse = (a, b) =>15 resolvedComparator(compare, a, b, true);16const compareWithResolvedComparatorAndNull = (a, b) =>17 resolvedComparator(compare, a, b, false, null);18const compareWithResolvedComparatorAndNullAndReverse = (a, b) =>19 resolvedComparator(compare, a, b, true, null);20const compareWithResolvedComparatorAndUndefined = (a, b) =>21 resolvedComparator(compare, a, b, false, undefined);22const compareWithResolvedComparatorAndUndefinedAndReverse = (a, b) =>23 resolvedComparator(compare, a, b, true, undefined);24const compareWithResolvedComparatorAndString = (a, b) =>25 resolvedComparator(compare, a, b, false, 'string');26const compareWithResolvedComparatorAndStringAndReverse = (a, b) =>27 resolvedComparator(compare, a, b, true, 'string');28const compareWithResolvedComparatorAndNumber = (a, b) =>29 resolvedComparator(compare, a, b, false, 1);30const compareWithResolvedComparatorAndNumberAndReverse = (a, b) =>31 resolvedComparator(compare, a, b, true, 1);32const compareWithResolvedComparatorAndObject = (a, b) =>33 resolvedComparator(compare, a, b, false, {});34const compareWithResolvedComparatorAndObjectAndReverse = (a, b) =>35 resolvedComparator(compare, a, b, true, {});36const compareWithResolvedComparatorAndArray = (a, b) =>37 resolvedComparator(compare, a, b, false, []);38const compareWithResolvedComparatorAndArrayAndReverse = (a, b) =>39 resolvedComparator(compare, a, b, true, []);40const compareWithResolvedComparatorAndNaN = (a, b) =>41 resolvedComparator(compare, a, b,

Full Screen

Using AI Code Generation

copy

Full Screen

1const resolvedComparator = require('fast-check-monorepo').resolvedComparator;2const fc = require('fast-check');3fc.assert(4 fc.property(fc.array(fc.integer()), (arr) => {5 const sorted = arr.sort(resolvedComparator);6 for (let i = 0; i < sorted.length - 1; i++) {7 if (sorted[i] > sorted[i + 1]) {8 return false;9 }10 }11 return true;12 })13);14{15 "scripts": {16 },17 "dependencies": {18 }19}20{21 "scripts": {22 },23 "dependencies": {24 }25}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { resolvedComparator } from 'fast-check-monorepo';2import { assert } from 'chai';3describe('resolvedComparator', () => {4 it('should work', () => {5 const comparator = resolvedComparator();6 assert.isTrue(comparator({ a: 1 }, { a: 1 }));7 assert.isTrue(comparator({ a: 1, b: 2 }, { a: 1, b: 2 }));8 assert.isTrue(comparator({ a: 1, b: 2 }, { b: 2, a: 1 }));9 assert.isFalse(comparator({ a: 1, b: 2 }, { a: 1 }));10 assert.isFalse(comparator({ a: 1 }, { a: 1, b: 2 }));11 assert.isFalse(comparator({ a: 1, b: 2 }, { a: 1, b: 3 }));12 });13});14I have a test.js file in the root of a project. I want to import the resolvedComparator method from fast-check-monorepo. I have a package.json file in the root of the project with the following content:15{16 "scripts": {17 },18 "dependencies": {19 },20 "devDependencies": {21 }22}23{24 "compilerOptions": {25 },26}27(function (exports, require, module, __filename, __dirname) { import { resolvedComparator } from 'fast-check-monorepo';28 at new Script (

Full Screen

Using AI Code Generation

copy

Full Screen

1const { resolvedComparator } = require('fast-check-monorepo');2const { assert } = require('chai');3describe('resolvedComparator', () => {4 it('should return true if the two arrays are equal', () => {5 assert.isTrue(resolvedComparator([1, 2, 3], [1, 2, 3]));6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { resolvedComparator } = require('fast-check-monorepo');2const { property } = require('fast-check');3const myComparator = (a, b) => {4 return a - b;5};6property(7 [resolvedComparator(myComparator)],8 (comparator) => {9 return comparator(1, 2) === -1;10 }11).then(() => {12 console.log('Success');13});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check')2const resolvedComparator = require('fast-check-monorepo').resolvedComparator3const { arb } = require('./arbitrary')4fc.assert(5 fc.property(arb, (array) => {6 const sortedArray = array.slice().sort(resolvedComparator)7 })8const fc = require('fast-check')9const { arbitrary } = require('fast-check-monorepo')10const { arb } = require('./arbitrary')11const { arb } = arbitrary({12})13fc.assert(14 fc.property(arb, (array) => {15 const sortedArray = array.slice().sort(resolvedComparator)16 })17{18 "dependencies": {19 }20}21{22 "dependencies": {23 },24 "devDependencies": {25 }26}27{28 "dependencies": {29 },30 "devDependencies": {31 },32 "scripts": {33 }34}35{36 "dependencies": {37 },38 "devDependencies": {39 },40 "scripts": {41 },42}43{44 "dependencies": {45 },46 "devDependencies": {

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 fast-check-monorepo 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