From 418326bbf5a4b6c0473095b4a7c33b297b9a3510 Mon Sep 17 00:00:00 2001 From: Justin Date: Sat, 16 Nov 2024 00:15:31 -0700 Subject: [PATCH] test error cases --- tests/test_uncertainties.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_uncertainties.py b/tests/test_uncertainties.py index 0cb81807..20cbc685 100644 --- a/tests/test_uncertainties.py +++ b/tests/test_uncertainties.py @@ -1278,6 +1278,28 @@ def test_correlated_values(): assert uarrays_close(cov, numpy.array(uncert_core.covariance_matrix(variables))) + nom_values = [0, 0, 0] + covariance_mat = numpy.diag([1, 1, -1]) + with pytest.raises( + ValueError, + match="must be positive semi-definite.", + ): + x, y, z = correlated_values(nom_values, covariance_mat) + + covariance_mat = numpy.array([[1, 0, 1], [0, 1, 0], [0, 0, 1]]) + with pytest.raises( + ValueError, + match="must be symmetric.", + ): + x, y, z = correlated_values(nom_values, covariance_mat) + + covariance_mat = numpy.array([[1, 0, 0], [0, 1j, 0], [0, 0, 1]]) + with pytest.raises( + ValueError, + match="must be real.", + ): + x, y, z = correlated_values(nom_values, covariance_mat) + def test_correlated_values_correlation_mat(): """ Tests the input of correlated value. @@ -1327,6 +1349,11 @@ def test_correlated_values_correlation_mat(): numpy.array(uncert_core.covariance_matrix([x2, y2, z2])), ) + values_with_std_dev = ((0, 1), (0, 1), (0, -1)) + correlation_mat = np.diag((1, 1, 1)) + with pytest.raises(ValueError, match="must be non-negative."): + x, y, z = correlated_values_norm(values_with_std_dev, correlation_mat) + @pytest.mark.skipif( np is not None,