repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build(deps-dev): bump typedoc from 0.26.0 to 0.26.2
[poolifier.git]
/
tests
/
test-utils.cjs
diff --git
a/tests/test-utils.cjs
b/tests/test-utils.cjs
index 735d406af1a91d7bb02625bc58bebd56a1c94a6a..5006df6e876065a75c893676185404d3c4c60a11 100644
(file)
--- a/
tests/test-utils.cjs
+++ b/
tests/test-utils.cjs
@@
-58,7
+58,7
@@
const sleepTaskFunction = async (
const jsonIntegerSerialization = n => {
for (let i = 0; i < n; i++) {
const o = {
const jsonIntegerSerialization = n => {
for (let i = 0; i < n; i++) {
const o = {
- a: i
+ a: i
,
}
JSON.stringify(o)
}
}
JSON.stringify(o)
}
@@
-66,25
+66,34
@@
const jsonIntegerSerialization = n => {
}
/**
}
/**
- * Intentionally inefficient implementation.
- * @param {number} n - The number of fibonacci numbers to generate.
- * @returns {number} - The nth fibonacci number.
+ * @param n - The number of fibonacci numbers to generate.
+ * @returns - The nth fibonacci number.
*/
const fibonacci = n => {
*/
const fibonacci = n => {
- if (n <= 1) return n
- return fibonacci(n - 1) + fibonacci(n - 2)
+ let current = 1
+ let previous = 0
+ while (--n) {
+ const tmp = current
+ current += previous
+ previous = tmp
+ }
+ return current
}
/**
}
/**
- * Intentionally inefficient implementation.
- * @param {number} n - The number to calculate the factorial of.
- * @returns {number} - The factorial of n.
+ * @param n - The number to calculate the factorial of.
+ * @returns - The factorial of n.
*/
const factorial = n => {
*/
const factorial = n => {
- if (n === 0) {
+ if (n === 0
|| n === 1
) {
return 1
return 1
+ } else {
+ let factorial = 1
+ for (let i = 1; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
}
- return factorial(n - 1) * n
}
const executeTaskFunction = data => {
}
const executeTaskFunction = data => {
@@
-92,7
+101,7
@@
const executeTaskFunction = data => {
case TaskFunctions.jsonIntegerSerialization:
return jsonIntegerSerialization(data.n || 100)
case TaskFunctions.fibonacci:
case TaskFunctions.jsonIntegerSerialization:
return jsonIntegerSerialization(data.n || 100)
case TaskFunctions.fibonacci:
- return fibonacci(data.n ||
25
)
+ return fibonacci(data.n ||
100
)
case TaskFunctions.factorial:
return factorial(data.n || 100)
default:
case TaskFunctions.factorial:
return factorial(data.n || 100)
default:
@@
-108,5
+117,5
@@
module.exports = {
sleep,
sleepTaskFunction,
waitPoolEvents,
sleep,
sleepTaskFunction,
waitPoolEvents,
- waitWorkerEvents
+ waitWorkerEvents
,
}
}