|
| 1 | +import test from 'ava' |
| 2 | +import {reduceCount} from '../src' |
| 3 | + |
| 4 | +test('first param has to be an array', t => { |
| 5 | + const array = {} |
| 6 | + const expected = `${array} isn't an array.` |
| 7 | + const actual = reduceCount(array, 0) |
| 8 | + t.deepEqual(actual, expected) |
| 9 | +}) |
| 10 | + |
| 11 | +test('array must have at least one value', t => { |
| 12 | + const array = [] |
| 13 | + const expected = `${array} is empty.` |
| 14 | + const actual = reduceCount(array, 0) |
| 15 | + t.deepEqual(actual, expected) |
| 16 | +}) |
| 17 | + |
| 18 | +test('array will count occurences of integer param', t => { |
| 19 | + const array = [1, 2, [1, 3], 4, 5, [1, 6, 7]] |
| 20 | + const expected = 3 |
| 21 | + const actual = reduceCount(array, 1) |
| 22 | + t.deepEqual(actual, expected) |
| 23 | +}) |
| 24 | + |
| 25 | +test('array will count occurences of string param', t => { |
| 26 | + const array = ['six', 2, [1, 'six'], 4, 5, [1, 'six', 7], 'six', 'sicks'] |
| 27 | + const expected = 4 |
| 28 | + const actual = reduceCount(array, 'six') |
| 29 | + t.deepEqual(actual, expected) |
| 30 | +}) |
| 31 | + |
| 32 | +test('array will count occurences of float param', t => { |
| 33 | + const array = [1, 2, [1, 3], 4, 6.4, [1, 6.4, 7], 6.4, 6.5, 4.6] |
| 34 | + const expected = 3 |
| 35 | + const actual = reduceCount(array, 6.4) |
| 36 | + t.deepEqual(actual, expected) |
| 37 | +}) |
0 commit comments