From d650fc9f04d6e53857eae3aa727de0e64945e63a Mon Sep 17 00:00:00 2001 From: hamzaelkhatri Date: Mon, 9 Oct 2023 16:34:44 +0100 Subject: [PATCH] test: add unitTest for sub exercise --- js/tests/sub_test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 js/tests/sub_test.js diff --git a/js/tests/sub_test.js b/js/tests/sub_test.js new file mode 100644 index 000000000..9bbaca965 --- /dev/null +++ b/js/tests/sub_test.js @@ -0,0 +1,14 @@ +export const tests = [] +const t = (f) => tests.push(f) + +// Sub is declared and is a function and take 2 argument +t(() => typeof Sub === 'function') +t(() => Sub.length === 2) + +// Sub works with positive numbers +t(() => Sub(5, 2) === 3) +t(() => Sub(Sub(Sub(5, 2), 2), 2) === -1) // Sub Sub Sub !! + +// sub works with negative numbers +t(() => Sub(-5, -2) === -3) +t(() => Sub(Sub(Sub(-5, -2), -2), -2) === 1) // Sub Sub Sub !! \ No newline at end of file