# test-value-generator

> Utility functions to generate incremental or unique values in automated tests.

Latest version **1.0.1** (published 2017-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install test-value-generator
pnpm add test-value-generator
yarn add test-value-generator
bun add test-value-generator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-11-28 |
| First published | 2017-11-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Media Engineering Institute |
| Maintainers | alphahydrae |
| Keywords | generator, spec, test, value |

## Links

- npm: https://www.npmjs.com/package/test-value-generator
- Repository: https://github.com/MediaComem/test-value-generator
- Homepage: https://github.com/MediaComem/test-value-generator#readme
- Issues: https://github.com/MediaComem/test-value-generator/issues
- npm.io page: https://npm.io/package/test-value-generator

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-11-28
- 1.0.0 — 2017-11-24

## README

# test-value-generator

Utilities to generate incremental and unique values in automated tests.

[![npm version](https://badge.fury.io/js/test-value-generator.svg)](https://badge.fury.io/js/test-value-generator)
[![Dependency Status](https://gemnasium.com/badges/github.com/MediaComem/test-value-generator.svg)](https://gemnasium.com/github.com/MediaComem/test-value-generator)
[![Build Status](https://travis-ci.org/MediaComem/test-value-generator.svg?branch=master)](https://travis-ci.org/MediaComem/test-value-generator)
[![Coverage Status](https://coveralls.io/repos/github/MediaComem/test-value-generator/badge.svg?branch=master)](https://coveralls.io/github/MediaComem/test-value-generator?branch=master)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Developed at the [Media Engineering Institute](http://mei.heig-vd.ch) ([HEIG-VD](https://heig-vd.ch)).



## Usage

This module exposes factory functions that return value generator functions when called:

```js
const testValueGenerator = require('test-value-generator');

// Create a value generator function:
const numberGenerator = testValueGenerator.incremental(i => i);
typeof(numberGenerator); // => "function"

// Generate a value by calling it:
numberGenerator(); // => 0
```

### Generating incremental values

```js
const testValueGenerator = require('test-value-generator');

// An incremental value generator helps you produce values containing
// a number that is incremented each time you use the generator.
const incrementalEmail = testValueGenerator.incremental(i => `email-${i}@example.com`);
incrementalEmail(); // => "email-0@example.com"
incrementalEmail(); // => "email-1@example.com"
incrementalEmail(); // => "email-2@example.com"
```

### Generating unique values

A value generator created with `unique` will call your function until it can
generate a value that it has not generated before. It will throw an error if it
fails after 10 attempts.

```js
const testValueGenerator = require('test-value-generator');

// A unique value generator makes sure to never produces the same value
// twice, and throws an error if it cannot.
const uniqueDiceRoll = testValueGenerator.unique(() => Math.floor(Math.random() * 6 + 1));
uniqueDiceRoll(); // => 3
uniqueDiceRoll(); // => 5
uniqueDiceRoll(); // => 6
uniqueDiceRoll(); // => 2
uniqueDiceRoll(); // => 1
uniqueDiceRoll(); // => 4
try {
  uniqueDiceRoll();
} catch(err) {
  // Error thrown: Could not generate unique value after 10 attempts.
}
```

---
_Source: https://npm.io/package/test-value-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
