def test_renovation(self): _1990 = FloorSpace(1990, self.square_footage, 'USA') five_year_rate = _1990.choose_renovation_rate(5) # If the rate is zero, there should be nothing the five-year bin: _1990.age_n_years(5) if five_year_rate == 0: for b_type in [1,2,3,4,5,6,9,10,11,78]: self.assertEqual(_1990.remaining_floor_space_by_year[1995][b_type], 0)
class TestRateFunctions(unittest.TestCase): def setUp(self): self.square_footage = {1:100, 2:100, 3:100, 4:100, 5:100, 6:100, 9:100, 10:100, 11:100, 78:100} self.fs = FloorSpace(1990, self.square_footage, 'CA') def test_renovation_chooser_should_return_correct_rate(self): # A 2-year old building has a 0% chance of renovation: rate = self.fs.choose_renovation_rate(2) self.assertEqual(rate, 0, "2-year-old building should have a 0% renovation rate.") # A 13-year old building has a 1% chance of renovation: rate = self.fs.choose_renovation_rate(13) self.assertEqual(rate, 0.01, "13-year-old building should have a 1% renovation rate.") # A 55-year old building has a 10% chance of renovation: rate = self.fs.choose_renovation_rate(55) self.assertEqual(rate, 0.1, "55-year-old building should have a 10% renovation rate.") def test_renovation_chooser_should_return_percentage(self): # The function should always return a rate such that 0 <= rate <= 1 for years_since_renovation in range(100): rate = self.fs.choose_renovation_rate(years_since_renovation) self.assertGreaterEqual(rate, 0, "renovation rate should be >= 0") self.assertLessEqual(rate, 1, "renovation rate should be <= 1")