chore: use generator for range utility (#8825)

* chore: use generator for range utility

* chore: update doc examples

* chore: fix spelling

* chore: fix typo

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Suneet Tipirneni
2022-12-25 13:43:58 -07:00
committed by GitHub
parent a6941d536c
commit 3160ab0fc7
3 changed files with 60 additions and 14 deletions

View File

@@ -2,11 +2,15 @@ import { describe, test, expect } from 'vitest';
import { range } from '../src/index.js';
describe('range', () => {
test('GIVEN valid range THEN valid array is returned', () => {
expect(range(0, 5)).toEqual([0, 1, 2, 3, 4, 5]);
test('GIVEN valid range and then valid numbers are returned', () => {
expect([...range(5)]).toEqual([0, 1, 2, 3, 4]);
});
test('GIVEN valid range with step THEN valid array is returned', () => {
expect(range(0, 10, 2)).toEqual([0, 2, 4, 6, 8, 10]);
test('GIVEN valid range with start and end THEN valid numbers are returned', () => {
expect([...range({ start: 0, end: 5 })]).toEqual([0, 1, 2, 3, 4]);
});
test('GIVEN valid range with start, end and step THEN valid numbers are returned', () => {
expect([...range({ start: 0, end: 11, step: 2 })]).toEqual([0, 2, 4, 6, 8, 10]);
});
});