Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions generators/lazy-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ class Benchmark {
toArray(),
);

this.totalLength += example().length;
this.totalLength += this.checkLength(example(), 3);

const factorials = pipe(
factorial(),
Expand All @@ -533,18 +533,18 @@ class Benchmark {
toArray(),
);

this.totalLength += factorials().length;
this.totalLength += this.checkLength(factorials(), 100);

const doubleFibonaccis = pipe(
fibonacci(),
take(78),
windows(3),
flatMap(x => x * 2),
flatMap(window => window.map(x => x * 2)),
unique(),
toArray(),
);

this.totalLength += doubleFibonaccis().length;
this.totalLength += this.checkLength(doubleFibonaccis(), 77);

const mersennePrimes = pipe(
naturalNumbers(),
Expand All @@ -554,7 +554,7 @@ class Benchmark {
toArray(),
);

this.totalLength += mersennePrimes().length;
this.totalLength += this.checkLength(mersennePrimes(), 5);

const primes = pipe(
naturalNumbers(),
Expand All @@ -563,7 +563,7 @@ class Benchmark {
toArray(),
);

this.totalLength += primes().length;
this.totalLength += this.checkLength(primes(), 150);

const powersOfTwo = pipe(
powers(1, 2),
Expand All @@ -573,7 +573,7 @@ class Benchmark {
toArray(),
);

this.totalLength += powersOfTwo().length;
this.totalLength += this.checkLength(powersOfTwo(), 100);

const primeFactors = pipe(
naturalNumbers(),
Expand All @@ -584,7 +584,7 @@ class Benchmark {
toArray(),
);

this.totalLength += primeFactors().length;
this.totalLength += this.checkLength(primeFactors(), 150);

const fizzbuzz = pipe(
naturalNumbers(),
Expand All @@ -598,7 +598,7 @@ class Benchmark {
toArray(),
);

this.totalLength += fizzbuzz().length;
this.totalLength += this.checkLength(fizzbuzz(), 100);

const binaryTree = pipe(
binaryRoot[Symbol.iterator](),
Expand All @@ -610,11 +610,20 @@ class Benchmark {
toArray(),
);

this.totalLength += binaryTree().length;
this.totalLength += this.checkLength(binaryTree(), 26);
}

checkLength(pipe, expected){
const length = pipe.length;
if (length !== expected) {
throw new Error(`Expected result.length == ${expected}, but got ${length}`);
}
return length;
}

validate(iterations) {
if (this.totalLength !== 635)
throw new Error(`this.totalLength of ${this.totalLength} is invalid!`);
const TOTAL_LENGTH = 711;
if (this.totalLength !== TOTAL_LENGTH)
throw new Error(`Expected this.totalLength of ${TOTAL_LENGTH} but got ${this.totalLength}!`);
}
}
Loading