How to use sourceN method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

geogrid.data.js

Source:geogrid.data.js Github

copy

Full Screen

1"use strict"2/****** DATA ******/3export class Data {4 constructor(options) {5 this._options = options6 this._dataById = null7 this._cells = []8 this._geoJSON = null9 this._geoJSONReduced = null10 11 // init plugins12 this._overwriteColor = {}13 this._overwriteSize = {}14 this._overwriteContourColor = {}15 this._overwriteContourWidth = {}16 }17 resetGeoJSON() {18 this._geoJSON = null19 this._geoJSONReduced = null20 }21 getCells() {22 return this._cells23 }24 setCells(cells) {25 this._cells = cells26 }27 _minDataValue(sourceN, key) {28 let min = Infinity29 for (const v of this._dataById[sourceN].values()) {30 if (v[key] === null) continue31 const w = this._dataMap(sourceN, v)[key]32 if (w < min) min = w33 }34 return min35 }36 _maxDataValue(sourceN, key) {37 let max = -Infinity38 for (const v of this._dataById[sourceN].values()) {39 if (v[key] === null) continue40 const w = this._dataMap(sourceN, v)[key]41 if (w > max) max = w42 }43 return max44 }45 updateScales() {46 if (!this._dataById) return47 const t = this48 const computeScale = (sourceN, scale, min, max, key) => {49 if (key === null) return null50 if (scale.length != 2) return scale51 const minComputed = (min != null) ? min : this._minDataValue(sourceN, key)52 const maxComputed = (max != null) ? max : this._maxDataValue(sourceN, key)53 return scale(minComputed, maxComputed)54 }55 this._cellColorScale = {}56 this._cellSizeScale = {}57 // for (const sourceN of Object.keys(this._dataById)) {58 for (const [sourceN, source] of this._options.sources.entries()) {59 this._cellColorScale[sourceN] = computeScale(sourceN, source.cellColorScale, source.cellColorMin, source.cellColorMax, source.cellColorKey)60 this._cellSizeScale[sourceN] = computeScale(sourceN, source.cellSizeScale, source.cellSizeMin, source.cellSizeMax, source.cellSizeKey)61 }62 }63 getOverwriteColor() {64 return this._overwriteColor65 }66 getOverwriteSize() {67 return this._overwriteSize68 }69 getOverwriteContourColor() {70 return this._overwriteContourColor71 }72 getOverwriteContourWidth() {73 return this._overwriteContourWidth74 }75 overwriteColor(id, color) {76 if (color !== null) this._overwriteColor[id] = color77 else delete this._overwriteColor[cell.id]78 }79 overwriteSize(id, size) {80 if (size !== null) this._overwriteSize[id] = size81 else delete this._overwriteSize[cell.id]82 }83 overwriteContourColor(id, color) {84 if (color !== null) this._overwriteContourColor[id] = color85 else delete this._overwriteContourColor[cell.id]86 }87 overwriteContourWidth(id, width) {88 if (width !== null) this._overwriteContourWidth[id] = width89 else delete this._overwriteContourWidth[cell.id]90 }91 resetOverwriteColor() {92 this._overwriteColor = {}93 }94 resetOverwriteSize() {95 this._overwriteSize = {}96 }97 resetOverwriteContourColor() {98 this._overwriteContourColor = {}99 }100 resetOverwriteContourWidth() {101 this._overwriteContourWidth = {}102 }103 cellColor(sourceN, id, properties) {104 const source = this._options.sources[sourceN]105 // return overwritten colour106 if (id in this._overwriteColor) return this._overwriteColor[id]107 // no key108 if (source.cellColorKey === null) return source.cellColorNoKey109 // compute value110 const value = properties[source.cellColorKey]111 // return if empty value112 if (value === null || value === undefined) return source.cellColorNoData113 // return if no scale114 if (this._cellColorScale === null || this._cellColorScale[sourceN] === null) return source.cellColorNoKey115 // compute colour116 return this._cellColorScale[sourceN](value)117 }118 cellSize(sourceN, id, properties, geometry) {119 const source = this._options.sources[sourceN]120 let relativeSize121 // choose overwritten relative size122 if (id in this._overwriteSize) relativeSize = this._overwriteSize[id]123 // no key124 else if (source.cellSizeKey === null) relativeSize = source.cellSizeNoKey125 else {126 // compute value127 const value = properties[source.cellSizeKey]128 // empty value129 if (value === null || value === undefined) relativeSize = source.cellSizeNoData130 // no scale131 else if (this._cellSizeScale === null || this._cellSizeScale[sourceN] === null) relativeSize = source.cellSizeNoKey132 // compute relative size133 else relativeSize = this._cellSizeScale[sourceN](value)134 }135 // if no resize needed, return geometry136 if (relativeSize == 1) return geometry137 // if relative size vanishes, return null138 if (relativeSize == 0) return null139 // resize geometry140 const centroid = properties._centroid141 return geometry.map(([x, y]) => [relativeSize * (x - centroid[0]) + centroid[0], relativeSize * (y - centroid[1]) + centroid[1]])142 }143 cellContourColor(id, returnNullOnDefault=false) {144 // return overwritten contour colour145 if (id in this._overwriteContourColor) return this._overwriteContourColor[id]146 // return default value147 return returnNullOnDefault ? null : this._options.cellContourColor148 }149 cellContourWidth(id, returnNullOnDefault=false) {150 // return overwritten contour width151 if (id in this._overwriteContourWidth) return this._overwriteContourWidth[id]152 // return default value153 return returnNullOnDefault ? null : this._options.cellContourWidth154 }155 cacheData(progress) {156 if (this._options.sources === null || this._options.sources.length === 0) return null157 this._dataById = {}158 const dataCells = {data: {}}159 for (const [sourceN, source] of this._options.sources.entries()) {160 this._dataById[sourceN] = new Map()161 if (!source || !source.data || !source.data.data) continue162 if (dataCells.resolution !== undefined && dataCells.resolution !== source.data.resolution) progress.error('All sources must have the same resolution')163 const ds = source.data.data164 for (let i = 0; i < ds.length; i++) {165 const d = ds[i]166 this._dataById[sourceN].set(d.id, d)167 if (!(d.id in dataCells.data)) {168 if (d.lat !== undefined) {169 dataCells.data[d.id] = {170 id: d.id,171 lat: d.lat,172 lon: d.lon,173 }174 if (d.isPentagon !== undefined) dataCells.data[d.id].isPentagon = d.isPentagon175 } else dataCells.data[d.id] = d.id176 }177 }178 for (const k of Object.keys(source.data)) if (k != 'data') dataCells[k] = source.data[k]179 if (source.data.url) source.data.data = true180 }181 dataCells.data = Object.values(dataCells.data)182 return dataCells183 }184 dataKeys(sourceN) {185 if (this._options.sources == null) return []186 const source = this._options.sources[sourceN]187 if (source.dataKeys !== null) return source.dataKeys188 if (this._dataById[sourceN] === undefined || this._dataById[sourceN] === null) return []189 const d = this._dataById[sourceN].values().next().value190 if (d === undefined) return []191 return Object.keys(d).filter(k => !['lat', 'lon', 'isPentagon'].includes(k))192 }193 produceGeoJSON() {194 // update scales195 this.updateScales()196 // preparations for computing how the hexagon shall be split197 const split = this._options.splitHexagon(this._options.sources.filter(s => !s.hide))198 const coordinatesForSources = (vertices, centroid, splitN, splitDelta) => {199 const vs = vertices.concat([vertices[0]])200 if (splitN == 0 && splitDelta == 6) return vs201 return [centroid].concat(vs.splice(splitN, Math.min(splitDelta + 1, vertices.length - splitN + 1))).concat([centroid])202 }203 // preparations for producing GeoJSONs204 const centroidOf = vertices => {205 let x = 0206 let y = 0207 for (let i = vertices.length; i--;) {208 x += vertices[i][0]209 y += vertices[i][1]210 }211 return [x / vertices.length, y / vertices.length]212 }213 const makeFeature = (coordinates, centroid, cell, sourceN, properties) => ({214 type: 'Feature',215 geometry: {216 type: 'Polygon',217 coordinates: [coordinates],218 },219 properties: {220 id: cell.id,221 _sourceN: sourceN,222 _centroid: centroid,223 ...properties,224 },225 })226 const makeFeatureBorder = (coordinates, centroid, cell) => ({227 type: 'Feature',228 geometry: {229 type: 'Polygon',230 coordinates: [coordinates],231 },232 properties: {233 id: cell.id,234 _isCell: true,235 _centroid: centroid,236 },237 })238 // produce GeoJSON239 const features = []240 for (let c of this._cells) {241 if (c.vertices !== undefined) {242 const centroid = centroidOf(c.vertices)243 let splitN = 0244 for (const [sourceN, splitDelta] of split) {245 const coordinates = coordinatesForSources(c.vertices, centroid, splitN, splitDelta)246 features.push(makeFeature(coordinates, centroid, c, sourceN, this.dataForId(sourceN, c.id)))247 splitN += splitDelta248 }249 features.push(makeFeatureBorder(c.vertices.concat([c.vertices[0]]), centroid, c))250 }251 }252 this._geoJSON = {253 type: 'FeatureCollection',254 features: features,255 }256 }257 _dataMap(sourceN, d) {258 if (this._options.sources[sourceN].dataMap !== null) return this._options.sources[sourceN].dataMap(d)259 return d260 }261 dataForId(sourceN, id) {262 const d = this._dataById[sourceN].get(id)263 if (d === undefined) return {}264 const d2 = this._dataMap(sourceN, d)265 const properties = {}266 if (this.dataKeys(sourceN)) for (const k of this.dataKeys(sourceN)) properties[k] = d2[k]267 return properties268 }269 dataForIdNotMapped(sourceN, id) {270 const d = this._dataById[sourceN].get(id)271 if (d === undefined) return {}272 return d273 }274 getGeoJSON() {275 return this._geoJSON276 }277 getGeoJSONReduced(b) {278 if (!this._geoJSON) return279 // return cached GeoJSON in case of unchanged bounds280 if (this._geoJSONReduced !== null && b.equals(this._bboxView)) return this._geoJSONReduced281 this._bboxView = b282 // reduce283 this._geoJSONReduced = {284 type: 'FeatureCollection',285 features: [],286 }287 for (let f of this._geoJSON.features) if (b.intersects(L.latLngBounds(f.geometry.coordinates[0].map(c => [c[1], c[0]])))) this._geoJSONReduced.features.push(f)288 // return289 return this._geoJSONReduced290 }...

Full Screen

Full Screen

geogrid.download.js

Source:geogrid.download.js Github

copy

Full Screen

1"use strict"2const cacheSize = 2.53const radians = degrees => degrees * Math.PI / 1804const latLonToTileID = (lat, lon, zoom) => {5 const n = 2**zoom6 const x = Math.floor(n * (lon + 180) / 360)7 const y = Math.floor(n / 2 * (1 - Math.log(Math.tan(radians(lat)) + 1 / Math.cos(radians(lat))) / Math.PI))8 return [x, y]9}10const cacheObjectJSONable = (options, source) => ({11 url: source.url,12 tileZoom: source.tileZoom,13 parameters: source.parameters,14})15const cacheObjectNonJSONable = (options, source) => ({16 resolution: options.resolution,17})18const cacheObjectNonJSONableKeys = [19 'resolution',20]21let instanceDownload = null22/****** Download ******/23export class Download {24 constructor(progress) {25 if (instanceDownload === null) {26 instanceDownload = this27 this._progress = progress28 this._cache = {}29 this._cacheObjects = {}30 this._cacheObjectsN = 031 }32 return instanceDownload33 }34 __getOrSaveCacheObject(object) {35 for (const [n, v] of Object.entries(this._cacheObjects)) if (v == object) return n36 const n = this._cacheObjectsN.toString()37 this._cacheObjects[n] = object38 this._cacheObjectsN++39 return n40 }41 __fetchCacheObject(n) {42 return this._cacheObjects[n]43 }44 __removeCacheObject(n) {45 delete this._cacheObjects[n]46 }47 __cleanupCache(cJSON, sourceN) {48 let cleanupCacheObjectNs = []49 // remove sourceN from unused caches50 for (const [k, v] of Object.entries(this._cache)) if (k != cJSON && v.sourceN == sourceN) {51 v._cachedFor.delete(sourceN)52 if (v._cachedFor.size == 0) cleanupCacheObjectNs = cleanupCacheObjectNs.concat(cacheObjectNonJSONableKeys.map(k2 => v[k2]))53 delete this._cache[k]54 }55 // delete unused caches and corresponding cache objects56 const usedCacheObjectNs = Object57 .values(this._cache)58 .flatMap(v => cacheObjectNonJSONableKeys.map(k => v[k]))59 for (const n of cleanupCacheObjectNs) if (!usedCacheObjectNs.includes(n)) this.__removeCacheObject(n)60 }61 _getCache(options, source, sourceN) {62 // create default cache63 const c = {64 ...cacheObjectJSONable(options, source),65 }66 // save objects to cache67 for (const [k, v] of Object.entries(cacheObjectNonJSONable(options, source))) c[k] = this.__getOrSaveCacheObject(v)68 // compute key69 const cJSON = JSON.stringify(c)70 // store to cache if necessary71 if (!(cJSON in this._cache)) this._cache[cJSON] = {72 ...c,73 _cachedFor: new Set(),74 _cachedData: {},75 _callbacksDownloading: {},76 }77 // add sourceN to _cachedFor78 this._cache[cJSON]._cachedFor.add(sourceN)79 // produce result80 const c2 = {...this._cache[cJSON]}81 // fetch objects from cache82 for (const k of cacheObjectNonJSONableKeys) c2[k] = this.__fetchCacheObject(c2[k])83 // cleanup cache84 this.__cleanupCache(cJSON, sourceN)85 // return result86 return [cJSON, c2]87 }88 load(options, source, sourceN, resolutionData, bbox, callback) {89 // get cache90 const [cJSON, c] = this._getCache(options, source, sourceN)91 // produce urls92 let urls93 let url = c.url.replace('{resolution}', resolutionData)94 for (const p in c.parameters) url = url.replace(`{${p}}`, (c.parameters[p] !== null) ? c.parameters[p] : '')95 if (c.url.includes('{bbox}')) urls = [url.replace('{bbox}', bbox.toBBoxString())]96 else {97 url = c.url.replace('{z}', c.tileZoom)98 const [xMin, yMin] = latLonToTileID(bbox.getNorth(), bbox.getWest(), c.tileZoom)99 const [xMax, yMax] = latLonToTileID(bbox.getSouth(), bbox.getEast(), c.tileZoom)100 const xy = []101 for (let x = xMin; x <= xMax; x++) for (let y = yMin; y <= yMax; y++) xy.push([x, y])102 urls = xy.map(([x, y]) => url.replace('{x}', x).replace('{y}', y))103 }104 this._download(options, cJSON, urls, callback)105 }106 _download(options, cJSON, urls, callback) {107 const ds = {}108 // prepare the final data109 const useData = (url, data) => {110 ds[url] = data111 if (Object.keys(ds).length < urls.length) return112 let result = null113 for (const d of Object.values(ds)) if (d !== null && d.data !== null) {114 if (result === null) result = {...d}115 else result.data = result.data.concat(d.data)116 }117 try {118 callback(result)119 if (Object.keys(this._cache[cJSON]._cachedData).length > cacheSize * urls.length) this._cache[cJSON]._cachedData = {}120 } catch (e) {121 console.error(e)122 }123 }124 // start downloads125 for (const url of urls) {126 if (url in this._cache[cJSON]._cachedData) {127 if ((options.debug || !options.silent) && this._progress) this._progress.log(`cached: ${url}`)128 useData(url, this._cache[cJSON]._cachedData[url])129 } else if (url in this._cache[cJSON]._callbacksDownloading) this._cache[cJSON]._callbacksDownloading[url].push((url, data) => useData(url, data))130 else {131 this._cache[cJSON]._callbacksDownloading[url] = []132 d3.json(url).then(data => {133 if ((options.debug || !options.silent) && this._progress) this._progress.log(`downloaded: ${url}`)134 this._cache[cJSON]._cachedData[url] = data135 useData(url, data)136 for (const cb of this._cache[cJSON]._callbacksDownloading[url]) {137 if ((options.debug || !options.silent) && this._progress) this._progress.log(`cached: ${url}`)138 cb(url, data)139 }140 delete this._cache[cJSON]._callbacksDownloading[url]141 }).catch(e => {142 if ((options.debug || !options.silent) && this._progress) this._progress.log(`downloaded with error: ${url}`)143 this._cache[cJSON]._cachedData[url] = null144 useData(url, null)145 for (const cb of this._cache[cJSON]._callbacksDownloading[url]) {146 if ((options.debug || !options.silent) && this._progress) this._progress.log(`cached: ${url}`)147 cb(url, null)148 }149 delete this._cache[cJSON]._callbacksDownloading[url]150 })151 }152 }153 }...

Full Screen

Full Screen

ana.js

Source:ana.js Github

copy

Full Screen

1/* LOS Analysis module for flea */2var pluginLogger;3var pluginDAO;4var pluginConfig;5var wugutils = require('../lib/wugutils.js');6var urlFormat = "http://flea.wolfen.za.net/FleaAnalyse.aspx?Name1=**n1**&Name2=**n2**&Id1=**id1**&Id2=**id2**&Lat1=**lat1**&Lat2=**lat2**&Lon1=**lon1**&Lon2=**lon2**";7function ChatModule() {8 this.init = function (logger, config) {9 pluginLogger = logger.getLogger(exports.commandName);10 if (config)11 {12 pluginConfig = config;13 wugutils.init(logger);14 wugutils.getKMZ(pluginConfig.kmzurl);15 }16 };17 this.messageReceived = function (message, dest, source)18 {19 var words = message.split(' ');20 var sourceNode = words[1];21 var destNode = words[2];22 23 pluginLogger.debug("Searching for matching node for: "+sourceNode);24 pluginLogger.debug("Searching for matching node for: "+destNode);25 var sourceN = wugutils.getNodeByName(sourceNode);26 var destN = wugutils.getNodeByName(destNode);27 if (!sourceN)28 {29 this.sendMessage(dest, "Unable to find: " + sourceNode);30 return;31 }32 if (!destN)33 {34 this.sendMessage(dest, "Unable to find: " + destNode);35 return;36 }37 38 pluginLogger.debug("sourceNode : "+JSON.stringify(sourceN));39 pluginLogger.debug("destNode : "+JSON.stringify(destN));40 41 var url = urlFormat.replace("**id1**", sourceN.id);42 url = url.replace("**id2**", destN.id);43 url = url.replace("**n1**", sourceN.name);44 url = url.replace("**n2**", destN.name);45 url = url.replace("**lat1**", sourceN.lat);46 url = url.replace("**lat2**", destN.lat);47 url = url.replace("**lon1**", sourceN.lon);48 url = url.replace("**lon2**", destN.lon);49 50 this.sendMessage(dest, "Analysis of LOS from ["+ sourceN.name +"] to ["+destN.name+"]:");51 this.sendMessage(dest, url);52 };53}54exports.commandName = 'ana';55exports.module = new ChatModule();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { source1, source2 } = require('fast-check-monorepo');3fc.assert(4 fc.property(source1(), source2(), (a, b) => {5 return a + b > 0;6 })7);8{9 "dependencies": {10 }11}12{13 "dependencies": {14 },15 "resolutions": {16 }17}

Full Screen

Using AI Code Generation

copy

Full Screen

1import {sourceN} from 'fast-check-monorepo';2sourceN(1, 2, 3);3import {sourceN} from 'fast-check';4sourceN(1, 2, 3);5import {sourceN} from 'fast-check';6sourceN(1, 2, 3);7import {sourceN} from 'fast-check';8sourceN(1, 2, 3);9import {sourceN} from 'fast-check';10sourceN(1, 2, 3);11import {sourceN} from 'fast-check';12sourceN(1, 2, 3);13import {sourceN} from 'fast-check';14sourceN(1, 2, 3);15import {sourceN} from 'fast-check';16sourceN(1, 2, 3);17import {sourceN} from 'fast-check';18sourceN(1, 2, 3);19import {sourceN} from 'fast-check';20sourceN(1, 2, 3);21import {sourceN} from 'fast-check';22sourceN(1, 2, 3);23import {sourceN} from 'fast-check';24sourceN(1, 2, 3);25import {sourceN} from 'fast-check';26sourceN(1, 2, 3);27import

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { sourceN } = require('fast-check-monorepo');3const { some, none } = require('fp-ts/lib/Option');4const isEven = (n) => n % 2 === 0;5const isOdd = (n) => n % 2 === 1;6const arbOptionEven = sourceN(fc.nat(), isEven, some);7const arbOptionOdd = sourceN(fc.nat(), isOdd, some);8fc.assert(9 fc.property(arbOptionEven, (n) => {10 return isEven(n);11 }),12 { numRuns: 100 }13);14sourceN<T, U>(15 predicate: (value: T) => boolean,16 f: (value: T) => U17source<T, U>(arb: Arbitrary<T>, f: (value: T) => U): Arbitrary<U>18sourceOption<T>(arb: Arbitrary<T>, predicate: (value: T) => boolean): Arbitrary<Option<T>>19sourceOptionN<T>(arb: Arbitrary<T>, f: (value: T) => Option<T>): Arbitrary<Option<T>>

Full Screen

Using AI Code Generation

copy

Full Screen

1import { sourceN } from 'fast-check-monorepo'2sourceN(1, 2, 3, 4, 5)3 .forEach((n) => console.log(n))4import { sourceN } from 'fast-check-monorepo'5sourceN(1, 2, 3, 4, 5)6 .forEach((n) => console.log(n))7import { sourceN } from 'fast-check-monorepo'8sourceN(1, 2, 3, 4, 5)9 .forEach((n) => console.log(n))10import { sourceN } from 'fast-check-monorepo'11sourceN(1, 2, 3, 4, 5)12 .forEach((n) => console.log(n))13import { sourceN } from 'fast-check-monorepo'14sourceN(1, 2, 3, 4, 5)15 .forEach((n) => console.log(n))16import { sourceN } from 'fast-check-monorepo'17sourceN(1, 2, 3, 4, 5)18 .forEach((n) => console.log(n))19import { sourceN } from 'fast-check-monorepo'20sourceN(1, 2, 3, 4, 5)21 .forEach((n) => console.log(n))22import { sourceN } from 'fast-check-monorepo'23sourceN(1, 2, 3, 4, 5)24 .forEach((n) => console.log(n))25import { sourceN } from 'fast-check-mon

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