Skip to content

Commit

Permalink
Merge pull request #37 from NREL/245-tests-for-simdrivelabel
Browse files Browse the repository at this point in the history
245 tests for simdrivelabel
  • Loading branch information
calbaker authored Jul 31, 2023
2 parents 83e60cf + 0f08371 commit 7d95bcf
Show file tree
Hide file tree
Showing 6 changed files with 674 additions and 371 deletions.
268 changes: 267 additions & 1 deletion python/fastsim/fastsimrust.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1046,4 +1046,270 @@ def abc_to_drag_coeffs(
simdrive_optimize: Optional[bool],
_show_plots: Optional[bool],
) -> Tuple[float, float]:
...
...

class LabelFe:
veh: RustVehicle
adj_params: AdjCoef
lab_udds_mpgge: float
lab_hwy_mpgge: float
lab_comb_mpgge: float
lab_udds_kwh_per_mi: float
lab_hwy_kwh_per_mi: float
lab_comb_kwh_per_mi: float
adj_udds_mpgge: float
adj_hwy_mpgge: float
adj_comb_mpgge: float
adj_udds_kwh_per_mi: float
adj_hwy_kwh_per_mi: float
adj_comb_kwh_per_mi: float
adj_udds_ess_kwh_per_mi: float
adj_hwy_ess_kwh_per_mi: float
adj_comb_ess_kwh_per_mi: float
net_range_miles: float
uf: float
net_accel: float
res_found: str
phev_calcs: Optional[LabelFePHEV]
adj_cs_comb_mpgge: Optional[float]
adj_cd_comb_mpgge: Optional[float]
net_phev_cd_miles: Optional[float]
trace_miss_speed_mph: float


@classmethod
def from_bincode(cls, encoded: ByteString) -> Self:
...

def to_bincode(self) -> ByteString:
...

@classmethod
def from_yaml(cls, yaml_str: str) -> Self:
...

def to_yaml(self) -> str:
...

@classmethod
def from_json(cls, json_str: str) -> Self:
...

def to_json(self) -> str:
...

@classmethod
def from_file(cls, filename: str) -> Self:
...

def to_file(self, filename: str) -> Self:
...

class LabelFePHEV:
regen_soc_buffer: float
udds: PHEVCycleCalc
hwy: PHEVCycleCalc


@classmethod
def from_bincode(cls, encoded: ByteString) -> Self:
...

def to_bincode(self) -> ByteString:
...

@classmethod
def from_yaml(cls, yaml_str: str) -> Self:
...

def to_yaml(self) -> str:
...

@classmethod
def from_json(cls, json_str: str) -> Self:
...

def to_json(self) -> str:
...

@classmethod
def from_file(cls, filename: str) -> Self:
...

def to_file(self, filename: str) -> Self:
...


class PHEVCycleCalc:
cd_ess_kwh: float
cd_ess_kwh_per_mi: float
cd_fs_gal: float
cd_fs_kwh: float
cd_mpg: float
cd_cycs: float
cd_miles: float
cd_lab_mpg: float
cd_adj_mpg: float
cd_frac_in_trans: float
trans_init_soc: float
trans_ess_kwh: float
trans_ess_kwh_per_mi: float
trans_fs_gal: float
trans_fs_kwh: float
cs_ess_kwh: float
cs_ess_kwh_per_mi: float
cs_fs_gal: float
cs_fs_kwh: float
cs_mpg: float
lab_mpgge: float
lab_kwh_per_mi: float
lab_uf: float
lab_uf_gpm: List[float]
lab_iter_uf: List[float]
lab_iter_uf_kwh_per_mi: List[float]
lab_iter_kwh_per_mi: List[float]
adj_iter_mpgge: List[float]
adj_iter_kwh_per_mi: List[float]
adj_iter_cd_miles: List[float]
adj_iter_uf: List[float]
adj_iter_uf_gpm: List[float]
adj_iter_uf_kwh_per_mi: List[float]
adj_cd_miles: float
adj_cd_mpgge: float
adj_cs_mpgge: float
adj_uf: float
adj_mpgge: float
adj_kwh_per_mi: float
adj_ess_kwh_per_mi: float
delta_soc: float
total_cd_miles: float


