From c69269e8098998c370a5d9bdd1ee1a6029d9e5f0 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 18 Aug 2024 17:56:37 +0100 Subject: [PATCH] Remove examples --- README.md | 7 ------- examples/README.md | 14 ------------- examples/cartesian.js | 45 ---------------------------------------- examples/functions.js | 26 ----------------------- examples/fuzz.js | 22 -------------------- examples/iterables.js | 26 ----------------------- examples/main.js | 28 ------------------------- examples/multiply.js | 2 -- examples/side_effects.js | 23 -------------------- examples/title.js | 37 --------------------------------- 10 files changed, 230 deletions(-) delete mode 100644 examples/README.md delete mode 100644 examples/cartesian.js delete mode 100644 examples/functions.js delete mode 100644 examples/fuzz.js delete mode 100644 examples/iterables.js delete mode 100644 examples/main.js delete mode 100644 examples/multiply.js delete mode 100644 examples/side_effects.js delete mode 100644 examples/title.js diff --git a/README.md b/README.md index ac948af..a6d9381 100644 --- a/README.md +++ b/README.md @@ -93,13 +93,6 @@ each(1000, Math.random, ({ title }, index, randomNumber) => { }) ``` -# Demo - -You can try this library: - -- either directly [in your browser](https://repl.it/@ehmicky/test-each). -- or by executing the [`examples` files](examples/README.md) in a terminal. - # Install ``` diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index 869045d..0000000 --- a/examples/README.md +++ /dev/null @@ -1,14 +0,0 @@ -This directory contains examples of this library. They can be run and edited: - -- either directly [in your browser](https://repl.it/@ehmicky/test-each) -- or in a terminal by cloning this repository - -## Examples - -- [Main usage](main.js) -- [Test titles](title.js) -- [Cartesian product](cartesian.js) -- [Input functions](functions.js) -- [Fuzz testing](fuzz.js) -- [Side effects](side_effects.js) -- [Iterables](iterables.js) diff --git a/examples/cartesian.js b/examples/cartesian.js deleted file mode 100644 index 3cdd247..0000000 --- a/examples/cartesian.js +++ /dev/null @@ -1,45 +0,0 @@ -// Demo of cartesian products. -// This file can be directly run: -// - first install `test-each` -// - then `node node_modules/test-each/examples/cartesian.js` -// An online demo is also available at: -// https://repl.it/@ehmicky/test-each - -import assert from 'node:assert' - -import { multiply } from './multiply.js' - -import { each } from 'test-each' - -// The code we are testing - -// Cartesian product. -// Run this test 4 times using every possible combination of inputs -each([0.5, 10], [2.5, 5], ({ title }, first, second) => { - assert( - typeof multiply(first, second) === 'number', - `should mix integers and floats | ${title}`, - ) -}) - -// Run callback five times: a -> b -> c -> d -> e -each(['a', 'b', 'c', 'd', 'e'], (info, param) => { - console.log(param) -}) - -// Run callback six times: a c -> a d -> a e -> b c -> b d -> b e -each(['a', 'b'], ['c', 'd', 'e'], (info, param, otherParam) => { - console.log(param, otherParam) -}) - -// Nested arrays are not iterated. -// This runs callback twice with an array `param`: ['a', 'b'] -> ['c', 'd', 'e'] -each( - [ - ['a', 'b'], - ['c', 'd', 'e'], - ], - (info, param) => { - console.log(param) - }, -) diff --git a/examples/functions.js b/examples/functions.js deleted file mode 100644 index ca11a1f..0000000 --- a/examples/functions.js +++ /dev/null @@ -1,26 +0,0 @@ -// Demo of input functions. -// This file can be directly run: -// - first install `test-each` -// - then `node node_modules/test-each/examples/functions.js` -// An online demo is also available at: -// https://repl.it/@ehmicky/test-each - -import { each } from 'test-each' - -// Run callback with a different random number each time -each(['red', 'green', 'blue'], Math.random, (info, color, randomNumber) => { - console.log(color, randomNumber) -}) - -// Input functions are called with the same arguments as the callback -/* eslint-disable max-params */ -each( - ['02', '15', '30'], - ['January', 'February', 'March'], - ['1980', '1981'], - (info, day, month, year) => `${day}/${month}/${year}`, - (info, day, month, year, date) => { - console.log(date) - }, -) -/* eslint-enable max-params */ diff --git a/examples/fuzz.js b/examples/fuzz.js deleted file mode 100644 index f5d0176..0000000 --- a/examples/fuzz.js +++ /dev/null @@ -1,22 +0,0 @@ -// Demo of fuzz testing. -// This file can be directly run: -// - first install `test-each` -// - then `node node_modules/test-each/examples/fuzz.js` -// An online demo is also available at: -// https://repl.it/@ehmicky/test-each - -import assert from 'node:assert' - -import { multiply } from './multiply.js' - -import { each } from 'test-each' - -// The code we are testing - -// Fuzz testing. Run this test 1000 times using different numbers. -each(1000, Math.random, ({ title }, index, randomNumber) => { - assert( - multiply(randomNumber, 1) === randomNumber, - `should correctly multiply floats | ${title}`, - ) -}) diff --git a/examples/iterables.js b/examples/iterables.js deleted file mode 100644 index fc67653..0000000 --- a/examples/iterables.js +++ /dev/null @@ -1,26 +0,0 @@ -// Demo of `iterable()`. -// This file can be directly run: -// - first install `test-each` -// - then `node node_modules/test-each/examples/iterables.js` -// An online demo is also available at: -// https://repl.it/@ehmicky/test-each - -import { iterable } from 'test-each' - -const combinations = iterable( - ['green', 'red', 'blue'], - [{ active: true }, { active: false }], -) - -// eslint-disable-next-line fp/no-loops -for (const [{ title }, color, param] of combinations) { - console.log(title, color, param) -} - -const array = [ - ...iterable(['green', 'red', 'blue'], [{ active: true }, { active: false }]), -] - -array.forEach(([{ title }, color, param]) => { - console.log(title, color, param) -}) diff --git a/examples/main.js b/examples/main.js deleted file mode 100644 index 2feec58..0000000 --- a/examples/main.js +++ /dev/null @@ -1,28 +0,0 @@ -// Demo of the main usage. -// This file can be directly run: -// - first install `test-each` -// - then `node node_modules/test-each/examples/main.js` -// An online demo is also available at: -// https://repl.it/@ehmicky/test-each - -import assert from 'node:assert' - -import { multiply } from './multiply.js' - -import { each } from 'test-each' - -// The code we are testing - -// Repeat test using different inputs and expected outputs -each( - [ - { first: 2, second: 2, output: 4 }, - { first: 3, second: 3, output: 9 }, - ], - ({ title }, { first, second, output }) => { - // Assertion titles will be: - // should multiply | {"first": 2, "second": 2, "output": 4} - // should multiply | {"first": 3, "second": 3, "output": 9} - assert(multiply(first, second) === output, `should multiply | ${title}`) - }, -) diff --git a/examples/multiply.js b/examples/multiply.js deleted file mode 100644 index 59c233b..0000000 --- a/examples/multiply.js +++ /dev/null @@ -1,2 +0,0 @@ -// The code we are testing -export const multiply = (first, second) => Number(first) * Number(second) diff --git a/examples/side_effects.js b/examples/side_effects.js deleted file mode 100644 index 044632a..0000000 --- a/examples/side_effects.js +++ /dev/null @@ -1,23 +0,0 @@ -// Demo of side effects. -// This file can be directly run: -// - first install `test-each` -// - then `node node_modules/test-each/examples/side_effects.js` -// An online demo is also available at: -// https://repl.it/@ehmicky/test-each - -import { each } from 'test-each' - -/* eslint-disable fp/no-mutation */ -each( - ['green', 'red', 'blue'], - [{ active: true }, { active: false }], - (info, color, param) => { - // This should not be done, as the objects are re-used in several iterations - // param.active = false - - // But this is safe since it's a copy - const newParam = { ...param } - newParam.active = false - }, -) -/* eslint-enable fp/no-mutation */ diff --git a/examples/title.js b/examples/title.js deleted file mode 100644 index 7a9f9d1..0000000 --- a/examples/title.js +++ /dev/null @@ -1,37 +0,0 @@ -// Demo of test titles. -// This file can be directly run: -// - first install `test-each` -// - then `node node_modules/test-each/examples/title.js` -// An online demo is also available at: -// https://repl.it/@ehmicky/test-each - -import { each } from 'test-each' - -each([{ color: 'red' }, { color: 'blue' }], ({ title }) => { - // Titles will be: - // should test color | {"color": "red"} - // should test color | {"color": "blue"} - console.log(`should test color | ${title}`) -}) - -// Plain objects can override this using a `title` property -each( - [ - { color: 'red', title: 'Red' }, - { color: 'blue', title: 'Blue' }, - ], - ({ title }) => { - // Titles will be: - // should test color | Red - // should test color | Blue - console.log(`should test color | ${title}`) - }, -) - -// The `info` argument can be used for dynamic titles -each([{ color: 'red' }, { color: 'blue' }], (info, param) => { - // Test titles will be: - // should test color | 0 red - // should test color | 1 blue - console.log(`should test color | ${info.index} ${param.color}`) -})