X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Ftest-utils.js;h=8565c7504bfe0a642679eafcbb1d62cfc3dc892a;hb=9c8526b801b42a5b40bfa5cec6f6e2082ffc9da7;hp=690f4b37487cf10d369b5cc1589727b358a5f0f7;hpb=85a3f8a7b3087e7240c1d307ba6dd78c05883f83;p=poolifier.git diff --git a/tests/test-utils.js b/tests/test-utils.js index 690f4b37..8565c750 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -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 => { + 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