Skip to content

Commit 1d26013

Browse files
committed
Rewrite and reorganize tests
1 parent 8efef6d commit 1d26013

38 files changed

+554
-574
lines changed

test/concat-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as lazy from '../';
2+
3+
describe(`concat()`, function() {
4+
const lst1 = lazy.list(1,2,3);
5+
const lst2 = lazy.list(4,5,6);
6+
const lst3 = lazy.list();
7+
const xss = lazy.list(lst1, lst2, lst3);
8+
it(`should concatenate (flatten) the elements in a list of lists`, function() {
9+
lazy.concat(xss).should.eql(lazy.list(1,2,3,4,5,6));
10+
});
11+
});

test/cons-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as lazy from '../';
2+
3+
describe(`cons()`, function() {
4+
const lst = lazy.list(4,5,6);
5+
it(`should create a new list from a head and tail`, function() {
6+
lazy.cons(3, lst).should.eql(lazy.list(3,4,5,6));
7+
lazy.cons(1, lazy.emptyList).should.eql(lazy.list(1));
8+
});
9+
});

test/cycle-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as lazy from '../';
2+
3+
describe(`cycle()`, function() {
4+
const lst = lazy.list(1,2,3);
5+
const cyc = lazy.cycle(lst);
6+
it(`should return the infinite repetition of a list`, function() {
7+
lazy.take(9, cyc).should.eql(lazy.list(1,2,3,1,2,3,1,2,3));
8+
lazy.index(cyc, 100).should.equal(2);
9+
});
10+
it(`should throw an error if the list is empty`, function() {
11+
lazy.cycle.bind(null, lazy.emptyList).should.throw();
12+
});
13+
});

test/drop-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as lazy from '../';
2+
3+
describe(`drop()`, function() {
4+
const lst = lazy.list(1,2,3);
5+
it(`should return the suffix of a list after discarding a specified number of values`, function() {
6+
lazy.drop(2, lst).should.eql(lazy.list(3));
7+
});
8+
it(`should return the empty list if the second argument is the empty list`, function() {
9+
lazy.drop(2, lazy.list()).should.equal(lazy.emptyList);
10+
});
11+
});

test/dropWhile-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as lazy from '../';
2+
3+
describe(`dropWhile()`, function() {
4+
const lst = lazy.list(1,2,3,4,5,6,7,8,9,10);
5+
const f = x => x < 3;
6+
it(`should drop values from a list while a given predicate function returns true`, function() {
7+
lazy.dropWhile(f, lst).should.eql(lazy.list(3,4,5,6,7,8,9,10));
8+
});
9+
it(`should return an empty list if the second argument is an empty list`, function() {
10+
lazy.dropWhile(f, lazy.emptyList).should.equal(lazy.emptyList);
11+
});
12+
});

test/emptyList-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as lazy from '../';
2+
3+
describe(`emptyList`, function() {
4+
const lst = lazy.list();
5+
it(`should be an empty list`, function() {
6+
lst.should.equal(lazy.emptyList);
7+
lazy.emptyList.should.equal(lst);
8+
lazy.length(lazy.emptyList).should.equal(0);
9+
});
10+
});

test/filter-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as lazy from '../';
2+
3+
describe(`filter()`, function() {
4+
const lst = lazy.listRangeBy(0, 50, x => x + 5);
5+
const f = x => x % 10 === 0;
6+
it(`should return the list of elements in a list for which a function f returns true`, function() {
7+
lazy.filter(f, lst).should.eql(lazy.list(0,10,20,30,40,50));
8+
});
9+
});

test/fromArrayToList-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as lazy from '../';
2+
3+
describe(`fromArrayToList()`, function() {
4+
const lst = lazy.list(1,2,3);
5+
const arr = [1,2,3];
6+
it(`should convert an array into a list`, function() {
7+
lazy.fromArrayToList(arr).should.eql(lst);
8+
});
9+
});

test/fromListToArray-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as lazy from '../';
2+
3+
describe(`fromListToArray()`, function() {
4+
const lst = lazy.list(1,2,3);
5+
const arr = [1,2,3];
6+
it(`should convert a list into an array`, function() {
7+
lazy.fromListToArray(lst).should.eql(arr);
8+
});
9+
});

test/fromListToString-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as lazy from '../';
2+
3+
describe(`fromListToString()`, function() {
4+
const str = lazy.list(`a`,`b`,`c`);
5+
it(`should convert a list into a string`, function() {
6+
lazy.fromListToString(str).should.equal(`abc`);
7+
});
8+
});

0 commit comments

Comments
 (0)