Skip to content

Commit

Permalink
Merge 031dfa3 into f89955a
Browse files Browse the repository at this point in the history
  • Loading branch information
mcherryleigh committed Jan 14, 2019
2 parents f89955a + 031dfa3 commit faa87d5
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .docma.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config = {
undescribed: false,
ignored: false,
hierarchy: true,
sort: 'alphabetic',
sort: 'grouped',
relativePath: null,
filter: null,
allowUnknownTags: true,
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ node_modules

# Jetbrains IDE
.idea
*.iml
*.iml

# IDE Plugins
wallaby.js
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![npm version](http://img.shields.io/npm/v/make-believe.svg?style=flat)](https://npmjs.org/package/make-believe "View this project on npm")
[![](https://img.shields.io/github/release-date/mcherryleigh/make-believe.svg)](https://github.com/mcherryleigh/make-believe)
[![Dependencies](http://img.shields.io/david/mcherryleigh/make-believe.svg?style=flat)](https://david-dm.org/mcherryleigh/make-believe)
[![License](https://img.shields.io/github/license/mcherryleigh/make-believe.svg)](https://github.com/mcherryleigh/make-believe/blob/master/LICENSE)

[![Status](https://travis-ci.com/mcherryleigh/make-believe.svg?branch=master)](https://travis-ci.com/mcherryleigh/make-believe)
[![Coveralls](http://img.shields.io/coveralls/mcherryleigh/make-believe.svg?style=flat)](https://coveralls.io/r/mcherryleigh/make-believe)
Expand All @@ -13,26 +14,32 @@
# Make-believe
> A dreamy test data framework for NodeJS
Make-Believe is a javascript library for generating and managing test data for software applications.
Make-Believe is a javascript library for generating and managing test data for your software applications.

## Features
## Alpha Version 1.x.x - Warning
**Make-Believe** is in very early development and should be considered unstable until the 2.0.0 release.
Similarly, its documentation may be unreliable in places, much of it is currently being used to solicit feedback
on an eventual stable API and set of features for the library.

Under Construction
## Features
* Pseudorandom value generation.
* Combine the values into entities.
* Combine entities to create batches of data or larger, more complex scenarios.

## Links
- Project homepage: https://mcherryleigh.github.com/make-believe
- Repository: https://github.com/mcherryleigh/make-believe
- Issue tracker: https://github.com/mcherryleigh/make-believe/issues

## Licensing
The code in this project is licensed under MIT license. You can view the license [here](https://github.com/mcherryleigh/make-believe/blob/master/LICENSE).
The code in this project is licensed under MIT license. You can view the license [in the repo](https://github.com/mcherryleigh/make-believe/blob/master/LICENSE).

## Support

__Bugs and requests__: submit them through the project's issues tracker.<br>
[![Issues](http://img.shields.io/github/issues/mcherryleigh/make-believe.svg)]( https://github.com/mcherryleigh/make-believe/issues )

__Questions__: ask them at StackOverflow with the tag *REPO*.<br>
__Questions__: ask them at StackOverflow with the tag *make-believe*.<br>
[![StackOverflow](http://img.shields.io/badge/stackoverflow-make--believe-blue.svg)]( http://stackoverflow.com/questions/tagged/make-believe )

__Chat__: join us at gitter.im.<br>
Expand Down
5 changes: 1 addition & 4 deletions docs/DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
## Developing

Here's a brief intro about what a developer must do in order to start developing
the project further:
**Under Construction**

```shell
git clone https://github.com/mcherryleigh/make-believe.git
cd make-believe/
npm install
```

And state what happens step-by-step.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"docs": "npm run docs-build && npm run docs-serve --path=site_output",
"docs-build": "node .docma.js > docma.json && node_modules/.bin/docma",
"docs-serve": "node_modules/.bin/docma serve",
"lint": "eslint ./ ./test",
"lint": "eslint ./src ./test",
"lint-fix": "eslint ./src ./test --fix",
"test": "nyc ava",
"semantic-release": "semantic-release",
Expand Down
101 changes: 101 additions & 0 deletions src/Entity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* eslint-disable no-underscore-dangle */

/**
* @class Entity
* Class used to generate predictably random objects.
*/
class Entity {
/**
* Create an Entity. Provide options in an EntityOptionsObject
* @param {Object} [options={
* verbose: false,
* plugins: []
* }] - An options
* object
*/
constructor(options) {
const defaults = {
verbose: false,
};
this._options = Object.assign(defaults, options);
this._schema = this._options.schema;
this._variants = [];
this._outputs = [];
}

/**
* Get the seed that was used in the options object
* @return {String} Return the seed that was used in the options object or the integer
* which was generated if a seed was not given.
*/
get schema() {
return this._schema;
}

/**
* Get a random integer within a range.
* @method
* @param {Object} schema - An object representing this entity's baseline schema.
* @return {Entity} Return this entity.
*/
setSchema(schema) {
this._schema = schema;
return this;
}

get options() {
return this._options;
}

setOptions(options) {
this._options = Object.assign(this._options, options);
return this;
}

/**
* Get the seed that was used in the options object
* @return {String} Return the seed that was used in the options object or the integer
* which was generated if a seed was not given.
*/
get variants() {
return this._variants;
}

/**
* Add a variant to the Entity's schema
* @method
* @param {Object} variantSchema - An object representing how this object is
* different from the schema.
* @return {Entity} Return this entity.
*/
addVariant(variant) {
this._variants = this._variants.concat(variant);
return this;
}

/**
* Get any outputs that have been loaded into the Entity.
* @method
* @param {Object} variantSchema - An object representing how this object is
* different from the schema.
* @return {Entity} Return this entity.
*/
get outputs() {
return this._outputs;
}

addOutputs(outputs) {
this._outputs = this._outputs.concat(outputs);
return this;
}
}

module.exports = Entity;

/**
* @typedef {Object} Entity~OptionsObject
* @type Object
* @param {Number} [rv=null] - A configured RandomValue. If none is provided one will
* be created using default settings
* @param {Number} [verbose=false] - Use verbose to get additional console logging information.
*/
179 changes: 179 additions & 0 deletions src/RandomValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/* eslint-disable no-underscore-dangle */

/**
* @class RandomValue
* Class used to generate predictably random series of values.
*/
class RandomValue {
/**
* @typedef {Object} PluginObject
* @property {String} PluginObject.name - The name of your function. This will be used as the
* method name unless an altName is also provided.
* @property {String} PluginObject.altName - An override that will be used as the method name
* for your object
* @property {function} PluginObject.func - A function returning a value relative to your theme.
*/

/**
* @typedef {Object} OptionsObject
* @property {number} OptionsObject.seed - The x coordinate.
* @property {number} OptionsObject.verbose - The x coordinate.
* @property {PluginObject[]} OptionsObject.plugins - The y coordinate.
*/

/**
* Create a RandomValue generator. Use the OptionsObject
* to override default behavior.
* @param {OptionsObject} [options] - An options object to set the seed and
*/
constructor(options) {
const defaults = {
seed: Date.now(),
verbose: false,
plugins: [],
};
this._options = Object.assign(defaults, options);
// TODO handle strings in seed value
this._state = Math.abs(this._options.seed % 2147483646) + 1;
if (this._state <= 0) this._state += 2147483646;
}

/**
* Get the seed that was used in the options object
* @return {String} Return the seed that was used in the options object or the integer
* which was generated if a seed was not given.
*/
get seed() {
return this._options.seed;
}

/**
* Get the seed that was used in the options object
* @return {RandomValue} Return the seed that was used in the options object or the integer
* which was generated if a seed was not given.
*/
setSeed(seed) {
this._options.seed = seed;
return this;
}

/**
* Get the current state that will be used next random() call
* @return {number} Return the current state of the random generator.
*/
get state() {
return this._state;
}

/**
* Get the current state that will be used next random() call
* @return {OptionsObject} Return the current state of the random generator.
*/
get options() {
return this._options;
}

next() {
this._state = (this._state * 16807) % 2147483647;
return this._state;
}

/**
* Get the next random float in the series.
* @return {number} Return the current state of the random generator.
*/
random() {
// TODO is this ok without using Math.abs approach from constructor?
return (this.next() - 1) / 2147483646;
}

/**
* Get a random integer within a range.
* @param {number} min - The smallest integer you might generate.
* @param {number} max - The largest integer you might generate.
* @return {number} Return a random integer value.
*/
randomInteger(options) {
const one = this.random() * (options.max - options.min + 1);
return Math.floor(one + options.min);
}

/**
* Run a RandomValue method multiple times and return the result from each run in an array.
* @param {function} func - An array of values to pick from.
* @param {number} amount - How many values to pick from the array.
* @return {any[]} Return an array of values returned from the method.
*/
times() {
return this; // TODO
}

/**
* Pick one or more values from an array. Returned values may include duplicates.
* @param {any[]} pickArray - An array of values to pick from.
* @param {number} amount - How many values to pick from the array.
* @return {any|any[]} Return a value or an array of values from the pickArray.
*/
pick() {
return this;
}

/**
* Pick one or more values from an array. Returned values will be from uniquely picked indexes.
* @param {any[]} pickArray - An array of values to pick from.
* @param {number} amount - How many values to pick from the array.
* @return {any|any[]} Return a value or an array of values from the pickArray.
*/
pickUnique(pickArray, amount) {
const outArray = this.shuffle(pickArray).slice(0, amount);
return outArray;
}

/**
* Run a RandomValue method multiple times and return a series of values from .
* @param {function} method - An array of values to pick from.
* @param {number} amount - How many values to pick from the array.
* @return {any[]} Return an array of values returned from the method.
*/
pickSeries() {
return this; // TODO
}

/**
* Pick one or more values from an array. Returned values will be picked weighted
* relative to values given in the weightArray.
* @param {any[]} pickArray - An array of values to pick from.
* @param {number[]} weightArray - An array of values representing the weighting
* values corresponding to the pickArray.
* @param {number} amount - How many values to pick from the array.
* @return {any|any[]} Return a value or an array of values from the pickArray.
*/
pickWeighted() {
return this; // TODO
}

/**
* Shuffles array in place.
* @param {Array} a items An array containing the items.
*/
shuffle(arr) {
let j; let x; let i;
for (i = arr.length - 1; i > 0; i -= 1) {
j = Math.floor(this.random() * (i + 1));
x = arr[i];
arr[i] = arr[j]; // eslint-disable-line no-param-reassign
arr[j] = x; // eslint-disable-line no-param-reassign
// TODO figure out how to do this without silencing eslint
}
return arr;
}

toJSON() {
return {
options: this._options,
state: this._state,
};
}
}

module.exports = RandomValue;
10 changes: 2 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
/**
* truly returns true
* @return {boolean}
*/

exports.truly = function truly() {
return true;
};
exports.RandomValue = require('./RandomValue');
exports.Entity = require('./Entity');
Loading

0 comments on commit faa87d5

Please sign in to comment.