Extract cartesian test into test file
authorRandall Leeds <randall@apache.org>
Mon, 12 Mar 2018 04:46:39 +0000 (21:46 -0700)
committerRandall Leeds <randall@apache.org>
Mon, 12 Mar 2018 04:46:39 +0000 (21:46 -0700)
packages/range/src/cartesian.mjs
packages/range/test/cartesian.mjs [new file with mode: 0644]
packages/range/test/index.mjs [new file with mode: 0644]
test/mocha.opts

index a0b1a1f..1022556 100644 (file)
@@ -53,39 +53,3 @@ export async function* product(...iterables) {
     yield* combinations;
   }
 }
-
-// eslint-disable-next-line no-unused-vars
-async function test() {
-  async function* gen1() {
-    yield 1;
-    yield Promise.resolve(2);
-    yield 3;
-  }
-
-  async function* gen2() {
-    yield 4;
-  }
-
-  async function* gen3() {
-    yield 5;
-    yield 6;
-  }
-
-  const cart = product(gen1(), gen2(), gen3());
-
-  // eslint-disable-next-line no-unused-vars
-  const expected = [
-    [1, 4, 5],
-    [2, 4, 5],
-    [3, 4, 5],
-    [1, 4, 6],
-    [2, 4, 6],
-    [3, 4, 6],
-  ];
-
-  const result = [];
-  for await (let value of cart) {
-    result.push(value);
-  }
-  // TODO assert that result equals expected.
-}
diff --git a/packages/range/test/cartesian.mjs b/packages/range/test/cartesian.mjs
new file mode 100644 (file)
index 0000000..aada1c0
--- /dev/null
@@ -0,0 +1,40 @@
+import { product } from '../lib/cartesian.mjs';
+
+async function* gen1() {
+  yield 1;
+  yield Promise.resolve(2);
+  yield 3;
+}
+
+async function* gen2() {
+  yield 4;
+}
+
+async function* gen3() {
+  yield 5;
+  yield 6;
+}
+
+describe('cartesian', () => {
+  describe('product', () => {
+    it('yields the cartesian product of the yielded items', async () => {
+      const cart = product(gen1(), gen2(), gen3());
+
+      const expected = [
+        [1, 4, 5],
+        [2, 4, 5],
+        [3, 4, 5],
+        [1, 4, 6],
+        [2, 4, 6],
+        [3, 4, 6],
+      ];
+
+      const result = [];
+      for await (let value of cart) {
+        result.push(value);
+      }
+
+      assert.sameDeepMembers(expected, result, 'yields the expected items');
+    });
+  });
+});
diff --git a/packages/range/test/index.mjs b/packages/range/test/index.mjs
new file mode 100644 (file)
index 0000000..e69de29
index 2f77d38..293695d 100644 (file)
@@ -3,4 +3,4 @@
 -r chai/register-assert
 --recursive
 --watch-extensions mjs
-packages/*/test
+packages/*/test/**/*.mjs