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_high_border_values(self): """ Test that a grid cell can be created without error using high border values for all three variables, using 100 for humidity and 1 for albedo. Temperature has no high border. """ cell = GridCell(987654321, 100, 1) self.assertEqual(cell.get_temperature(), 987654321) self.assertEqual(cell.get_relative_humidity(), 100) self.assertEqual(cell.get_albedo(), 1)
def test_low_border_values(self): """ Test that a grid cell can be created without error using low border values for all three variables, namely 0 for temperature, humidity, and albedo. """ cell = GridCell(0, 0, 0) self.assertEqual(cell.get_temperature(), 0) self.assertEqual(cell.get_relative_humidity(), 0) self.assertEqual(cell.get_albedo(), 0)
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)