Skip to content

Commit

Permalink
#6 testing calculateOccurrence
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewNobes committed Jun 14, 2022
1 parent a5d5b04 commit 4e32897
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const calculateAttackEfficiency = (protectionWeakness) => {
* @param {boolean} Q6 The answer to Q6.
* @returns {string} The threat occurrence
*/
const calculateOccurrence = (attackEfficiency, Q5, Q6) => {
export const calculateOccurrence = (attackEfficiency, Q5, Q6) => {
if (Q5 === true && Q6 === true) {
if (attackEfficiency === "Low") {
return "Medium";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
calculateThreatScope,
calculateProtectionWeakness,
calculateAttackEfficiency,
calculateOccurrence,
} from "./calculateLikelihood";

describe("testing the calculateThreatScope function", () => {
Expand Down Expand Up @@ -175,3 +176,125 @@ describe("testing the calculateAttackEfficiency function", () => {
expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue);
});
});

describe("testing the calculateOccurrence function", () => {
it("should return Medium if the attackEfficiency is Low, and Q5 & Q6 are both true", () => {
const expectValue = "Medium";
const attackEfficiency = "Low";
const Q5Value = true;
const Q6Value = true;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return Low if the attackEfficiency is Low, and Q5 & Q6 are both false", () => {
const expectValue = "Low";
const attackEfficiency = "Low";
const Q5Value = false;
const Q6Value = false;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return Low if the attackEfficiency is Low, and Q5 is true & Q6 is false", () => {
const expectValue = "Low";
const attackEfficiency = "Low";
const Q5Value = true;
const Q6Value = false;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return Low if the attackEfficiency is Low, and Q5 is false & Q6 is true", () => {
const expectValue = "Low";
const attackEfficiency = "Low";
const Q5Value = false;
const Q6Value = true;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return High if the attackEfficiency is Medium, and Q5 & Q6 are both true", () => {
const expectValue = "High";
const attackEfficiency = "Medium";
const Q5Value = true;
const Q6Value = true;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return Low if the attackEfficiency is Medium, and Q5 & Q6 are both false", () => {
const expectValue = "Low";
const attackEfficiency = "Medium";
const Q5Value = false;
const Q6Value = false;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return Medium if the attackEfficiency is Medium, and Q5 is true & Q6 is false", () => {
const expectValue = "Medium";
const attackEfficiency = "Medium";
const Q5Value = true;
const Q6Value = false;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return Medium if the attackEfficiency is Medium, and Q5 is false & Q6 is true", () => {
const expectValue = "Medium";
const attackEfficiency = "Medium";
const Q5Value = false;
const Q6Value = true;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return High if the attackEfficiency is High, and Q5 & Q6 are both true", () => {
const expectValue = "High";
const attackEfficiency = "High";
const Q5Value = true;
const Q6Value = true;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return Medium if the attackEfficiency is High, and Q5 & Q6 are both false", () => {
const expectValue = "Medium";
const attackEfficiency = "High";
const Q5Value = false;
const Q6Value = false;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return High if the attackEfficiency is High, and Q5 is true & Q6 is false", () => {
const expectValue = "High";
const attackEfficiency = "High";
const Q5Value = true;
const Q6Value = false;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});

it("should return High if the attackEfficiency is High, and Q5 is false & Q6 is true", () => {
const expectValue = "High";
const attackEfficiency = "High";
const Q5Value = false;
const Q6Value = true;
expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe(
expectValue
);
});
});

0 comments on commit 4e32897

Please sign in to comment.