Skip to content

Commit

Permalink
test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
N8Brooks committed Oct 6, 2021
1 parent 1cb37e9 commit 7d371e8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
10 changes: 5 additions & 5 deletions combinations_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Deno.test("r < n", () => {
assertEquals(actual, expected);
});

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
for (let r = 0; r < 8; r++) {
Deno.test(`comb(${r}, ${n})`, () => {
Expand All @@ -90,21 +90,21 @@ for (let n = 0; n <= 8; n++) {
}
}

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
for (let r = 0; r < 8; r++) {
Deno.test(`combinations1([${r}, ${iterable}])`, () => {
Deno.test(`combinations1(${r}, [${iterable}])`, () => {
const actual = [...combinations(r, iterable)];
const expected1 = [...combinations1(r, iterable)];
assertEquals(actual, expected1);
});
}
}

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
for (let r = 0; r < 8; r++) {
Deno.test(`combinations2([${r}, ${iterable}])`, () => {
Deno.test(`combinations2(${r}, [${iterable}])`, () => {
const actual = [...combinations(r, iterable)];
const expected2 = [...combinations2(r, iterable)];
assertEquals(actual, expected2);
Expand Down
4 changes: 2 additions & 2 deletions combinations_with_replacement_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Deno.test("r = 65_537", () => {
assertEquals(actual, expected);
});

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
for (let r = 0; r < 8; r++) {
Deno.test(`cwr(${r}, ${n})`, () => {
Expand All @@ -125,7 +125,7 @@ for (let n = 0; n <= 8; n++) {
}
}

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
for (let r = 0; r < 8; r++) {
Deno.test(`combinationsWithReplacement1(${r}, [${iterable}])`, () => {
Expand Down
4 changes: 2 additions & 2 deletions permutations_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Deno.test("r < n", () => {
assertEquals(actual, expected);
});

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
for (let r = 0; r < 8; r++) {
Deno.test(`perm(${r}, ${n})`, () => {
Expand All @@ -130,7 +130,7 @@ for (let n = 0; n <= 8; n++) {
}
}

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
for (let r = 0; r < 8; r++) {
Deno.test(`permutations1(${r}, [${iterable}])`, () => {
Expand Down
17 changes: 7 additions & 10 deletions power_set_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Deno.test("n = 3", () => {
assertEquals(actual, expected);
});

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
Deno.test(`pwr(${n})`, () => {
const actual = [...powerSet(iterable)];
Expand All @@ -47,7 +47,7 @@ for (let n = 0; n <= 8; n++) {
});
}

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
Deno.test(`powerSet1([${iterable}])`, () => {
const actual = [...powerSet(iterable)];
Expand All @@ -56,7 +56,7 @@ for (let n = 0; n <= 8; n++) {
});
}

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
Deno.test(`powerSet2([${iterable}])`, () => {
const actual = [...powerSet(iterable)];
Expand All @@ -65,7 +65,7 @@ for (let n = 0; n <= 8; n++) {
});
}

for (let n = 0; n <= 8; n++) {
for (let n = 0; n < 8; n++) {
const iterable = range(n);
Deno.test(`powerSet3([${iterable}])`, () => {
const actual = [...powerSet(iterable)];
Expand All @@ -87,8 +87,7 @@ function pwr(n: number): number {
function* powerSet1<T>(iterable: Iterable<T>): Generator<T[]> {
const pool = [...iterable];
const n = pool.length;
yield [];
for (let r = 1; r <= n; r++) {
for (let r = 0; r <= n; r++) {
yield* combinations(r, pool);
}
}
Expand All @@ -97,8 +96,7 @@ function* powerSet1<T>(iterable: Iterable<T>): Generator<T[]> {
function* powerSet2<T>(iterable: Iterable<T>): Generator<T[]> {
const pool = [...iterable];
const n = pool.length;
yield [];
for (let r = 1; r <= n; r++) {
for (let r = 0; r <= n; r++) {
yield* combinations1(r, pool);
}
}
Expand All @@ -107,8 +105,7 @@ function* powerSet2<T>(iterable: Iterable<T>): Generator<T[]> {
function* powerSet3<T>(iterable: Iterable<T>): Generator<T[]> {
const pool = [...iterable];
const n = pool.length;
yield [];
for (let r = 1; r <= n; r++) {
for (let r = 0; r <= n; r++) {
yield* combinations2(r, pool);
}
}
24 changes: 12 additions & 12 deletions product_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,32 +163,32 @@ function test(func: typeof productLength | typeof productContent): void {
func(r);
}

for (let n0 = 0; n0 <= 4; n0++) {
for (let n0 = 0; n0 < 4; n0++) {
for (let r = 0; r < 4; r++) {
func(r, n0);
}
}

for (let n0 = 0; n0 <= 4; n0++) {
for (let n1 = 0; n1 <= 4; n1++) {
for (let n0 = 0; n0 < 4; n0++) {
for (let n1 = 0; n1 < 4; n1++) {
for (let r = 0; r < 2; r++) {
func(r, n0, n1);
}
}
}

for (let n0 = 0; n0 <= 4; n0++) {
for (let n1 = 0; n1 <= 4; n1++) {
for (let n2 = 0; n2 <= 4; n2++) {
for (let n0 = 0; n0 < 4; n0++) {
for (let n1 = 0; n1 < 4; n1++) {
for (let n2 = 0; n2 < 4; n2++) {
func(1, n0, n1, n2);
}
}
}

for (let n0 = 0; n0 <= 4; n0++) {
for (let n1 = 0; n1 <= 4; n1++) {
for (let n2 = 0; n2 <= 4; n2++) {
for (let n3 = 0; n3 <= 4; n3++) {
for (let n0 = 0; n0 < 4; n0++) {
for (let n1 = 0; n1 < 4; n1++) {
for (let n2 = 0; n2 < 4; n2++) {
for (let n3 = 0; n3 < 4; n3++) {
func(1, n0, n1, n2, n3);
}
}
Expand All @@ -199,7 +199,7 @@ function test(func: typeof productLength | typeof productContent): void {
/** Tests `product` for length against `prod`. */
function productLength(r: number, ...ns: number[]) {
const iterables = getIterables(...ns);
Deno.test(`prod(${r}, ${ns.join(", ")})`, () => {
Deno.test(`prod(${r}${ns.length ? ", " : ""}${ns.join(", ")})`, () => {
const actual = [...product(r, ...iterables)];
const expectedLength = prod(r, ...ns);
assertStrictEquals(actual.length, expectedLength);
Expand All @@ -210,7 +210,7 @@ function productLength(r: number, ...ns: number[]) {
function productContent(r: number, ...ns: number[]) {
const iterables = getIterables(...ns);
const restArgs = JSON.stringify(iterables).slice(1, -1);
Deno.test(`product1(${r}, ${restArgs})`, () => {
Deno.test(`product1(${r}${ns.length ? ", " : ""}${restArgs})`, () => {
const actual = [...product(r, ...iterables)];
const expected1 = [...product1(r, ...iterables)];
assertEquals(actual, expected1);
Expand Down

0 comments on commit 7d371e8

Please sign in to comment.