refactor: abstract functions to reuse independent of number of rats
This commit is contained in:
parent
3ab46cbb72
commit
16d7c8f3dc
33
src/index.js
33
src/index.js
@ -151,23 +151,17 @@ class Validator {
|
||||
return MINIMUM_AREA_THREE_RATS + (numOfRats - 3) * AREA_PER_ADDITIONAL_RAT;
|
||||
}
|
||||
|
||||
cageCheck(dimensions, numRats, numFullFloors) {
|
||||
failCageNumberIndependent(dimensions, numFullFloors) {
|
||||
/*
|
||||
Function that checks a cage independent of the number of rats.
|
||||
*/
|
||||
let failedCriteria = {};
|
||||
|
||||
if (numRats < 2 || numRats > 15) {
|
||||
failedCriteria[FAILED_NUM_RATS] = this.FAIL_CRITERIA[FAILED_NUM_RATS];
|
||||
}
|
||||
|
||||
const baseArea = dimensions.depth * dimensions.width;
|
||||
if (baseArea < MINIMUM_BASE_AREA) {
|
||||
failedCriteria[FAILED_BASE_AREA] = this.FAIL_CRITERIA[FAILED_BASE_AREA];
|
||||
}
|
||||
|
||||
const areaNeeded = this.overallAreaNeeded(numRats);
|
||||
if (baseArea * numFullFloors < areaNeeded) {
|
||||
failedCriteria[FAILED_OVERALL_AREA] = this.FAIL_CRITERIA[FAILED_OVERALL_AREA];
|
||||
}
|
||||
|
||||
if (dimensions.height / numFullFloors > MAXIMUM_FALL_HEIGHT) {
|
||||
failedCriteria[FAILED_FALL_HEIGHT] = this.FAIL_CRITERIA[FAILED_FALL_HEIGHT];
|
||||
}
|
||||
@ -187,6 +181,25 @@ class Validator {
|
||||
return failedCriteria;
|
||||
}
|
||||
|
||||
cageCheck(dimensions, numRats, numFullFloors) {
|
||||
/*
|
||||
Function that checks a cage based on overall criteria and the number of rats.
|
||||
*/
|
||||
let failedCriteria = this.failCageNumberIndependent(dimensions, numFullFloors);
|
||||
|
||||
if (numRats < 2 || numRats > 15) {
|
||||
failedCriteria[FAILED_NUM_RATS] = this.FAIL_CRITERIA[FAILED_NUM_RATS];
|
||||
}
|
||||
|
||||
const areaNeeded = this.overallAreaNeeded(numRats);
|
||||
const baseArea = dimensions.depth * dimensions.width;
|
||||
if (baseArea * numFullFloors < areaNeeded) {
|
||||
failedCriteria[FAILED_OVERALL_AREA] = this.FAIL_CRITERIA[FAILED_OVERALL_AREA];
|
||||
}
|
||||
|
||||
return failedCriteria;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user