Skip to content

Commit

Permalink
Merge branch 'feature/take-while&&skip-while' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Keloo committed Aug 9, 2018
2 parents 31af860 + 7e38097 commit 2d6f80b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/iterators/skipWhile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,30 @@ describe('iterators/skipWhile', () => {
expect(toArray(iterator)).to.deep.equal([]);
});
});

describe('When take elements by index', () => {
it('Should return 3 elements', () => {
const source = [1, 2, 3, 4, 5, 5, 5];
const iterator = skipWhile(source, (e, idx) => idx <= 3);

expect(toArray(iterator)).to.deep.equal([5, 5, 5]);
});
});

describe('When take elements by object property', () => {
it('Should return 2 elements', () => {
const source = [
{ val: 1 },
{ val: 10 },
{ val: -1 },
{ val: -2 },
];
const iterator = skipWhile(source, e => e.val > 0);

expect(toArray(iterator)).to.deep.equal([
{ val: -1 },
{ val: -2 },
]);
});
});
});
26 changes: 26 additions & 0 deletions test/iterators/takeWhile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,30 @@ describe('iterators/takeWhile', () => {
expect(toArray(iterator)).to.deep.equal([]);
});
});

describe('When take elements by index', () => {
it('Should return 3 elements', () => {
const source = [1, 2, 3, 4, 5, 5, 5];
const iterator = takeWhile(source, (e, idx) => idx < 3);

expect(toArray(iterator)).to.deep.equal([1, 2, 3]);
});
});

describe('When take elements by object property', () => {
it('Should return 2 elements', () => {
const source = [
{ val: 1 },
{ val: 10 },
{ val: -1 },
{ val: -2 },
];
const iterator = takeWhile(source, e => e.val > 0);

expect(toArray(iterator)).to.deep.equal([
{ val: 1 },
{ val: 10 },
]);
});
});
});

0 comments on commit 2d6f80b

Please sign in to comment.