-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e32897
commit 683c8c7
Showing
7 changed files
with
238 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...trix/BinaryRiskMatrixLogic/calculateImpact/calculateHarmCapacity/calculateHarmCapacity.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
}; |
31 changes: 31 additions & 0 deletions
31
...BinaryRiskMatrixLogic/calculateImpact/calculateHarmCapacity/calculateHarmCapacity.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
64 changes: 2 additions & 62 deletions
64
src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateImpact/calculateImpact.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
160 changes: 12 additions & 148 deletions
160
src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateImpact/calculateImpact.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...inaryRiskMatrixLogic/calculateImpact/calculateImpactValuation/calculateImpactValuation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
}; |
Oops, something went wrong.