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 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_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.')