From 05dacb4e8068e3938970c4fa276dfb4d9a354f97 Mon Sep 17 00:00:00 2001 From: Shaikimram Date: Mon, 13 Jan 2025 03:48:20 +0000 Subject: [PATCH] 34331 --- common/tests/test_numpy_fast.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/common/tests/test_numpy_fast.py b/common/tests/test_numpy_fast.py index ec2f5ea099b135..308c4df16fe919 100644 --- a/common/tests/test_numpy_fast.py +++ b/common/tests/test_numpy_fast.py @@ -1,20 +1,23 @@ import numpy as np - class TestInterp: - def test_correctness_controls(self): - _A_CRUISE_MIN_BP = np.asarray([0., 5., 10., 20., 40.]) - _A_CRUISE_MIN_V = np.asarray([-1.0, -.8, -.67, -.5, -.30]) - v_ego_arr = [-1, -1e-12, 0, 4, 5, 6, 7, 10, 11, 15.2, 20, 21, 39, - 39.999999, 40, 41] + def test_correctness_controls(self): + _A_CRUISE_MIN_BP = np.asarray([0., 5., 10., 20., 40.]) + _A_CRUISE_MIN_V = np.asarray([-1.0, -.8, -.67, -.5, -.30]) + v_ego_arr = [-1, -1e-12, 0, 4, 5, 6, 7, 10, 11, 15.2, 20, 21, 39, + 39.999999, 40, 41] + + # Use np.interp directly for arrays + expected = np.interp(v_ego_arr, _A_CRUISE_MIN_BP, _A_CRUISE_MIN_V) + actual = np.interp(v_ego_arr, _A_CRUISE_MIN_BP, _A_CRUISE_MIN_V) - expected = float(np.interp(v_ego_arr, _A_CRUISE_MIN_BP, _A_CRUISE_MIN_V)) - actual = float(np.interp(v_ego_arr, _A_CRUISE_MIN_BP, _A_CRUISE_MIN_V)) + # Assert that the arrays are equal + np.testing.assert_array_equal(actual, expected) - np.testing.assert_equal(actual, expected) + # Test for individual scalar values + for v_ego in v_ego_arr: + expected = float(np.interp(v_ego, _A_CRUISE_MIN_BP, _A_CRUISE_MIN_V)) + actual = float(np.interp(v_ego, _A_CRUISE_MIN_BP, _A_CRUISE_MIN_V)) + np.testing.assert_equal(actual, expected) - for v_ego in v_ego_arr: - expected = float(np.interp(v_ego, _A_CRUISE_MIN_BP, _A_CRUISE_MIN_V)) - actual = float(np.interp(v_ego, _A_CRUISE_MIN_BP, _A_CRUISE_MIN_V)) - np.testing.assert_equal(actual, expected)