Skip to content

Commit

Permalink
#6 risk calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewNobes committed Jun 14, 2022
1 parent 2e61f7a commit 05a2520
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @param {string} threatImpact The threat impact.
* @returns {string} The overall risk.
*/
const calculateRisk = (threatLikelihood, threatImpact) => {
export const calculateRisk = (threatLikelihood, threatImpact) => {
if (threatImpact === threatLikelihood) {
return threatLikelihood;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,64 @@
import { calculateRisk } from "./calculateRisk";

test("takes in a likelihood of High, impact of High and returns High for its risk", () => {
const expectedRisk = "High";
const likelihood = "High";
const impact = "High";
expect(calculateRisk(likelihood, impact)).toBe("High");
expect(calculateRisk(likelihood, impact)).toBe(expectedRisk);
});

test("takes in a likelihood of Medium, impact of Medium and returns Medium for its risk", () => {
const expectedRisk = "Medium";
const likelihood = "Medium";
const impact = "Medium";
expect(calculateRisk(likelihood, impact)).toBe("Medium");
expect(calculateRisk(likelihood, impact)).toBe(expectedRisk);
});

test("takes in a likelihood of Low, impact of Low and returns Low for its risk", () => {
const expectedRisk = "Low";
const likelihood = "Low";
const impact = "Low";
expect(calculateRisk(likelihood, impact)).toBe("Low");
expect(calculateRisk(likelihood, impact)).toBe(expectedRisk);
});

test("takes in a likelihood of Low, impact of Medium and returns Medium for its risk", () => {
const expectedRisk = "Medium";
const likelihood = "Low";
const impact = "Medium";
expect(calculateRisk(likelihood, impact)).toBe("Medium");
expect(calculateRisk(likelihood, impact)).toBe(expectedRisk);
});

test("takes in a likelihood of Low, impact of High and returns Medium for its risk", () => {
const expectedRisk = "Medium";
const likelihood = "Low";
const impact = "High";
expect(calculateRisk(likelihood, impact)).toBe("Medium");
expect(calculateRisk(likelihood, impact)).toBe(expectedRisk);
});

test("takes in a likelihood of Medium, impact of Low and returns Low for its risk", () => {
const expectedRisk = "Low";
const likelihood = "Medium";
const impact = "Low";
expect(calculateRisk(likelihood, impact)).toBe("Low");
expect(calculateRisk(likelihood, impact)).toBe(expectedRisk);
});

test("takes in a likelihood of Medium, impact of High and returns High for its risk", () => {
const expectedRisk = "High";
const likelihood = "Medium";
const impact = "High";
expect(calculateRisk(likelihood, impact)).toBe("High");
expect(calculateRisk(likelihood, impact)).toBe(expectedRisk);
});

test("takes in a likelihood of High, impact of Low and returns Medium for its risk", () => {
const expectedRisk = "Medium";
const likelihood = "High";
const impact = "Low";
expect(calculateRisk(likelihood, impact)).toBe("Medium");
expect(calculateRisk(likelihood, impact)).toBe(expectedRisk);
});

test("takes in a likelihood of High, impact of Medium and returns High for its risk", () => {
const expectedRisk = "High";
const likelihood = "High";
const impact = "Medium";
expect(calculateRisk(likelihood, impact)).toBe("High");
expect(calculateRisk(likelihood, impact)).toBe(expectedRisk);
});

0 comments on commit 05a2520

Please sign in to comment.