Skip to content

Commit

Permalink
Add regression test for efficiency with string FOM
Browse files Browse the repository at this point in the history
Signed-off-by: John Pennycook <[email protected]>
  • Loading branch information
Pennycook committed Sep 13, 2024
1 parent 711c57f commit 59b3d0a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/metrics/test_efficiency.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ def test_efficiency(self):
with self.assertRaises(TypeError):
application_efficiency(df, foms="higher")

def test_non_numeric(self):
"""Check that non-numeric data is correctly cast to numeric."""
# This is the same correctness test as above, but values are strings.
data = {
"problem": ["test"] * 10,
"platform": ["A", "B", "C", "D", "E"] * 2,
"application": ["latest"] * 5 + ["best"] * 5,
"fom": ["4", "8", "4", 0, "20"] + ["4", "10", "8", "20", "100"],
}
df = pd.DataFrame(data)

result = application_efficiency(df, foms="higher")

eff_data = {
"app eff": [1.0, 0.8, 0.5, 0.0, 0.2] + [1.0, 1.0, 1.0, 1.0, 1.0],
}
expected_data = data.copy()
expected_data.update(eff_data)
expected_df = pd.DataFrame(expected_data)

pd.testing.assert_frame_equal(result, expected_df)


if __name__ == "__main__":
unittest.main()

0 comments on commit 59b3d0a

Please sign in to comment.