def bmiCalculator(): args = request.args.to_dict() if ("feet" not in args): return "Expected parameter 'feet'.", status.HTTP_400_BAD_REQUEST feet = args["feet"] if not args["feet"].isnumeric(): return "Parameter 'feet' must be an integer.", status.HTTP_400_BAD_REQUEST if ("inches" not in args): return "Expected parameter 'inches'.", status.HTTP_400_BAD_REQUEST inches = args["inches"] if not args["inches"].isnumeric(): return "Parameter 'inches' must be an integer.", status.HTTP_400_BAD_REQUEST if ("weight" not in args): return "Expected parameter 'weight'.", status.HTTP_400_BAD_REQUEST weight = args["weight"] if not (args["weight"].replace(".", "", 1)).isnumeric(): return "Parameter 'weight' must be a float.", status.HTTP_400_BAD_REQUEST feet = int(feet) inches = int(inches) weight = float(weight) return jsonify({'bmi': bmi.calcBmi(feet, inches, weight)})
def test_firstSecondAndThirdInputDictionaryDup(self): result = bmi.calcBmi({ "A": 1, "B": 2 }, { "A": 1, "B": 2 }, { "A": 1, "B": 2 }) self.assertEqual(result, "ERROR: Invalid Input")
def bmiCalculator(): """Calculate a body mass index given height and weight""" feet = input("Enter Height (whole feet value only): ") inches = input("Enter Inches Above Highest Foot: ") weight = input("Enter Weight (lbs): ") try: feet = int(feet) inches = int(inches) weight = float(weight) print(bmi.calcBmi(feet, inches, weight)) except ValueError: print("ERROR: Invalid Input")
def test_worksWithProperInputFloatRoundsToTenthsNormalDup(self): result = bmi.calcBmi(6, 2, 185.0) self.assertEqual(result, "23.8 Normal")
def test_firstSecondAndThirdInputTupleDup(self): result = bmi.calcBmi((1, 2, 3), (1, 2, 3), (1, 2, 3)) self.assertEqual(result, "ERROR: Invalid Input")
def test_worksWithProperInputFloatRoundsToTenthOverweight(self): result = bmi.calcBmi(6, 2, 215.0) self.assertEqual(result, "27.6 Overweight")
def test_heavierThanTwiceTheHeaviestPersonEverDup(self): result = bmi.calcBmi(5, 10, 2000) self.assertEqual(result, "ERROR: Invalid Input")
def test_worksWithProperInputFloatRoundsToTenthsUnderweight(self): result = bmi.calcBmi(5, 10, 120.0) self.assertEqual(result, "17.2 Underweight")
def test_tallerThanTwiceTheTallestPersonEver(self): result = bmi.calcBmi(18, 0, 165) self.assertEqual(result, "ERROR: Invalid Input")
def test_firstSecondAndThirdInputBooleanDup(self): result = bmi.calcBmi(False, False, False) self.assertEqual(result, "ERROR: Invalid Input")
def test_secondInputDictionary(self): result = bmi.calcBmi(5, {1: 2, 3: 4}, 165) self.assertEqual(result, "ERROR: Invalid Input")
def test_thirdAndFirstInputBooleanDup(self): result = bmi.calcBmi(False, 10, False) self.assertEqual(result, "ERROR: Invalid Input")
def test_thirdAndSecondInputBoolean(self): result = bmi.calcBmi(5, True, True) self.assertEqual(result, "ERROR: Invalid Input")
def test_thirdAndFirstInputBoolean(self): result = bmi.calcBmi(True, 10, True) self.assertEqual(result, "ERROR: Invalid Input")
def test_secondInputBooleanDup(self): result = bmi.calcBmi(5, False, 165) self.assertEqual(result, "ERROR: Invalid Input")
def test_firstInputBoolean(self): result = bmi.calcBmi(True, 10, 165) self.assertEqual(result, "ERROR: Invalid Input")
def test_worksWithProperInputFloatRoundsToTenthsObese(self): result = bmi.calcBmi(6, 2, 240.0) self.assertEqual(result, "30.8 Obese")
def test_secondInputDictionaryDup(self): result = bmi.calcBmi(5, {"A": 1, "B": 2}, 165) self.assertEqual(result, "ERROR: Invalid Input")
def test_worksWithProperInputFloatRoundsToTenthsObeseDup(self): result = bmi.calcBmi(5, 3, 180.0) self.assertEqual(result, "31.9 Obese")
def test_thirdAndFirstInputDictionary(self): result = bmi.calcBmi({1: 2, 3: 4}, 10, {1: 2, 3: 4}) self.assertEqual(result, "ERROR: Invalid Input")
def test_worksWithProperInputFloatRoundsToTenthsUnderweightDup(self): result = bmi.calcBmi(5, 2, 70.0) self.assertEqual(result, "12.8 Underweight")
def test_thirdAndFirstInputDictionaryDup(self): result = bmi.calcBmi({"A": 1, "B": 2}, 10, {"A": 1, "B": 2}) self.assertEqual(result, "ERROR: Invalid Input")
def test_tallerThanTwiceTheTallestPersonEverDup(self): result = bmi.calcBmi(20, 2, 400) self.assertEqual(result, "ERROR: Invalid Input")
def test_firstSecondAndThirdInputDictionary(self): result = bmi.calcBmi({1: 2, 3: 4}, {1: 2, 3: 4}, {1: 2, 3: 4}) self.assertEqual(result, "ERROR: Invalid Input")
def test_shorterThanHalfTheShortestPersonEverDup(self): result = bmi.calcBmi(0, 8, 290) self.assertEqual(result, "ERROR: Invalid Input")
def test_thirdAndFirstInputTupleDup(self): result = bmi.calcBmi((1, 2, 3), 10, (1, 2, 3)) self.assertEqual(result, "ERROR: Invalid Input")
def test_lighterThanHalfTheLightestPersonEver(self): result = bmi.calcBmi(5, 10, 0.03125) self.assertEqual(result, "ERROR: Invalid Input")
def test_worksWithProperInputFloatRoundsToTenthsNormal(self): result = bmi.calcBmi(5, 10, 165.0) self.assertEqual(result, "23.7 Normal")
def test_secondAndFirstInputTuple(self): result = bmi.calcBmi((1, 2), (1, 2), 165) self.assertEqual(result, "ERROR: Invalid Input")
def test_thirdAndSecondInputTuple(self): result = bmi.calcBmi(5, (1, 2), (1, 2)) self.assertEqual(result, "ERROR: Invalid Input")