refactor: abstract functions to reuse independent of number of rats
This commit is contained in:
		
							
								
								
									
										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;
 | 
					        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 = {};
 | 
					        let failedCriteria = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (numRats < 2 || numRats > 15) {
 | 
					 | 
				
			||||||
            failedCriteria[FAILED_NUM_RATS] = this.FAIL_CRITERIA[FAILED_NUM_RATS];
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const baseArea = dimensions.depth * dimensions.width;
 | 
					        const baseArea = dimensions.depth * dimensions.width;
 | 
				
			||||||
        if (baseArea < MINIMUM_BASE_AREA) {
 | 
					        if (baseArea < MINIMUM_BASE_AREA) {
 | 
				
			||||||
            failedCriteria[FAILED_BASE_AREA] = this.FAIL_CRITERIA[FAILED_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) {
 | 
					        if (dimensions.height / numFullFloors > MAXIMUM_FALL_HEIGHT) {
 | 
				
			||||||
            failedCriteria[FAILED_FALL_HEIGHT] = this.FAIL_CRITERIA[FAILED_FALL_HEIGHT];
 | 
					            failedCriteria[FAILED_FALL_HEIGHT] = this.FAIL_CRITERIA[FAILED_FALL_HEIGHT];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -187,6 +181,25 @@ class Validator {
 | 
				
			|||||||
        return failedCriteria;
 | 
					        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;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user