def test_6_average(self): """Test if averaging works as specified.""" average_temperature = Temperature.average( [Temperature(temp) for temp in VALID_TEMPERATURES]).celsius self.assertTrue( equal_to_n_decimal_places(AVERAGE_TEMPERATURE, average_temperature, 4), f"Average temperature should be {AVERAGE_TEMPERATURE} " f"degrees celsius, but is {average_temperature} " "degrees celsius")
print('Testing the getters') print('inputted:', VALID_TEMPERATURES) try: print('result in Celsius:', [temperature.celsius for temperature in temperatures]) print('result in Kelvin:', [temperature.kelvin for temperature in temperatures]) print('result in Fahrenheit:', [temperature.fahrenheit for temperature in temperatures]) except Exception as e: print(e, 'occurred when utilizing getters') print() # Computing the average of the values print('The average of those temps is', Temperature.average(temperatures).celsius) print('This should be approx. -1.0311') print() # Creating invalid temperatures # All should raise TemperatureErrors print('Trying to initialize with bad values') for value in INVALID_TEMPERATURES: try: Temperature(value) except TemperatureError: print('Correct error raised for', value) except Exception as e: print(e, 'raised instead of TemperatureError for', value) print()