Skip to content

Commit

Permalink
Add jasmine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darkodraskovic committed May 7, 2022
1 parent c4eaae7 commit 55e3673
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"start": "nodemon src/index.js",
"start-babel": "nodemon --exec babel-node src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jasmine"
},
"keywords": [],
"author": "",
Expand All @@ -16,6 +16,7 @@
"@babel/core": "^7.17.4",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.12.11",
"jasmine": "^4.1.0",
"nodemon": "^2.0.15"
}
}
}
16 changes: 16 additions & 0 deletions spec/recursion.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { findFactorialRecursive, findFactorialIterative } from '../src/algorithms/recursion.js'

describe("Recursion function which", function () {
var resultRecursive;
var resultIterative;

it("calculates factorial recursively", function () {
resultRecursive = findFactorialRecursive(5);
expect(resultRecursive).toBe(120);
});
it("calculates factorial iteratively", function () {
resultIterative = findFactorialIterative(5);
expect(resultIterative).toBe(120);
});
});

13 changes: 13 additions & 0 deletions spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true
}
}
22 changes: 20 additions & 2 deletions src/algorithms/recursion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ function inception(counter) {
return inception(--counter);
}

export function findFactorialRecursive(number) {
if (number < 2) {
return 1;
}
return number * findFactorialRecursive(--number);
}

export function findFactorialIterative(number) {
var result = 1;
while (number > 1) {
result *= number--;
}
return result;
}

export function test() {
console.log(inception(3));
}
const resultRecursive = findFactorialRecursive(5);
const resultIterative = findFactorialIterative(5);

return;
}

0 comments on commit 55e3673

Please sign in to comment.