How to use numRoads method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

graphanalysis.js

Source:graphanalysis.js Github

copy

Full Screen

1/**2 * Created by jonathanbobrow on 1/11/16.3 */4GraphAnalysis = (Meteor.isClient ? window : global).GraphAnalysis || {};5/**6 * Status for roads, will be used for coloring them7 * @type {{OPEN: number, CLOSED_EMPTY: number, CLOSED_RESPONDERS: number, CLOSED_CONTAINED: number, CLOSED_ISOLATED: number}}8 */9GraphAnalysis.roadStatus = {10 /**11 * No quarantine here12 */13 OPEN: 0,14 /**15 * Closed quarantine but no one inside.16 */17 CLOSED_EMPTY: 1,18 /**19 * Only healthy people trapped.20 */21 CLOSED_RESPONDERS: 2,22 /**23 * Patient Zero contained with healthy people.24 */25 CLOSED_CONTAINED: 3,26 /**27 * Patient Zero isolated.28 */29 CLOSED_ISOLATED: 430};31/**32 * Patient Zero status33 * TODO: This might belong in patient zero... (but only used here for now)34 * @type {{LOOSE: number, CONTAINED: number, ISOLATED: number}}35 */36GraphAnalysis.pzerostatus = {37 /**38 * No quarantine here39 */40 LOOSE: 0,41 /**42 * Closed quarantine but no one inside.43 */44 CONTAINED: 1,45 /**46 * Only healthy people trapped.47 */48 ISOLATED: 249};50/**51 * Get information about each component (in the graph theoretic sense) of the road network52 * @param graph {Object.<Number, [Number]>} An adjacency list representation of the road network53 * @param infoForNode {Object.<Number, {}>} A dictionary of additional metadata for a particular node54 * @private55 */56GraphAnalysis._getComponents = function (graph) {57 var seen = new Set();58 var components = [];59 _.each(graph, function (us, v) {60 if (!seen.has(parseInt(v))) {61 var nodesInComponent = GraphAnalysis._bfs(graph, parseInt(v));62 components.push(nodesInComponent);63 nodesInComponent.forEach(function (u) {64 seen.add(parseInt(u));65 });66 }67 });68 // Do analysis on components69 // Return components70 return components;71};72/**73 * Is patient zero isolated?74 * @param components {[[Number]]} An array of arrays of road ids representing components in a graph theoretic sense75 * @param playerRoadIds {[Number]} An array of road ids containing players76 * @param patientZeroRoadId {Number} The road id corresponding to the location of patient zero77 * @param numRoads {Number} the total number of roads, help with determining inside or outside78 * @private79 */80GraphAnalysis._isPatientZeroIsolated = function (components, playerRoadIds, patientZeroRoadId, numRoads) {81 var pZeroComponent = _.find(components, function (component) {82 return _.contains(component, patientZeroRoadId);83 });84 return GraphAnalysis._getComponentStatus(pZeroComponent, playerRoadIds, patientZeroRoadId, numRoads) === GraphAnalysis.roadStatus.CLOSED_ISOLATED;85};86/**87 * Is patient zero contained?88 * @param components {[[Number]]} An array of arrays of road ids representing components in a graph theoretic sense89 * @param playerRoadIds {[Number]} An array of road ids containing players90 * @param patientZeroRoadId {Number} The road id corresponding to the location of patient zero91 * @param numRoads {Number} the total number of roads, help with determining inside or outside92 * @private93 */94GraphAnalysis._isPatientZeroContained = function (components, playerRoadIds, patientZeroRoadId, numRoads) {95 var pZeroComponent = _.find(components, function (component) {96 return _.contains(component, patientZeroRoadId);97 });98 return GraphAnalysis._getComponentStatus(pZeroComponent, playerRoadIds, patientZeroRoadId, numRoads) === GraphAnalysis.roadStatus.CLOSED_CONTAINED;99};100/**101 * Get a state for Patient Zero (currently just isolated or not)...102 * @param graph {Object.<Number, [Number]>} An adjacency list representation of the road network103 * @param playerRoadIds {[Number]} An array of roadIds which players are on104 * @param patientZeroRoadId {Number} id of the road that Patient Zero is currently on105 * @param numRoads {Number} the total number of roads, help with determining inside or outside106 * @returns {Number} pzerostatus107 */108GraphAnalysis.checkPatientZero = function (graph, playerRoadIds, patientZeroRoadId, numRoads) {109 var components = GraphAnalysis._getComponents(graph);110 if (GraphAnalysis._isPatientZeroIsolated(components, playerRoadIds, patientZeroRoadId, numRoads)) {111 return GraphAnalysis.pzerostatus.ISOLATED;112 }113 else if (GraphAnalysis._isPatientZeroContained(components, playerRoadIds, patientZeroRoadId, numRoads)) {114 return GraphAnalysis.pzerostatus.CONTAINED;115 }116 else {117 return GraphAnalysis.pzerostatus.LOOSE;118 }119};120/**121 * Get a single roads status by Id122 * @param graph {Object.<Number, [Number]>} An adjacency list representation of the road network123 * @param roadId {Number} the id of the road whose status we want124 * @param playerRoadIds {[Number]} An array of roadIds which players are on125 * @param patientZeroRoadId {Number} id of the road that Patient Zero is currently on126 * @param numRoads {Number} the total number of roads, help with determining inside or outside127 * @returns {Number} a type of road status128 */129GraphAnalysis.getRoadStatusById = function (graph, roadId, playerRoadIds, patientZeroRoadId, numRoads) {130 // checks which component the road is part of and then returns that component's status131 var components = GraphAnalysis._getComponents(graph);132 var component = _.find(components, function (component) {133 return _.contains(component, roadId);134 });135 if (!component) {136 console.log("No component found for road: ", roadId);137 return GraphAnalysis.roadStatus.OPEN;138 }139 return GraphAnalysis._getComponentStatus(component, playerRoadIds, patientZeroRoadId, numRoads);140};141/**142 * Get a map of road statuses143 * @param graph {Object.<Number, [Number]>} An adjacency list representation of the road network144 * @param playerRoadIds {[Number]} An array of roadIds which players are on145 * @param patientZeroRoadId {Number} id of the road that Patient Zero is currently on146 * @param numRoads {Number} the total number of roads, help with determining inside or outside147 * @returns {{GraphAnalysis.roadStatus}} Road statuses organized by roadId148 */149GraphAnalysis.getRoadStatus = function (graph, playerRoadIds, patientZeroRoadId, numRoads) {150 var roadStatuses = {};151 var components = GraphAnalysis._getComponents(graph);152 _.each(components, function (component) {153 var roadStatus = GraphAnalysis._getComponentStatus(component, playerRoadIds, patientZeroRoadId, numRoads);154 _.each(component, function (roadId) {155 roadStatuses[roadId] = roadStatus;156 });157 });158 return roadStatuses;159};160/**161 * Gets the status of a single component (group of roads)162 * @param component {[Number]} group of roadIds163 * @param playerRoadIds {[Number]} roadIds occupied by responders164 * @param patientZeroRoadId {Number} roadId occupied by Patient Zero165 * @param numRoads {Number} the total number of roads, help with determining inside or outside166 * @returns {GraphAnalysis.roadStatus} status of the component167 */168GraphAnalysis._getComponentStatus = function (component, playerRoadIds, patientZeroRoadId, numRoads) {169 var componentStatus;170 var doesContainPatientZero = _.contains(component, patientZeroRoadId);171 var doesContainResponders = _.any(playerRoadIds, function (playerRoadId) {172 return _.contains(component, playerRoadId);173 });174 // check and see if this is the largest component... or some other way of determining inside or outside...175 // the quarantine must not contain more than half of the map to be a successful quarantine.176 if (component.length > (2 * numRoads / 3)) {177 return GraphAnalysis.roadStatus.OPEN;178 }179 if (doesContainPatientZero && !doesContainResponders) {180 // isolated181 componentStatus = GraphAnalysis.roadStatus.CLOSED_ISOLATED;182 }183 else if (doesContainPatientZero && doesContainResponders) {184 // contained185 componentStatus = GraphAnalysis.roadStatus.CLOSED_CONTAINED;186 }187 else if (!doesContainPatientZero && doesContainResponders) {188 // responders present189 componentStatus = GraphAnalysis.roadStatus.CLOSED_RESPONDERS;190 }191 else if (!doesContainPatientZero && !doesContainResponders) {192 // empty193 componentStatus = GraphAnalysis.roadStatus.CLOSED_EMPTY;194 }195 return componentStatus;196};197/**198 * Breadth First Search199 * @param graph {Object.<Number, [Number]>} An adjacency list representation of the road network200 * @param source {*}201 * @returns {Array}202 * @private203 */204GraphAnalysis._bfs = function (graph, source) {205 var nodes = [];206 var seen = new Set();207 var nextLevel = new Set([source]);208 while (nextLevel.size > 0) {209 var thisLevel = nextLevel;210 nextLevel = new Set();211 thisLevel.forEach(function (v) {212 if (!seen.has(v)) {213 nodes.push(v);214 seen.add(v);215 graph[v].forEach(function (u) {216 nextLevel.add(u);217 });218 }219 });220 }221 return nodes;...

Full Screen

Full Screen

world_builder.ts

Source:world_builder.ts Github

copy

Full Screen

1import RoadMap from "../models/road_map";2import Car from "../models/car";3import World from "./world";4import RoadNetwork from "./road_network";5import DrivingCar from "./driving_car";6import Address from "./address";7import { RoadDirection } from "../enums";8import { randInt, randDouble } from "../util";9import Road from "../models/road";10import { getRoadLength, randomAddress, randomDirection } from "./simulator_helpers";11import CarController from "./car_controller";12import LightSwitcher from "./light_switcher";13import TrafficLight from "./traffic_light";14import DefaultLightSwitcher from "./default_light_switcher";15import { Coord } from "../util";16const PARALLEL_ROAD_DISTANCE = .1;17export default class WorldBuilder {18 private roadID: number = 0;19 constructor(private map?: RoadMap, private cars?: Car[]) {20 if(!this.map) {21 this.map = this.createSimpleMap(10);22 }23 if(!this.cars) {24 this.cars = this.createCars(20);25 }26 }27 createSimpleMap(roadsPerSide: number): RoadMap {28 this.roadID = 0;29 let grid: Road[] = Array.from(this.createRoadRows(roadsPerSide))30 .concat(Array.from(this.createRoadColumns(roadsPerSide)));31 return new RoadMap(grid);32 }33 private *createRoadRows(numRoads: number): IterableIterator<Road> {34 let roadLength = numRoads * PARALLEL_ROAD_DISTANCE;35 yield* this.createRoads(numRoads, 36 (num) => this.makeHorizontalPath(num, roadLength));37 }38 private *createRoadColumns(numRoads: number): IterableIterator<Road> {39 let roadLength = numRoads * PARALLEL_ROAD_DISTANCE;40 yield* this.createRoads(numRoads, 41 (num) => this.makeVerticalPath(num, roadLength));42 }43 private *createRoads(numRoads: number, coordCreator: (n: number) => Coord[]): 44 IterableIterator<Road> 45 {46 for (let i = 0; i < numRoads; i++) {47 let path = coordCreator(i);48 yield new Road(this.roadID, path, 1, 1);49 this.roadID++;50 }51 }52 private makeHorizontalPath(roadNum: number, roadLength: number): Coord[] {53 return [new Coord(0, roadNum * PARALLEL_ROAD_DISTANCE), 54 new Coord(roadLength, roadNum * PARALLEL_ROAD_DISTANCE)];55 }56 57 private makeVerticalPath(roadNum: number, roadLength: number): Coord[] {58 return [new Coord(roadNum * PARALLEL_ROAD_DISTANCE, 0), 59 new Coord(roadNum * PARALLEL_ROAD_DISTANCE, roadLength)];60 }61 createCars(numCars: number): Car[] {62 let cars: Car[] = [];63 for (let i = 0; i < numCars; i++) {64 cars.push(new Car(i, .005, 10, 3));65 }66 return cars;67 }68 build(): World {69 let network = new RoadNetwork(this.map);70 let world = new World(network);71 let worldCars: DrivingCar[] = this.cars.map((c) => {72 let [addr, dir] = this.generateRandomAddressDir(network);73 let car: DrivingCar = new DrivingCar(c, addr, dir);74 let controller: CarController = new CarController(car, world);75 car.setController(controller);76 car.setOnAtDest(() => {77 let [addr, dir] = this.generateRandomAddressDir(network);78 car.direction = dir;79 car.setDestination(addr);80 });81 return car;82 });83 world.setCars(worldCars);84 world.network.intersections.forEach(int => {85 let light: TrafficLight = int.light;86 let controller: LightSwitcher = new DefaultLightSwitcher(light);87 light.setSwitcher(controller);88 });89 return world90 }91 private generateRandomAddressDir(network: RoadNetwork): [Address, RoadDirection] {92 let addr: Address = randomAddress(network);93 return [addr, randomDirection(addr.road)];94 }...

Full Screen

Full Screen

test_exports.ts

Source:test_exports.ts Github

copy

Full Screen

1import { IntersectionDirection } from "../enums";2import TrafficLight from "../simulator/traffic_light";3import LightSwitcher from "../simulator/light_switcher";4import RoadMap from "../models/road_map";5import Road from "../models/road";6import { Coord } from "../util";7import Car from "../models/car";8export function* defaultCars(num: number): IterableIterator<Car> {9 for(let i = 0; i < num; i++) {10 yield new Car(i, .005, 100, 3);11 }12}13export function defaultCar(): Car {14 return defaultCars(1).next().value;15}16export function createMap(): RoadMap {17 let creator: MapCreator = new MapCreator(2, .1);18 return creator.createMap(5);19}20class MapCreator {21 private roadID: number = 0;22 private numRoads: number;23 constructor(private roadLen: number, private roadSeparation: number) {24 }25 createMap(num: number): RoadMap {26 this.numRoads = num;27 let grid: Road[] = this.generateGrid();28 return new RoadMap(grid);29 }30 private generateGrid(): Road[] {31 return Array.from(this.createRoadRows(this.numRoads))32 .concat(Array.from(this.createRoadColumns(this.numRoads)));33 }34 35 private *createRoadRows(numRoads: number): IterableIterator<Road> {36 yield* this.createRoads(numRoads, this.makeHorizontalPath.bind(this));37 }38 39 private *createRoadColumns(numRoads: number): IterableIterator<Road> {40 yield* this.createRoads(numRoads, this.makeVerticalPath.bind(this));41 }42 43 private *createRoads(numRoads: number, coordCreator: (n: number) => Coord[]): 44 IterableIterator<Road> 45 {46 for (let i = 0; i < numRoads; i++) {47 let path = coordCreator(i);48 yield new Road(this.roadID, path, 1, 1);49 this.roadID++;50 }51 }52 53 private makeHorizontalPath(roadNum: number): Coord[] {54 return [new Coord(0, roadNum * this.roadSeparation), 55 new Coord(this.roadLen, roadNum * this.roadSeparation)];56 }57 58 private makeVerticalPath(roadNum: number): Coord[] {59 return [new Coord(roadNum * this.roadSeparation, 0), 60 new Coord(roadNum * this.roadSeparation, this.roadLen)];61 }62}63export class SimpleLightSwitcher implements LightSwitcher {64 constructor(protected light: TrafficLight, protected direction: IntersectionDirection) {65 this.light.setSwitcher(this);66 light.greenDirection = this.direction;67 }68 tick(): void {}69 setDirection(dir: IntersectionDirection): void {}70 carSensorTripped(dir: IntersectionDirection): void {}71}72export class AutoSwitcher implements LightSwitcher {73 constructor(private light: TrafficLight) {74 }75 tick(): void {}76 setDirection(dir: IntersectionDirection): void {}77 carSensorTripped(dir: IntersectionDirection): void {78 this.light.greenDirection = dir;79 }80}81export class TrippedTestSwitcher extends SimpleLightSwitcher {82 public trippedDirs: IntersectionDirection[] = []83 constructor(light: TrafficLight, direction: IntersectionDirection) {84 super(light, direction);85 }86 carSensorTripped(dir: IntersectionDirection): void {87 this.trippedDirs.push(dir);88 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { numRoads } = require('fast-check-monorepo');2console.log('numRoads', numRoads);3const { numRoads } = require('fast-check-monorepo');4console.log('numRoads', numRoads);5const { numRoads } = require('fast-check-monorepo');6console.log('numRoads', numRoads);7const { numRoads } = require('fast-check-monorepo');8console.log('numRoads', numRoads);9const { numRoads } = require('fast-check-monorepo');10console.log('numRoads', numRoads);11const { numRoads } = require('fast-check-monorepo');12console.log('numRoads', numRoads);13const { numRoads } = require('fast-check-monorepo');14console.log('numRoads', numRoads);15const { numRoads } = require('fast-check-monorepo');16console.log('numRoads', numRoads);17const { numRoads } = require('fast-check-monorepo');18console.log('numRoads', numRoads);19const { numRoads } = require('fast-check-monorepo');20console.log('numRoads', numRoads);21const { numRoads } = require('fast-check-monorepo');22console.log('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { numRoads } = require('fast-check-monorepo');2console.log(numRoads);3const { numRoads } = require('fast-check-monorepo');4console.log(numRoads);5const { numRoads } = require('fast-check-monorepo');6console.log(numRoads);7const { numRoads } = require('fast-check-monorepo');8console.log(numRoads);9const { numRoads } = require('fast-check-monorepo');10console.log(numRoads);11const { numRoads } = require('fast-check-monorepo');12console.log(numRoads);13const { numRoads } = require('fast-check-monorepo');14console.log(numRoads);15const { numRoads } = require('fast-check-monorepo');16console.log(numRoads);17const { numRoads } = require('fast-check-monorepo');18console.log(numRoads);19const { numRoads } = require('fast-check-monorepo');20console.log(numRoads);21const { numRoads } = require('fast-check-monorepo');22console.log(numRoads);23const { numRoads } = require('fast-check-monorepo');24console.log(numRoads);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { numRoads } = require('fast-check-monorepo');2console.log(numRoads(10));3const { numRoads } = require('fast-check-monorepo');4console.log(numRoads(10));5const { numRoads } = require('fast-check-monorepo');6console.log(numRoads(10));7const { numRoads } = require('fast-check-monorepo');8console.log(numRoads(10));9const { numRoads } = require('fast-check-monorepo');10console.log(numRoads(10));11const { numRoads } = require('fast-check-monorepo');12console.log(numRoads(10));13const { numRoads } = require('fast-check-monorepo');14console.log(numRoads(10));15const { numRoads } = require('fast-check-monorepo');16console.log(numRoads(10));17const { numRoads } = require('fast-check-monorepo');18console.log(numRoads(10));19const { numRoads } = require('fast-check-monorepo');20console.log(numRoads(10));21const { numRoads } = require('fast-check-monorepo');22console.log(numRoads(10));23const { num

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const numRoads = require('fast-check-monorepo');3fc.assert(4 fc.property(fc.nat(), fc.nat(), fc.nat(), (a, b, c) => {5 return numRoads(a, b, c) === a + b + c;6 })7);8const fc = require('fast-check');9const numRoads = require('fast-check-monorepo');10fc.assert(11 fc.property(fc.nat(), fc.nat(), fc.nat(), (a, b, c) => {12 return numRoads(a, b, c) === a + b + c;13 })14);15const fc = require('fast-check');16const numRoads = require('fast-check-monorepo');17fc.assert(18 fc.property(fc.nat(), fc.nat(), fc.nat(), (a, b, c) => {19 return numRoads(a, b, c) === a + b + c;20 })21);22const fc = require('fast-check');23const numRoads = require('fast-check-monorepo');24fc.assert(25 fc.property(fc.nat(), fc.nat(), fc.nat(), (a, b, c) => {26 return numRoads(a, b, c) === a + b + c;27 })28);29const fc = require('fast-check');30const numRoads = require('fast-check-monorepo');31fc.assert(32 fc.property(fc.nat(), fc.nat(), fc.nat(), (a, b, c) => {33 return numRoads(a, b, c) === a + b + c;34 })35);

Full Screen

Using AI Code Generation

copy

Full Screen

1const {numRoads} = require('fast-check-monorepo');2console.log(numRoads(4));3const {numRoads} = require('fast-check-monorepo');4console.log(numRoads(4));5const {numRoads} = require('fast-check-monorepo');6console.log(numRoads(4));7const {numRoads} = require('fast-check-monorepo');8console.log(numRoads(4));9const {numRoads} = require('fast-check-monorepo');10console.log(numRoads(4));11const {numRoads} = require('fast-check-monorepo');12console.log(numRoads(4));13const {numRoads} = require('fast-check-monorepo');14console.log(numRoads(4));15const {numRoads} = require('fast-check-monorepo');16console.log(numRoads(4));17const {numRoads} = require('fast-check-monorepo');18console.log(numRoads(4));19const {numRoads} = require('fast-check-monorepo');20console.log(numRoads(4));21const {numRoads} = require('fast-check-monorepo');22console.log(numRoads(4));23const {num

Full Screen

Using AI Code Generation

copy

Full Screen

1const { numRoads } = require('fast-check-monorepo');2const result = numRoads(4);3console.log(result);4const { numRoads } = require('fast-check-monorepo');5const result = numRoads(5);6console.log(result);7const { numRoads } = require('fast-check-monorepo');8const result = numRoads(6);9console.log(result);10const { numRoads } = require('fast-check-monorepo');11const result = numRoads(7);12console.log(result);13const { numRoads } = require('fast-check-monorepo');14const result = numRoads(8);15console.log(result);16const { numRoads } = require('fast-check-monorepo');17const result = numRoads(9);18console.log(result);19const { numRoads } = require('fast-check-monorepo');20const result = numRoads(10);21console.log(result);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { numRoads } = require('fast-check-monorepo');2const { expect } = require('chai');3describe('numRoads', () => {4 it('should return 0 for empty array', () => {5 const roads = [];6 expect(numRoads(roads)).to.equal(0);7 });8 it('should return 1 for array of 1 element', () => {9 const roads = [[1, 2]];10 expect(numRoads(roads)).to.equal(1);11 });12 it('should return 2 for array of 2 elements', () => {13 const roads = [[1, 2], [3, 4]];14 expect(numRoads(roads)).to.equal(2);15 });16});17const { numRoads } = require('fast-check-monorepo');18const { expect } = require('chai');19describe('numRoads', () => {20 it('should return 0 for empty array', () => {21 const roads = [];22 expect(numRoads(roads)).to.equal(0);23 });24 it('should return 1 for array of 1 element', () => {25 const roads = [[1, 2]];26 expect(numRoads(roads)).to.equal(1);27 });28 it('should return 2 for array of 2 elements', () => {29 const roads = [[1, 2], [3, 4]];30 expect(numRoads(roads)).to.equal(2);31 });32});33const { numRoads } = require('fast-check-monorepo');34const { expect } = require('chai');35describe('numRoads', () => {36 it('should return 0 for empty array', () => {37 const roads = [];38 expect(numRoads(roads)).to.equal(0);39 });40 it('should return 1 for array of 1 element', () => {41 const roads = [[1, 2]];42 expect(numRoads(roads)).to.equal(1);43 });44 it('should return 2 for array of 2 elements', () => {

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