def calculate(): """Calculates weights and sets message.""" STANDARD_BAR = 45 STANDARD_PLATES = [45, 25, 10, 5, 2.5] try: bar_weight = STANDARD_BAR plate_list = STANDARD_PLATES try: lift_weight = float(entry_weight.get()) except ValueError: message.config('Lift weight must be a number.') return if entry_bar.get() != '': try: bar_weight = float(entry_bar.get()) except ValueError: message.config('Bar weight must be a number.') return if entry_plates.get() != '': try: plate_list = calc.get_list(entry_plates.get()) except TypeError: message.config('Plates mus be comma separated numbers.') return plate_dict = calc.get_plates(lift_weight, bar_weight, plate_list) message.config(text=str(plate_dict)) except calc.LessThanBar: message.config(text='Your lift weight is less than the bar.') except calc.NotDivisible: message.config(text='Your lift weight is not divisible by your plates')
def test_getplates_less_than_bar(self): with self.assertRaises(calc.LessThanBar): calc.get_plates(25)
def test_getplates_empty(self): empty_dict = dict() self.assertEqual(empty_dict, calc.get_plates(45))
def test_getplates_custom_plates_unordered(self): self.assertEqual({ 45: 1, 1.25: 1 }, calc.get_plates(137.5, 45, [10, 25, 45, 5, 2.5, 1.25]))
def test_getplates_custom_bar_lessthanbar(self): with self.assertRaises(calc.LessThanBar): calc.get_plates(12, 25)
def test_getplates_custom_bar(self): self.assertEqual({25: 1}, calc.get_plates(75, 25))
def test_getplates_standard_weights_3(self): self.assertEqual({45: 1, 25: 1, 2.5: 1}, calc.get_plates(190))
def test_getplates_standard_weights_1(self): self.assertEqual({45: 1}, calc.get_plates(135))
def test_getplates_not_divisible(self): with self.assertRaises(calc.NotDivisible): calc.get_plates(46.25)