Skip to content

Commit

Permalink
Adding test.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Nov 29, 2023
1 parent 055a804 commit b01cd18
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/dataconverter/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ def listify_template(data_dict: Template):
listified_template[optionality][path] = [data_dict[optionality][path]]
return listified_template

@pytest.mark.parametrize("input_data, expected_output", [
('2.4E-23', 2.4e-23),
('28', 28),
('45.98', 45.98),
('test', 'test'),
(['59', '3.00005', '498E-36'], np.array([59.0, 3.00005, 4.98e-34])),
('23 34 444 5000', np.array([23., 34., 444., 5000.])),
(None, None),
])
def test_transform_to_intended_dt(input_data, expected_output):
result = helpers.transform_to_intended_dt(input_data)

# Use pytest.approx for comparing floating-point numbers
if isinstance(expected_output, np.ndarray):
np.testing.assert_allclose(result, expected_output, rtol=1e-3)
elif isinstance(expected_output, float):
assert result == pytest.approx(expected_output, rel=1e-5)
else:
assert result == expected_output


@pytest.fixture(name="nxdl_root")
def fixture_nxdl_root():
Expand Down

0 comments on commit b01cd18

Please sign in to comment.