Refactor `TestEnergyCost` test helper class
- Dominant language
- Python
- Stars
- 123
- Forks
- 56
- Avg merge
- 17d 18h
- Merged PRs (30d)
- 3
Description
Currently we see a test helper class `TestEnergyCost` duplicated across multiple test files:
+ "smart_control/reward/base_setpoint_energy_carbon_reward_test.py"
+ "smart_control/reward/setpoint_energy_carbon_regret_test.py"
+ "smart_control/reward/setpoint_energy_carbon_reward_test.py"
```py
class TestEnergyCost(BaseEnergyCost):
def __init__(self, usd_per_kwh: float, kg_per_kwh: float):
# Energy price in USD/Watt second (fixed schedule)
# To convert denominator units hours to seconds, divide by 3600.0, and to
# convert kW to W, divide by 1000. This leaves us with an enegy price
# in USD /W /s and carbon rate of kg /W /s.
self._energy_price = usd_per_kwh / 3600.0 / 1000.0
self._carbon_rate = kg_per_kwh / 3600.0 / 1000.0
def cost(
self, start_time: pd.Timestamp, end_time: pd.Timestamp, energy_rate: float
) -> float:
dt = (end_time - start_time).total_seconds()
return self._energy_price * energy_rate * dt
def carbon(
self, start_time: pd.Timestamp, end_time: pd.Timestamp, energy_rate: float
) -> float:
dt = (end_time - start_time).total_seconds()
return self._carbon_rate * energy_rate * dt
```
We should refactor this class definition into a common location, and import it into the tests that need it.
UPDATE: this seems this class might not actually be used in the "smart_control/reward/base_setpoint_energy_carbon_reward_test.py" file, in which case it can be removed from that file.
Contributor guide
Assessment
This issue has not been assessed yet.