-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(reverse): add tests for
reverse()
method
- Loading branch information
blond
committed
Aug 13, 2016
1 parent
711b7d2
commit cace49f
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'); | ||
|
||
const reverse = require('../../lib/reverse'); | ||
const createIterator = require('../../lib/create-iterator'); | ||
|
||
test('should throw error if specified two arguments', t => { | ||
const iter1 = createIterator([1, 2, 3]); | ||
const iter2 = createIterator([4, 5, 6]); | ||
|
||
t.throws( | ||
() => reverse(iter1, iter2), | ||
'The `resolve()` method not support more than one argument. Use `series() or `evenly()` to combine iterators.' | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'); | ||
|
||
const reverse = require('../../lib/reverse'); | ||
const createIterator = require('../../lib/create-iterator'); | ||
|
||
test('should return empty iterator', t => { | ||
const iter = reverse(); | ||
|
||
t.deepEqual(iter.next(), { done: true }); | ||
}); | ||
|
||
test('should support empty iterator', t => { | ||
const emptyIter = createIterator(); | ||
|
||
const iter = reverse(emptyIter); | ||
|
||
t.deepEqual(iter.next(), { done: true }); | ||
}); | ||
|
||
test('should reverse iterator', t => { | ||
const iter = createIterator([1, 2]); | ||
|
||
const reverseIter = reverse(iter); | ||
|
||
t.deepEqual(Array.from(reverseIter), [2, 1]); | ||
}); | ||
|
||
test('should support iterable', t => { | ||
const iterable = [1, 2]; | ||
|
||
const reverseIter = reverse(iterable); | ||
|
||
t.deepEqual(Array.from(reverseIter), [2, 1]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'); | ||
|
||
const reverse = require('../../lib/reverse'); | ||
|
||
test('should throw error if value is `null`', t => { | ||
t.throws(() => reverse(null)); | ||
}); | ||
|
||
test('should throw error if value is `undefined`', t => { | ||
t.throws(() => reverse(undefined)); | ||
}); | ||
|
||
test('should throw error if value is number', t => { | ||
t.throws(() => reverse(123)); | ||
}); | ||
|
||
test('should throw error if value is boolean', t => { | ||
t.throws(() => reverse(true)); | ||
}); | ||
|
||
test('should reverse string characters', t => { | ||
const iter = reverse('str'); | ||
|
||
t.deepEqual(Array.from(iter), ['r', 't', 's']); | ||
}); |