Skip to content

Commit

Permalink
#7 revamping impact system
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewNobes committed Jun 14, 2022
1 parent 4e32897 commit 683c8c7
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ import calculateImpact from "../BinaryRiskMatrixLogic/calculateImpact";
import calculateLikelihood from "../BinaryRiskMatrixLogic/calculateLikelihood";
import calculateRisk from "../BinaryRiskMatrixLogic/calculateRisk";

import { calculateHarmCapacity } from "../BinaryRiskMatrixLogic/calculateImpact/calculateHarmCapacity/calculateHarmCapacity";
import { calculateImpactValuation } from "../BinaryRiskMatrixLogic/calculateImpact/calculateImpactValuation/calculateImpactValuation";

const calculateValues = (userResponses) => {
const values = {};

values.harmCapacity = calculateHarmCapacity(
userResponses[6],
userResponses[7]
);
values.impactValuation = calculateImpactValuation(
values.harmCapacity,
userResponses[8],
userResponses[9]
);
values.threatImpact = calculateImpact(values.impactValuation);

return values;
};

export const BinaryRiskMatrixForm = () => {
const [Q1, appendQ1] = useState(false);
const [Q2, appendQ2] = useState(false);
Expand Down Expand Up @@ -40,16 +60,18 @@ export const BinaryRiskMatrixForm = () => {
const likelihoodResults = calculateLikelihood(values);
const impactResults = calculateImpact(values);

appendHarmCapacity(impactResults[0]);
appendImpactValuation(impactResults[1]);
const calculatedValues = calculateValues(values);

appendHarmCapacity(calculatedValues.harmCapacity);
appendImpactValuation(calculatedValues.impactValuation);

appendThreatScore(likelihoodResults[0]);
appendProtectionWeakness(likelihoodResults[1]);
appendAttackEfficiency(likelihoodResults[2]);
appendOccurrence(likelihoodResults[3]);

appendLikelihood(likelihoodResults[4]);
appendImpact(impactResults[2]);
appendImpact(calculatedValues.threatImpact);

const risk = calculateRisk(likelihoodResults[4], impactResults[2]);
appendRisk(risk);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
*
* @param {boolean} Q7 The value of question 7, as set by the user.
* @param {boolean} Q8 The value of question 8, as set by the user.
* @returns {string} Harm Capacity
*/
export const calculateHarmCapacity = (Q7, Q8) => {
if (Q7 === true && Q8 === true) {
return "High";
} else {
if (Q7 === true || Q8 === true) {
return "Medium";
} else {
return "Low";
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { calculateHarmCapacity } from "./calculateHarmCapacity";

describe("testing the calculateHarmCapacity function", () => {
it("should return High if Q7 & Q8 are both true", () => {
const expectValue = "High";
const Q7Value = true;
const Q8Value = true;
expect(calculateHarmCapacity(Q7Value, Q8Value)).toBe(expectValue);
});

it("should return Low if Q7 & Q8 are both false", () => {
const expectValue = "Low";
const Q7Value = false;
const Q8Value = false;
expect(calculateHarmCapacity(Q7Value, Q8Value)).toBe(expectValue);
});

it("should return Medium if Q7 is false and Q8 is true", () => {
const expectValue = "Medium";
const Q7Value = false;
const Q8Value = true;
expect(calculateHarmCapacity(Q7Value, Q8Value)).toBe(expectValue);
});

it("should return Medium if Q7 is true and Q8 is false", () => {
const expectValue = "Medium";
const Q7Value = true;
const Q8Value = false;
expect(calculateHarmCapacity(Q7Value, Q8Value)).toBe(expectValue);
});
});
Original file line number Diff line number Diff line change
@@ -1,64 +1,4 @@
/**
*
* @param {string[]} values An array of the users answers for the questions on the binary risk matrix.
* @returns {string} Threat Impact
*/
export const calculateImpact = (values) => {
const harmCapacity = calculateHarmCapacity(values[6], values[7]);
const impactValuation = calculateImpactValuation(
harmCapacity,
values[8],
values[9]
);

export const calculateImpact = (impactValuation) => {
const threatImpact = impactValuation;
const impactResults = [harmCapacity, impactValuation, threatImpact];
return impactResults;
};

/**
*
* @param {boolean} Q7 The value of question 7, as set by the user.
* @param {boolean} Q8 The value of question 8, as set by the user.
* @returns {string} Harm Capacity
*/
export const calculateHarmCapacity = (Q7, Q8) => {
if (Q7 === true && Q8 === true) {
return "High";
} else {
if (Q7 === true || Q8 === true) {
return "Medium";
} else {
return "Low";
}
}
};

/**
*
* @param {string} harmCapacity
* @param {boolean} Q9 The value of question 9, as set by the user.
* @param {boolean} Q10 The value of question 10, as set by the user.
* @returns {string} Impact Validation
*/
export const calculateImpactValuation = (harmCapacity, Q9, Q10) => {
if (Q9 === false && Q10 === false) {
if (harmCapacity === "High") {
return "Medium";
} else {
return "Low";
}
} else {
if (Q9 === true && Q10 === true) {
if (harmCapacity === "Low") {
return "Medium";
} else {
return "High";
}
} else {
if (Q9 === true || Q10 === true) {
return harmCapacity;
}
}
}
return threatImpact;
};
Original file line number Diff line number Diff line change
@@ -1,157 +1,21 @@
import {
calculateImpact,
calculateImpactValuation,
calculateHarmCapacity,
} from "./calculateImpact";
import { calculateImpact } from "./calculateImpact";

describe("testing the calculateHarmCapacity function", () => {
it("should return High if Q7 & Q8 are both true", () => {
describe("testing the calculateImpact function", () => {
it("should return High if the impactValuation is High", () => {
const expectValue = "High";
const Q7Value = true;
const Q8Value = true;
expect(calculateHarmCapacity(Q7Value, Q8Value)).toBe(expectValue);
const impactValuation = "High";
expect(calculateImpact(impactValuation)).toBe(expectValue);
});

it("should return Low if Q7 & Q8 are both false", () => {
const expectValue = "Low";
const Q7Value = false;
const Q8Value = false;
expect(calculateHarmCapacity(Q7Value, Q8Value)).toBe(expectValue);
});

it("should return Medium if Q7 is false and Q8 is true", () => {
const expectValue = "Medium";
const Q7Value = false;
const Q8Value = true;
expect(calculateHarmCapacity(Q7Value, Q8Value)).toBe(expectValue);
});

it("should return Medium if Q7 is true and Q8 is false", () => {
it("should return Medium if the impactValuation is Medium", () => {
const expectValue = "Medium";
const Q7Value = true;
const Q8Value = false;
expect(calculateHarmCapacity(Q7Value, Q8Value)).toBe(expectValue);
});
});

describe("testing the calculateImpactValuation function", () => {
it("should return High if Q9 & Q10 are both true, and the harmCapacity is High", () => {
const expectedImpactValuation = "High";
const harmCapacity = "High";
const Q9Value = true;
const Q10Value = true;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return Medium if Q9 & Q10 are both false, and the harmCapacity is High", () => {
const expectedImpactValuation = "Medium";
const harmCapacity = "High";
const Q9Value = false;
const Q10Value = false;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return High if Q9 is false and Q10 is true, and the harmCapacity is High", () => {
const expectedImpactValuation = "High";
const harmCapacity = "High";
const Q9Value = false;
const Q10Value = true;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return High if Q9 is true and Q10 is false, and the harmCapacity is High", () => {
const expectedImpactValuation = "High";
const harmCapacity = "High";
const Q9Value = true;
const Q10Value = false;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
const impactValuation = "Medium";
expect(calculateImpact(impactValuation)).toBe(expectValue);
});

it("should return High if Q9 & Q10 are both true, and the harmCapacity is Medium", () => {
const expectedImpactValuation = "High";
const harmCapacity = "Medium";
const Q9Value = true;
const Q10Value = true;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return Low if Q9 & Q10 are both false, and the harmCapacity is Medium", () => {
const expectedImpactValuation = "Low";
const harmCapacity = "Medium";
const Q9Value = false;
const Q10Value = false;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return Medium if Q9 is false and Q10 is true, and the harmCapacity is Medium", () => {
const expectedImpactValuation = "Medium";
const harmCapacity = "Medium";
const Q9Value = false;
const Q10Value = true;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return Medium if Q9 is true and Q10 is false, and the harmCapacity is Medium", () => {
const expectedImpactValuation = "Medium";
const harmCapacity = "Medium";
const Q9Value = true;
const Q10Value = false;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return Medium if Q9 & Q10 are both true, and the harmCapacity is Low", () => {
const expectedImpactValuation = "Medium";
const harmCapacity = "Low";
const Q9Value = true;
const Q10Value = true;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return Low if Q9 & Q10 are both false, and the harmCapacity is Low", () => {
const expectedImpactValuation = "Low";
const harmCapacity = "Low";
const Q9Value = false;
const Q10Value = false;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return Low if Q9 is false and Q10 is true, and the harmCapacity is Low", () => {
const expectedImpactValuation = "Low";
const harmCapacity = "Low";
const Q9Value = false;
const Q10Value = true;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
});

it("should return Low if Q9 is true and Q10 is false, and the harmCapacity is Low", () => {
const expectedImpactValuation = "Low";
const harmCapacity = "Low";
const Q9Value = true;
const Q10Value = false;
expect(calculateImpactValuation(harmCapacity, Q9Value, Q10Value)).toBe(
expectedImpactValuation
);
it("should return Low if the impactValuation is Low", () => {
const expectValue = "Low";
const impactValuation = "Low";
expect(calculateImpact(impactValuation)).toBe(expectValue);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
*
* @param {string} harmCapacity
* @param {boolean} Q9 The value of question 9, as set by the user.
* @param {boolean} Q10 The value of question 10, as set by the user.
* @returns {string} Impact Validation
*/
export const calculateImpactValuation = (harmCapacity, Q9, Q10) => {
if (Q9 === false && Q10 === false) {
if (harmCapacity === "High") {
return "Medium";
} else {
return "Low";
}
} else {
if (Q9 === true && Q10 === true) {
if (harmCapacity === "Low") {
return "Medium";
} else {
return "High";
}
} else {
if (Q9 === true || Q10 === true) {
return harmCapacity;
}
}
}
};
Loading

0 comments on commit 683c8c7

Please sign in to comment.