@classmethod
def from_bincode(cls, encoded: ByteString) -> Self:
...

def to_bincode(self) -> ByteString:
...

@classmethod
def from_yaml(cls, yaml_str: str) -> Self:
...

def to_yaml(self) -> str:
...

@classmethod
def from_json(cls, json_str: str) -> Self:
...

def to_json(self) -> str:
...

@classmethod
def from_file(cls, filename: str) -> Self:
...

def to_file(self, filename: str) -> Self:
...

def make_accel_trace() -> RustCycle:
...
def get_net_accel(sd_accel: RustSimDrive, scenario_name: str) -> float:
...
class AdjCoef:
def __init__(self):
self.city_intercept: float = 0.0
self.city_slope: float = 0.0
self.hwy_intercept: float = 0.0
self.hwy_slope: float = 0.0

@classmethod
def from_bincode(cls, encoded: ByteString) -> Self:
...

def to_bincode(self) -> ByteString:
...

@classmethod
def from_yaml(cls, yaml_str: str) -> Self:
...

def to_yaml(self) -> str:
...

@classmethod
def from_json(cls, json_str: str) -> Self:
...

def to_json(self) -> str:
...

@classmethod
def from_file(cls, filename: str) -> Self:
...

def to_file(self, filename: str) -> Self:
...

class AdjCoefMap:
def __init__(self):
self.adj_coef_map: Dict[str, AdjCoef] = {}


class RustLongParams:
def __init__(self):
self.rechg_freq_miles: List[float] = []
self.uf_array: List[float] = []
self.ld_fe_adj_coef: AdjCoefMap = {}

@classmethod
def from_bincode(cls, encoded: ByteString) -> Self:
...

def to_bincode(self) -> ByteString:
...

@classmethod
def from_yaml(cls, yaml_str: str) -> Self:
...

def to_yaml(self) -> str:
...

@classmethod
def from_json(cls, json_str: str) -> Self:
...

def to_json(self) -> str:
...

@classmethod
def from_file(cls, filename: str) -> Self:
...

def to_file(self, filename: str) -> Self:
...


def get_label_fe(
veh: RustVehicle,
full_detail: Optional[bool],
verbose: Optional[bool],
) -> Tuple[LabelFe, Optional[Dict[str, RustSimDrive]]]:
...

def get_label_fe_phev(
veh: RustVehicle,
sd: Dict[str, RustSimDrive],
long_params: RustLongParams,
adj_params: AdjCoef,
sim_params: RustSimDriveParams,
props: RustPhysicalProperties,
) -> LabelFePHEV:
...

def get_label_fe_conv(veh: RustVehicle) -> LabelFe:
...


25 changes: 25 additions & 0 deletions python/fastsim/tests/test_simdrivelabel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest
import numpy as np

from fastsim import fastsimrust as fsr


class TestSimDriveLabel(unittest.TestCase):
def test_get_label_fe_conv(self):
veh = fsr.RustVehicle.mock_vehicle()
label_fe, _ = fsr.get_label_fe(veh, False, False) # Unpack the tuple
# Because the full test is already implemented in Rust, we
# don't need a comprehensive check here.
self.assertEqual(label_fe.lab_udds_mpgge, 32.47503766676829)
self.assertEqual(label_fe.lab_hwy_mpgge, 42.265348793379445)
self.assertEqual(label_fe.lab_comb_mpgge, 36.25407690819302)

def test_get_label_fe_phev(self):
# Set up the required parameters and objects needed for testing get_label_fe_phev
veh = fsr.RustVehicle.mock_vehicle()
label_fe, _ = fsr.get_label_fe(veh, False, False)
self.assertEqual(label_fe.adj_udds_mpgge, 25.246151811422468)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion python/fastsim/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from fastsim import utils

class test_utils(unittest.TestCase):
class TestUtils(unittest.TestCase):
def setUp(self):
utils.disable_logging()

Expand Down
Loading

0 comments on commit 7d95bcf

Please sign in to comment.