Skip to content

Commit

Permalink
test(zip): update zip tests for variable sources
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed Oct 10, 2017
1 parent 828dc5c commit 9c62a34
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 22 deletions.
6 changes: 3 additions & 3 deletions spec/asynciterable-operators/memoize-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async function* rand() {

test('AsyncIterable#memoize should share effects of random', async t => {
const rnd = memoize(take(rand(), 100));
t.true(await every(zip(rnd, rnd, async (l, r) => l === r), async x => x));
t.true(await every(zip(rnd, rnd, async ([l, r]) => l === r), async x => x));
t.end();
});

Expand All @@ -189,7 +189,7 @@ test('AsyncIterable#memoize with selector', async t => {
memoize(
tap(range(0, 4), { next: async () => { n++; } }),
undefined,
xs => take(zip(xs, xs, async (l, r) => l + r), 4)
xs => take(zip(xs, xs, async ([l, r]) => l + r), 4)
)
);

Expand All @@ -204,7 +204,7 @@ test('AsyncIterable#memoize limited with selector', async t => {
memoize(
tap(range(0, 4), { next: async () => { n++; } }),
2,
xs => take(zip(xs, xs, async (l, r) => l + r), 4)
xs => take(zip(xs, xs, async ([l, r]) => l + r), 4)
)
);

Expand Down
2 changes: 1 addition & 1 deletion spec/asynciterable-operators/publish-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ test('AsyncIterable#publish with selector', async t => {
const res = await toArray(
publish(
tap(range(0, 10), { next: async () => { n++; } }),
xs => take(zip(xs, xs, async (l, r) => l + r), 4)
xs => take(zip(xs, xs, async ([l, r]) => l + r), 4)
)
);

Expand Down
2 changes: 1 addition & 1 deletion spec/asynciterable-operators/share-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test('AsyncIterable#share with selector', async t => {
const res = await toArray(
share(
tap(range(0, 10), { next: async () => { n++;} }),
xs => take(zip(xs, xs, (l, r) => l + r), 4)
xs => take(zip(xs, xs, ([l, r]) => l + r), 4)
)
);

Expand Down
26 changes: 20 additions & 6 deletions spec/asynciterable-operators/zip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { hasNext, noNext } from '../asynciterablehelpers';
test('AsyncIterable#zip equal length', async t => {
const xs = of(1, 2, 3);
const ys = of(4, 5, 6);
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.asyncIterator]();
await hasNext(t, it, 1 * 4);
Expand All @@ -21,7 +21,7 @@ test('AsyncIterable#zip equal length', async t => {
test('AsyncIterable#zip left longer', async t => {
const xs = of(1, 2, 3, 4);
const ys = of(4, 5, 6);
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.asyncIterator]();
await hasNext(t, it, 1 * 4);
Expand All @@ -34,7 +34,7 @@ test('AsyncIterable#zip left longer', async t => {
test('AsyncIterable#zip right longer', async t => {
const xs = of(1, 2, 3);
const ys = of(4, 5, 6, 7);
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.asyncIterator]();
await hasNext(t, it, 1 * 4);
Expand All @@ -44,11 +44,25 @@ test('AsyncIterable#zip right longer', async t => {
t.end();
});

test('AsyncIterable#zip multiple sources', async t => {
const xs = of(1, 2, 3);
const ys = of(4, 5, 6, 7);
const zs = of(8, 9, 10);
const res = zip(xs, ys, zs, ([x, y, z]) => x * y * z);

const it = res[Symbol.asyncIterator]();
await hasNext(t, it, 1 * 4 * 8);
await hasNext(t, it, 2 * 5 * 9);
await hasNext(t, it, 3 * 6 * 10);
await noNext(t, it);
t.end();
});

test('AsyncIterable#zip left throws', async t => {
const err = new Error();
const xs = _throw<number>(err);
const ys = of(4, 5, 6);
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.asyncIterator]();
try {
Expand All @@ -63,7 +77,7 @@ test('AsyncIterable#zip right throws', async t => {
const err = new Error();
const xs = of(1, 2, 3);
const ys = _throw<number>(err);
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.asyncIterator]();
try {
Expand All @@ -78,7 +92,7 @@ test('AsyncIterable#zip selector throws', async t => {
const err = new Error();
const xs = of(1, 2, 3);
const ys = of(4, 5, 6);
const res = zip(xs, ys, (x, y) => { if (x > 0) { throw err; } return x * y; });
const res = zip(xs, ys, ([x, y]) => { if (x > 0) { throw err; } return x * y; });

const it = res[Symbol.asyncIterator]();
try {
Expand Down
6 changes: 3 additions & 3 deletions spec/iterable-operators/memoize-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function* rand() {

test('Iterable#memoize should share effects of random', t => {
const rnd = memoize(take(rand(), 100));
t.true(every(zip(rnd, rnd, (l, r) => l === r), x => x));
t.true(every(zip(rnd, rnd, ([l, r]) => l === r), x => x));
t.end();
});

Expand All @@ -176,7 +176,7 @@ test('Iterable#memoize with selector', t => {
memoize(
tap(range(0, 4), { next: () => n++ }),
undefined,
xs => take(zip(xs, xs, (l, r) => l + r), 4)
xs => take(zip(xs, xs, ([l, r]) => l + r), 4)
)
);

Expand All @@ -191,7 +191,7 @@ test('Iterable#memoize limited with selector', t => {
memoize(
tap(range(0, 4), { next: () => n++ }),
2,
xs => take(zip(xs, xs, (l, r) => l + r), 4)
xs => take(zip(xs, xs, ([l, r]) => l + r), 4)
)
);

Expand Down
2 changes: 1 addition & 1 deletion spec/iterable-operators/publish-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ test('Iterable#publish with selector', t => {
const res = toArray(
publish(
tap(range(0, 10), { next: () => n++ }),
xs => take(zip(xs, xs, (l, r) => l + r), 4)
xs => take(zip(xs, xs, ([l, r]) => l + r), 4)
)
);

Expand Down
2 changes: 1 addition & 1 deletion spec/iterable-operators/share-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test('Iterable#share with selector', t => {
const res = toArray(
share(
tap(range(0, 10), { next: () => n++ }),
xs => take(zip(xs, xs, (l, r) => l + r), 4)
xs => take(zip(xs, xs, ([l, r]) => l + r), 4)
)
);

Expand Down
26 changes: 20 additions & 6 deletions spec/iterable-operators/zip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hasNext, noNext } from '../iterablehelpers';
test('Iterable#zip equal length', t => {
const xs = [1, 2, 3];
const ys = [4, 5, 6];
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.iterator]();
hasNext(t, it, 1 * 4);
Expand All @@ -20,7 +20,7 @@ test('Iterable#zip equal length', t => {
test('Iterable#zip left longer', t => {
const xs = [1, 2, 3, 4];
const ys = [4, 5, 6];
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.iterator]();
hasNext(t, it, 1 * 4);
Expand All @@ -33,7 +33,7 @@ test('Iterable#zip left longer', t => {
test('Iterable#zip right longer', t => {
const xs = [1, 2, 3];
const ys = [4, 5, 6, 7];
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.iterator]();
hasNext(t, it, 1 * 4);
Expand All @@ -43,10 +43,24 @@ test('Iterable#zip right longer', t => {
t.end();
});

test('Iterable#zip multiple sources', t => {
const xs = [1, 2, 3];
const ys = [4, 5, 6, 7];
const zs = [8, 9, 10];
const res = zip(xs, ys, zs, ([x, y, z]) => x * y * z);

const it = res[Symbol.iterator]();
hasNext(t, it, 1 * 4 * 8);
hasNext(t, it, 2 * 5 * 9);
hasNext(t, it, 3 * 6 * 10);
noNext(t, it);
t.end();
});

test('Iterable#zip left throws', t => {
const xs = _throw<number>(new Error());
const ys = [4, 5, 6];
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.iterator]();
t.throws(() => it.next());
Expand All @@ -56,7 +70,7 @@ test('Iterable#zip left throws', t => {
test('Iterable#zip right throws', t => {
const xs = [1, 2, 3];
const ys = _throw<number>(new Error());
const res = zip(xs, ys, (x, y) => x * y);
const res = zip(xs, ys, ([x, y]) => x * y);

const it = res[Symbol.iterator]();
t.throws(() => it.next());
Expand All @@ -66,7 +80,7 @@ test('Iterable#zip right throws', t => {
test('Iterable#zip selector throws', t => {
const xs = [1, 2, 3];
const ys = [4, 5, 6];
const res = zip(xs, ys, (x, y) => { if (x > 0) { throw new Error(); } return x * y; });
const res = zip(xs, ys, ([x, y]) => { if (x > 0) { throw new Error(); } return x * y; });

const it = res[Symbol.iterator]();
t.throws(() => it.next());
Expand Down

0 comments on commit 9c62a34

Please sign in to comment.