def test_temperature_change_tracks(self): """ Test that changes to a grid cell's temperature are reflected properly in both its temperature value and temperature change value. """ temp = 298 r_hum = 37.25 albedo = 0.5 cell = GridCell(temp, r_hum, albedo) self.assertEqual(cell.get_temperature_change(), 0) cell.set_temperature(temp + 1) self.assertEqual(cell.get_temperature(), temp + 1) self.assertEqual(cell.get_temperature_change(), 1) cell.set_temperature(temp - 1) self.assertEqual(cell.get_temperature(), temp - 1) self.assertEqual(cell.get_temperature_change(), -1)
def test_invalid_temperature_change(self): """ Test that an error is raised when a grid cell's temperature is changed to an invalid value after the cell is instantiated. Also ensures that the grid cell's temperature is unchanged after the attempt. """ cell = GridCell(273.15, 65, 0.6) cell.set_temperature(274.15) with self.assertRaises(ValueError): cell.set_temperature(-1) self.assertEqual(cell.get_temperature(), 274.15) self.assertEqual(cell.get_temperature_change(), 1)
def test_valid_init(self): """ Test error-free creation of a valid grid cell, and proper returns from getter methods. """ temp = 1 r_hum = 75 albedo = 1 cell = GridCell(temp, r_hum, albedo) self.assertEqual(cell.get_temperature(), temp) self.assertEqual(cell.get_relative_humidity(), r_hum) self.assertEqual(cell.get_albedo(), albedo) self.assertEqual(cell.get_temperature_change(), 0)