Skip to content

Commit

Permalink
ranges tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrieder committed Apr 14, 2017
1 parent 613a3a3 commit 0d47ab4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
14 changes: 4 additions & 10 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function seq<A>( ...values: any[] ): Seq<A>

Range
-----
The Range class represents numeric values in range [start;end) with non-zero step value step.
The Range class represents numeric values in range with non-zero step value step.
A Range is a special case of Seq.

```typescript
Expand All @@ -143,26 +143,20 @@ A Range is a special case of Seq.
export function range( length: number ): Range;

/**
* Create a range from the specified start to the element end-1 included in step of 1
* Create a range from the specified start to the element (end - 1) included in steps of 1
*/
export function range( start: number, end: number ): Range

/**
* Create a range from start to end-step included
* Create a range from start to (end - step) included
*/
export function range( start: number, end: number, step: number ): Range
```

Ranges are not indexed but based on (lazy) iterators.

- it is therefore possible to manipulate `Infinity` in Ranges:
Ranges are not indexed but based on (lazy) iterators; it is therefore possible to manipulate `Infinity` in Ranges:
```javascript
range(0, Infinity).take(10).toArray //[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
```
- however, accessing elements by index is slow. When the range is small, convert it to an array if multiple accesses are required
```javascript
seq(range(1000).toArray).at(3)
```

Try
---
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "m.m",
"version": "1.0.0-alpha.5",
"version": "1.0.0",
"description": "A few missing monads for javascript and typescript",
"private": false,
"repository": {
Expand Down
33 changes: 33 additions & 0 deletions typescript/test/Range.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Author: Bruno Grieder
*/
import {range, Range} from '../Range'

require( 'source-map-support' ).install()
import chai = require('chai')


const deepEqual: ( act: any, exp: any, msg?: string ) => void = chai.assert.deepEqual;


describe( 'Range', function () {

before( ( done: MochaDone ) => {
done()
} )

after( ( done: MochaDone ) => {
done()
} )

it( 'range', ( done: MochaDone ) => {
deepEqual( range( 10 ).toArray, [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], 'range failed' )
deepEqual( range( 2, 10 ).toArray, [ 2, 3, 4, 5, 6, 7, 8, 9 ], 'range failed' )
deepEqual( range( 3, 10, 2 ).toArray, [ 3, 5, 7, 9 ], 'range failed' )
done()
} )

} )



0 comments on commit 0d47ab4

Please sign in to comment.