Skip to content

Commit

Permalink
🧪 test: Allow CommonJS tests to run.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Mar 7, 2024
1 parent dde8bf9 commit 79d135d
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 26 deletions.
7 changes: 5 additions & 2 deletions test/src/Symbol.iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const order = lexicographical(increasing);
const set = (x) =>
list(map(([k]) => JSON.parse(k), group(JSON.stringify, sorted(order, x))));

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const result = sorted(order, Pairs.from(input));
const expected = set(map(list, input));
t.deepEqual(expected, result);
Expand All @@ -22,7 +22,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)})`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down
7 changes: 5 additions & 2 deletions test/src/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';

import {MemoryEfficientPairs, EfficientlyInvertiblePairs} from '#module';

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const result = Pairs.from(input);
const out = result.clear();
t.is(undefined, out);
Expand All @@ -13,7 +13,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).clear()`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down
7 changes: 5 additions & 2 deletions test/src/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';

import {MemoryEfficientPairs, EfficientlyInvertiblePairs} from '#module';

const macro = (t, Pairs, input, deleted) => {
const macro = (t, {Pairs}, input, deleted) => {
const result = Pairs.from(input);
t.is(false, result.delete(deleted));
t.is(input.length, result.size);
Expand All @@ -14,7 +14,10 @@ macro.title = (title, Pairs, input, deleted) =>
deleted,
)})`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, [], 'ab');
test(
macro,
Expand Down
7 changes: 5 additions & 2 deletions test/src/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const order = lexicographical(increasing);
const set = (x) =>
list(map(([k]) => JSON.parse(k), group(JSON.stringify, sorted(order, x))));

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const result = sorted(order, Pairs.from(input).entries());
const expected = set(map((x) => [list(x), list(x)], input));
t.deepEqual(expected, result);
Expand All @@ -22,7 +22,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).entries()`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down
7 changes: 5 additions & 2 deletions test/src/forEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const order = lexicographical(increasing);
const set = (x) =>
list(map(([k]) => JSON.parse(k), group(JSON.stringify, sorted(order, x))));

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const pairs = Pairs.from(input);
const _pairs = [];
// eslint-disable-next-line unicorn/no-array-for-each
Expand All @@ -28,7 +28,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).forEach(...)`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down
7 changes: 5 additions & 2 deletions test/src/from.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const order = lexicographical(increasing);
const set = (x) =>
list(map(([k]) => JSON.parse(k), group(JSON.stringify, sorted(order, x))));

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const result = sorted(order, Pairs.from(input).values());
const expected = set(map(list, input));
t.deepEqual(expected, result);
Expand All @@ -22,7 +22,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)})`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down
7 changes: 5 additions & 2 deletions test/src/invert.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const set = (x) =>
list(map(([k]) => JSON.parse(k), group(JSON.stringify, sorted(order, x))));
const invert = (x) => map(([A, B]) => [B, A], x);

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const pairs1 = Pairs.from(input);
const pairs2 = pairs1.invert();
const result1 = sorted(order, pairs1.values());
Expand All @@ -28,7 +28,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).invert()`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down
7 changes: 5 additions & 2 deletions test/src/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const order = lexicographical(increasing);
const set = (x) =>
list(map(([k]) => JSON.parse(k), group(JSON.stringify, sorted(order, x))));

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const result = sorted(order, Pairs.from(input).keys());
const expected = set(map(list, input));
t.deepEqual(expected, result);
Expand All @@ -22,7 +22,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).keys()`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down
7 changes: 5 additions & 2 deletions test/src/left.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {MemoryEfficientPairs, EfficientlyInvertiblePairs} from '#module';
const set = (x) => sorted(increasing, new Set(x));
const left = (x) => map(([A, _B]) => A, x);

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const pairs = Pairs.from(input);
const l = set(left(input));
t.deepEqual(l, sorted(increasing, pairs.left()));
Expand All @@ -36,7 +36,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).left()`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down
7 changes: 5 additions & 2 deletions test/src/leftOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const set = (x) => sorted(increasing, new Set(x));
const left = (x) => map(([A, _B]) => A, x);
const leftOf = (x, b) => left(filter(([_A, B]) => b === B, x));

const macro = (t, Pairs, input, ohs) => {
const macro = (t, {Pairs}, input, ohs) => {
const pairs = Pairs.from(input);
const expected = set(leftOf(input, ohs));
t.deepEqual(expected, sorted(increasing, pairs.leftOf(ohs)));
Expand All @@ -37,7 +37,10 @@ const macro = (t, Pairs, input, ohs) => {
macro.title = (title, Pairs, input, ohs) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).leftOf(${ohs})`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, [], 0);
test(
macro,
Expand Down
7 changes: 5 additions & 2 deletions test/src/right.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {MemoryEfficientPairs, EfficientlyInvertiblePairs} from '#module';
const set = (x) => sorted(increasing, new Set(x));
const right = (x) => map(([_A, B]) => B, x);

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const pairs = Pairs.from(input);
const r = set(right(input));
t.deepEqual(r, sorted(increasing, pairs.right()));
Expand All @@ -36,7 +36,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).right()`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down
7 changes: 5 additions & 2 deletions test/src/rightOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const set = (x) => sorted(increasing, new Set(x));
const right = (x) => map(([_A, B]) => B, x);
const rightOf = (x, a) => right(filter(([A, _B]) => a === A, x));

const macro = (t, Pairs, input, ohs) => {
const macro = (t, {Pairs}, input, ohs) => {
const pairs = Pairs.from(input);
const expected = set(rightOf(input, ohs));
t.deepEqual(expected, sorted(increasing, pairs.rightOf(ohs)));
Expand All @@ -37,7 +37,10 @@ const macro = (t, Pairs, input, ohs) => {
macro.title = (title, Pairs, input, ohs) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).rightOf(${ohs})`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, [], 0);
test(
macro,
Expand Down
7 changes: 5 additions & 2 deletions test/src/size.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {enumerate} from '@iterable-iterator/zip';

import {MemoryEfficientPairs, EfficientlyInvertiblePairs} from '#module';

const macro = (t, Pairs, input) => {
const macro = (t, {Pairs}, input) => {
const result = Pairs.from(input);
const expected = input.length;
t.is(expected, result.size);
Expand All @@ -20,7 +20,10 @@ const macro = (t, Pairs, input) => {
macro.title = (title, Pairs, input) =>
title || `${Pairs.name}.from(${JSON.stringify(input)}).size`;

for (const Pairs of [MemoryEfficientPairs, EfficientlyInvertiblePairs]) {
for (const Pairs of [
{name: 'MemoryEfficientPairs', Pairs: MemoryEfficientPairs},
{name: 'EfficientlyInvertiblePairs', Pairs: EfficientlyInvertiblePairs},
]) {
test(macro, Pairs, []);
test(macro, Pairs, [
[1, 1],
Expand Down

0 comments on commit 79d135d

Please sign in to comment.