diff --git a/src/index.js b/src/index.js index afca4f9..da2fd1a 100644 --- a/src/index.js +++ b/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; + } + }