Example #1
0
    def checkOption(self, menu, option):
        from main import recordActivityAction
        from caloric_balance import CaloricBalance

        self.setUp()

        cb = CaloricBalance('f', 23.0, 65.0, 130.0)
        expected = -1417.9
        actual = cb.getBalance()
        self.assertAlmostEqual(
            actual, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (actual, expected))

        self.input_response_list = [
            option, "twleve", "zero", "0", "0", "-1", "-17", "55"
        ]
        recordActivityAction(cb)

        actual2 = cb.getBalance()
        self.assertNotEqual(
            actual, actual2,
            'Your recordActivityAction with option "%s" did not update the caloric balance.'
            % option)

        printed_lines = self.printed_lines
        lines = "    ".join(printed_lines)
        expression = "caloric.*balance.*(-[0-9]+\.[0-9]+)"
        matches = re.findall(expression, lines.lower())
        self.assertTrue(
            len(matches) >= 1,
            'You did not print the updated caloric balance to the user?\n' +
            'Your printed message should contain the words "caloric", "balance", and the updated balance.\n'
            + 'You printed (we entered some bad values for minutes):\n    %s' %
            lines)
    def test004_eatFoodAction_updatesBalance(self):
        from main import eatFoodAction
        from caloric_balance import CaloricBalance

        cb = CaloricBalance('f', 23.0, 65.0, 130.0)
        expected = -1417.9
        actual = cb.getBalance()
        self.assertAlmostEqual(
            actual, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (actual, expected))

        expected_response = "998"
        self.input_response_list = [
            "0", "-1.7", "-20", "zero", "twleve", "", "\n", expected_response,
            "500", "600", "700"
        ]
        eatFoodAction(cb)

        actual2 = cb.getBalance()
        self.assertNotEqual(
            actual, actual2,
            'Your eatFoodAction did not update the caloric balance.')

        expected = actual + float(expected_response)
        actual = actual2
        self.assertAlmostEqual(
            expected, actual, 2,
            'Your result (%s) is not close enough to (%s). Did you use getUserFloat?'
            % (actual, expected))
 def test005_applyActionDetectsIllegalAction(self):
     from main import applyAction
     from caloric_balance import CaloricBalance
     cb = CaloricBalance('f', 23.0, 65.0, 130.0)
     obal = cb.getBalance()
     applyAction(cb, "x")
     self.assertEqual(obal, cb.getBalance(),
                      'applyAction should not change the caloric balance.')
     self.assertFalse(
         self.eat_food_called,
         "An illegal option was provided, eatFoodAction should not have been called."
     )
     self.assertFalse(
         self.record_activity_called,
         "An illegal option was provided, recordActivityAction should not have been called."
     )
     self.assertFalse(
         self.quit_called,
         "An illegal option was provided, quitAction should not have been called."
     )
     lines = "    ".join(self.printed_lines)
     self.assertGreaterEqual(
         len(self.printed_lines), 1,
         'You should have printed an error message to the user.\n' +
         'You printed:\n    %s' % lines)
    def test003_eatFoodAction_updatesBalance(self):
        from main import eatFoodAction
        from caloric_balance import CaloricBalance

        cb = CaloricBalance('f', 23.0, 65.0, 130.0)
        expected = -1417.9
        actual = cb.getBalance()
        self.assertAlmostEqual(actual, expected, 2,
                               'Your result (%s) is not close enough to (%s)' % (actual, expected))

        expected_response = "400"
        self.input_response_list = ["0", "-1.7", "-20", "zero", "twleve", "", "\n", expected_response]
        eatFoodAction(cb)

        actual2 = cb.getBalance()
        self.assertNotEqual(actual, actual2,
                            'Your eatFoodAction did not update the caloric balance.')

        expected = actual + float(expected_response)
        actual  = actual2
        self.assertAlmostEqual(expected, actual, 2,
                               'Your result (%s) is not close enough to (%s). Did you use getUserFloat?' % (actual, expected))

        lines = "    ".join(self.printed_lines)
        expression = "caloric.*balance.*(-[0-9]+\.[0-9]+)"
        matches = re.findall(expression, lines.lower())
        self.assertTrue(
            len(matches) >= 1,
            'You did not print the updated caloric balance to the user?\n' +
            'Your message should contain the words "caloric", "balance", and the updated balance.\n' +
            'You printed:\n    %s' % lines
        )
    def test002_f_getBalance(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('f', 23.0, 65.0, 130.0)

        balance = cb.getBalance()
        expected = -1417.9

        self.assertAlmostEqual(balance, expected, 2, 'Your result (%s) is not close enough to (%s)' % (balance, expected))
    def test003_f_getBalance(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('f', 27.0, 74.0, 155.0)

        balance = cb.getBalance()
        expected = -1550.15

        self.assertAlmostEqual(balance, expected, 2, 'Your result (%s) is not close enough to (%s)' % (balance, expected))
    def test004_m_getBalance(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('m', 26.0, 70.5, 185.0)

        balance = cb.getBalance()
        expected = -1937.1

        self.assertAlmostEqual(balance, expected, 2, 'Your result (%s) is not close enough to (%s)' % (balance, expected))
    def test005_m_getBalance(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('m', 35.0, 76.0, 275.0)

        balance = cb.getBalance()
        expected = -2506.45

        self.assertAlmostEqual(balance, expected, 2, 'Your result (%s) is not close enough to (%s)' % (balance, expected))
    def test006_x_getBalance(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('x', 26.0, 70.5, 185.0)

        balance = cb.getBalance()
        expected = 0.0

        self.assertEqual(balance, expected, 'Your result (%s) is not equal to (%s)' % (balance, expected))
    def test004_testGetBMRError(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('x', 26.0, 70.5, 185.0)

        bmr = cb.getBMR('x', 26.0, 70.5, 185.0)
        expected = 0.0

        self.assertEqual(
            bmr, expected,
            'Your result (%s) is not equal to (%s)' % (bmr, expected))
    def test002_testGetBMRFemale(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('f', 23.0, 65.0, 130.0)

        bmr = cb.getBMR('f', 23.0, 65.0, 130.0)
        expected = 1417.9

        self.assertAlmostEqual(
            bmr, expected, 2,
            'Your result (%s) is not close enough to (%s)' % (bmr, expected))
    def test003_testGetBMRMale(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('m', 26.0, 70.5, 185.0)

        bmr = cb.getBMR('m', 26.0, 70.5, 185.0)
        expected = 1937.1

        self.assertAlmostEqual(
            bmr, expected, 2,
            'Your result (%s) is not close enough to (%s)' % (bmr, expected))
Example #13
0
    def test003_getBalance(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('f', 27.0, 74.0, 155.0)

        balance = cb.getBalance()
        expected = -1550.15
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(.087, 45)
        balance = cb.getBalance()
        expected = -2156.975
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(.087, 15)
        balance = cb.getBalance()
        expected = -2359.25
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))
Example #14
0
    def test002_recordActivity(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('f', 23.0, 65.0, 130.0)

        balance = cb.getBalance()
        expected = -1417.9
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(.074, 30)
        balance = cb.getBalance()
        expected = -1706.5
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(.074, 45)
        balance = cb.getBalance()
        expected = -2139.4
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))
Example #15
0
    def test004_m_getBalance(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('m', 26.0, 70.5, 185.0)

        balance = cb.getBalance()
        expected = -1937.1

        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(.009, 85)
        balance = cb.getBalance()
        expected = -2078.625
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(.009, 32.6)
        balance = cb.getBalance()
        expected = -2132.90
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))
Example #16
0
def createCaloricBalance():
    gender = getUserString('What is your gender (f or m)? ')
    age = getUserFloat('What is your age? ')
    height = getUserFloat('What is your height in inches? ')
    weight = getUserFloat('What is your weight in pounds? ')
    caloricbalance = CaloricBalance(gender, age, height, weight)
    return caloricbalance
 def test002_twoOrMoreDataMembers(self):
     from caloric_balance import CaloricBalance
     cb = CaloricBalance('f', 23.0, 65.0, 130.0)
     datamembers = cb.__dict__
     self.assertGreaterEqual(
         len(datamembers), 2,
         'You did not save enough datamembers. You should have at least `weight` and `balance`'
     )
    def test006_illegalAction_activityActions(self):
        from main import formatActivityMenu
        from main import applyAction
        from caloric_balance import CaloricBalance
        import re

        menu = formatActivityMenu()
        options = []
        for line in menu:
            matches = re.findall("\[([a-z0-9]+)\]", line)
            if len(matches) > 0:
                options += matches

        self.assertGreaterEqual(4, len(options),
                                'Have you finished formatActivityMenu?')

        for option in options:
            if option not in ['f', 'a', 'q']:
                self.setUp()
                cb = CaloricBalance('f', 23.0, 65.0, 130.0)
                obal = cb.getBalance()
                applyAction(cb, option)
                self.assertEqual(
                    obal, cb.getBalance(),
                    'applyAction should not change the caloric balance.')
                self.assertFalse(
                    self.eat_food_called,
                    "An illegal option (%s) was provided, eatFoodAction should not have been called."
                    % option)
                self.assertFalse(
                    self.record_activity_called,
                    "An illegal option (%s) was provided, recordActivityAction should not have been called."
                    % option)
                self.assertFalse(
                    self.quit_called,
                    "An illegal option (%s) was provided, quitAction should not have been called."
                    % option)
                lines = "".join(self.printed_lines)
                self.assertGreaterEqual(
                    len(self.printed_lines), 1,
                    'You should have printed an error message to the user.\n' +
                    'Your printed lines were:\n%s' % lines)
    def test003_weightIsSaved(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('f', 23.0, 65.0, 130.0)
        datamembers = cb.__dict__

        weightFlag = False
        for k in datamembers:
            if datamembers[k] == 130.0:
                weightFlag = True
        self.assertTrue(weightFlag,
                        'The value of weight was not saved in a datamember.')
    def test008_recordActivityAction_badOption(self):
        from main import recordActivityAction
        from main import formatActivityMenu
        from caloric_balance import CaloricBalance

        menu = formatActivityMenu()
        options = []
        for line in menu:
            matches = re.findall("\[([a-z0-9]+)\]", line)
            if len(matches) > 0:
                options += matches

        self.assertGreaterEqual(
            len(options), 4,
            'Unable to find at least 4 options to choose from. Check your formatActivityMenu function'
        )

        # join all the options together to get a bad option
        joinedoption = "".join(options)

        cb = CaloricBalance('f', 23.0, 65.0, 130.0)
        expected = -1417.9
        actual = cb.getBalance()
        self.assertAlmostEqual(
            actual, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (actual, expected))

        self.input_response_list = [joinedoption]
        recordActivityAction(cb)

        actual2 = cb.getBalance()
        self.assertEqual(
            actual, actual2,
            'Your recordActivityAction should not have updated the caloric balance, because the user gave a bad option'
        )

        printed_lines = self.printed_lines
        self.assertGreaterEqual(len(printed_lines),
                                len(menu) + 1,
                                'You did not print a message to the user.')
Example #21
0
 def test003_applyActionCallsRecordActivityAction(self):
     from main import applyAction
     from caloric_balance import CaloricBalance
     cb = CaloricBalance('f', 23.0, 65.0, 130.0)
     obal = cb.getBalance()
     applyAction(cb, "a")
     self.assertEqual(obal, cb.getBalance(),
                      'applyAction should not change the caloric balance.')
     self.assertFalse(
         self.eat_food_called,
         "Option 'a' was provided, eatFoodAction should not have been called."
     )
     self.assertTrue(
         self.record_activity_called,
         "Option 'a' was provided, recordActivity should have been called.")
     self.assertFalse(
         self.quit_called,
         "Option 'a' was provided, quitAction should not have been called.")
     self.assertEqual(
         len(self.printed_lines), 0,
         'Nothing should be printed in the applyAction function.')
    def test002_eatFoodAction_updatesBalance(self):
        from main import eatFoodAction
        from caloric_balance import CaloricBalance

        cb = CaloricBalance('f', 23.0, 65.0, 130.0)
        expected = -1417.9
        actual = cb.getBalance()
        self.assertAlmostEqual(
            actual, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (actual, expected))

        self.input_response_list = ["400"]
        eatFoodAction(cb)

        actual_response = self.input_response_list[self.input_response_index]
        self.assertEqual("400", actual_response)

        actual2 = cb.getBalance()
        self.assertNotEqual(
            actual, actual2,
            'Your eatFoodAction did not update the caloric balance.')
    def test006_bmrIsSaved(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('m', 26.0, 70.5, 185.0)
        datamembers = cb.__dict__

        bmrFlag = False
        for k in datamembers:
            if math.isclose(datamembers[k], -1937.1, abs_tol=0.005):
                bmrFlag = True
        self.assertTrue(
            bmrFlag,
            'The updated caloric balance was not found as a datamember. Did you remember to subtract the BMR?'
        )
    def test007_bmrIsSaved(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('x', 26.0, 70.5, 185.0)
        datamembers = cb.__dict__

        bmrFlag = False
        for k in datamembers:
            if datamembers[k] == 0.0:
                bmrFlag = True
        self.assertTrue(
            bmrFlag,
            'The updated caloric balance was not found as a datamember. Did you remember to subtract the BMR?'
        )
    def checkOption(self, menu, option):
        from main import recordActivityAction
        from caloric_balance import CaloricBalance

        self.setUp()

        cb = CaloricBalance('f', 23.0, 65.0, 130.0)
        expected = -1417.9
        actual = cb.getBalance()
        self.assertAlmostEqual(
            actual, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (actual, expected))

        self.input_response_list = [option, "55"]
        recordActivityAction(cb)

        actual2 = cb.getBalance()
        self.assertNotEqual(
            actual, actual2,
            'Your recordActivityAction with option "%s" did not update the caloric balance.'
            % option)

        printed_lines = self.printed_lines
        self.assertGreaterEqual(len(printed_lines),
                                len(menu) + 1,
                                'You did not print a message to the user.')

        lines = "".join(printed_lines)

        expression = "caloric.*balance.*(-[0-9]+\.[0-9]+)"
        matches = re.findall(expression, lines)
        self.assertTrue(
            len(matches) >= 1,
            'You did not print the updated caloric balance to the user? Your message should contain the words "caloric", "balance", and the updated balance.'
        )
Example #26
0
    def test005_bmrIsSaved(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('f', 23.0, 65.0, 130.0)
        datamembers = cb.__dict__

        bmrFlag = False
        for k in datamembers:
            try:
                if math.isclose(datamembers[k], -1417.9, abs_tol=0.005):
                    bmrFlag = True
            except:
                #not a real number
                pass
        self.assertTrue(
            bmrFlag,
            'The updated caloric balance was not found as a datamember. Did you remember to subtract the BMR?'
        )
    def test001_fullRun(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('f', 23.0, 65.0, 130.0)

        balance = cb.getBalance()
        expected = -1417.9
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.eatFood(400)
        balance = cb.getBalance()
        expected = -1017.9
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.eatFood(906)
        balance = cb.getBalance()
        expected = -111.9
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(0.074, 30)
        balance = cb.getBalance()
        expected = -400.5
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(0.087, 15)
        balance = cb.getBalance()
        expected = -570.15
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.eatFood(450)
        balance = cb.getBalance()
        expected = -120.15
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))
    def test002_fullRun(self):
        from caloric_balance import CaloricBalance
        cb = CaloricBalance('m', 26.0, 70.5, 185.0)

        balance = cb.getBalance()
        expected = -1937.1
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.eatFood(400)
        balance = cb.getBalance()
        expected = -1537.1
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.eatFood(906)
        balance = cb.getBalance()
        expected = -631.1
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(0.074, 30)
        balance = cb.getBalance()
        expected = -1041.8
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.recordActivity(0.087, 15)
        balance = cb.getBalance()
        expected = -1283.23
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))

        cb.eatFood(450)
        balance = cb.getBalance()
        expected = -833.23
        self.assertAlmostEqual(
            balance, expected, 2,
            'Your result (%s) is not close enough to (%s)' %
            (balance, expected))