Report some code cleanups from work in progress PR
[poolifier.git] / tests / test-utils.js
index 690f4b37487cf10d369b5cc1589727b358a5f0f7..4668e0720c7ea1c2eb9cca649f17bb7ade4eb826 100644 (file)
@@ -16,6 +16,46 @@ class TestUtils {
   static async sleep (ms) {
     return new Promise(resolve => setTimeout(resolve, ms))
   }
+
+  static async workerSleepFunction (data, ms) {
+    return new Promise((resolve, reject) => {
+      setTimeout(() => resolve(data), ms)
+    })
+  }
+
+  static jsonIntegerSerialization (n) {
+    for (let i = 0; i < n; i++) {
+      const o = {
+        a: i
+      }
+      JSON.stringify(o)
+    }
+  }
+
+  /**
+   * Intentionally inefficient implementation.
+   *
+   * @param {*} n
+   * @returns {number}
+   */
+  static fibonacci (n) {
+    if (n <= 1) return 1
+    return TestUtils.fibonacci(n - 1) + TestUtils.fibonacci(n - 2)
+  }
+
+  /**
+   * Intentionally inefficient implementation.
+   *
+   * @param {*} n
+   * @returns {number}
+   */
+  static factorial (n) {
+    if (n === 0) {
+      return 1
+    } else {
+      return TestUtils.factorial(n - 1) * n
+    }
+  }
 }
 
 module.exports = TestUtils