diff --git a/tests/root/test_EulerAngles.py b/tests/root/test_EulerAngles.py index 4b59357a..3a7d917c 100644 --- a/tests/root/test_EulerAngles.py +++ b/tests/root/test_EulerAngles.py @@ -4,9 +4,11 @@ # or https://github.com/scikit-hep/vector for details. import pytest -from hypothesis import given, strategies as st -import vector +# from hypothesis import given +# from hypothesis import strategies as st + +# import vector # If ROOT is not available, skip these tests. ROOT = pytest.importorskip("ROOT") @@ -14,7 +16,7 @@ # 4D constructor arguments to get all the weird cases. constructor = [ (0, 0, 0, 0), - (0, 0, 1, 0), # theta == 0.0 + (0, 0, 1, 0), # theta == 0.0 (0, 0, -1, 0), (0, 0, 1, 0), (0, 0, 0, 4294967296), @@ -24,7 +26,7 @@ (1, 2, 3, 0), (1, 2, 3, 10), (1, 2, 3, -10), - (1., 2., 3., 2.5), + (1.0, 2.0, 3.0, 2.5), (1, 2, 3, 2.5), (1, 2, 3, -2.5), ] @@ -32,7 +34,7 @@ # Coordinate conversion methods to apply to the VectorObject4D. coordinate_list = [ "to_xyzt", - "to_xythetat", # may fail for constructor2 + "to_xythetat", # may fail for constructor2 "to_xyetat", "to_rhophizt", "to_rhophithetat", @@ -45,10 +47,12 @@ "to_rhophietatau", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -62,10 +66,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -74,6 +80,7 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param diff --git a/tests/root/test_Polar2DVector.py b/tests/root/test_Polar2DVector.py index 91e4eee8..52912dd4 100644 --- a/tests/root/test_Polar2DVector.py +++ b/tests/root/test_Polar2DVector.py @@ -3,10 +3,10 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. -import pytest -from hypothesis import given, strategies as st - import numpy as np +import pytest +from hypothesis import given +from hypothesis import strategies as st import vector @@ -21,8 +21,8 @@ (1, 0), (10, 0), (1, 10), - (10., 10), - (1., 2.5), + (10.0, 10), + (1.0, 2.5), (1, 2.5), (1, 6.283185307179586), ] @@ -33,27 +33,31 @@ "to_rhophi", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, - 0.25*np.pi, - -0.25*np.pi, - 0.5*np.pi, - -0.5*np.pi, + 0.25 * np.pi, + -0.25 * np.pi, + 0.5 * np.pi, + -0.5 * np.pi, np.pi, -np.pi, - 2*np.pi, - -2*np.pi, + 2 * np.pi, + -2 * np.pi, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -62,38 +66,58 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Dot(constructor, coordinates): - assert ROOT.Math.Polar2DVector(*constructor).Dot(ROOT.Math.Polar2DVector(*constructor)) == pytest.approx( + assert ROOT.Math.Polar2DVector(*constructor).Dot( + ROOT.Math.Polar2DVector(*constructor) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )()) + )().dot( + getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() + ) ) # Run the same tests within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fuzz_Dot(constructor1, constructor2, coordinates): - assert ROOT.Math.Polar2DVector(*constructor1).Dot(ROOT.Math.Polar2DVector(*constructor2)) == pytest.approx( + assert ROOT.Math.Polar2DVector(*constructor1).Dot( + ROOT.Math.Polar2DVector(*constructor2) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["rho", "phi"], constructor1))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor2))), coordinates - )()), rel=1e-6, abs=1e-6 + )().dot( + getattr( + vector.obj(**dict(zip(["rho", "phi"], constructor2))), coordinates + )() + ), + rel=1e-6, + abs=1e-6, ) @@ -108,10 +132,16 @@ def test_Mag2(constructor, coordinates): # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_Mag2(constructor, coordinates): assert ROOT.Math.Polar2DVector(*constructor).Mag2() == pytest.approx( getattr( @@ -123,23 +153,29 @@ def test_fuzz_Mag2(constructor, coordinates): # Run a test that compares ROOT's 'R()' with vector's 'rho' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Mag(constructor, coordinates): - assert ROOT.Math.sqrt(ROOT.Math.Polar2DVector(*constructor).Mag2()) == pytest.approx( - getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )().rho + assert ROOT.Math.sqrt( + ROOT.Math.Polar2DVector(*constructor).Mag2() + ) == pytest.approx( + getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)().rho ) # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_Mag(constructor, coordinates): - assert ROOT.Math.sqrt(ROOT.Math.Polar2DVector(*constructor).Mag2()) == pytest.approx( - getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )().rho + assert ROOT.Math.sqrt( + ROOT.Math.Polar2DVector(*constructor).Mag2() + ) == pytest.approx( + getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)().rho ) @@ -147,23 +183,27 @@ def test_fuzz_Mag(constructor, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_Phi(constructor, coordinates): assert ROOT.Math.Polar2DVector(*constructor).Phi() == pytest.approx( - getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )().phi + getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)().phi ) + # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_Phi(constructor, coordinates): assert ROOT.Math.Polar2DVector(*constructor).Phi() == pytest.approx( - getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )().phi + getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)().phi ) + # Run a test that compares ROOT's 'Rotate()' with vector's 'rotateZ' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Rotate(constructor, angle, coordinates): @@ -173,146 +213,182 @@ def test_Rotate(constructor, angle, coordinates): vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates )().rotateZ(angle) res_vec = vec.rotateZ(angle) - assert (ref_vec.R() == pytest.approx(res_vec.rho) and - ref_vec.Phi() == pytest.approx(res_vec.phi)) + assert ref_vec.R() == pytest.approx(res_vec.rho) and ref_vec.Phi() == pytest.approx( + res_vec.phi + ) # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - angle=st.floats(min_value=-10e7, max_value=10e7) - | st.integers(min_value=-10e7, max_value=10e7)) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + angle=st.floats(min_value=-10e7, max_value=10e7) + | st.integers(min_value=-10e7, max_value=10e7), +) def test_fuzz_Rotate(constructor, angle, coordinates): ref_vec = ROOT.Math.Polar2DVector(*constructor) ref_vec.Rotate(angle) - vec = getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )() + vec = getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() res_vec = vec.rotateZ(angle) - assert (ref_vec.R() == pytest.approx(res_vec.rho) and - ref_vec.Phi() == pytest.approx(res_vec.phi)) + assert ref_vec.R() == pytest.approx(res_vec.rho) and ref_vec.Phi() == pytest.approx( + res_vec.phi + ) # Run a test that compares ROOT's 'Unit()' with vector's 'unit' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Unit(constructor, coordinates): ref_vec = ROOT.Math.Polar2DVector(*constructor).Unit() - vec = getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )() + vec = getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() res_vec = vec.unit - assert (ref_vec.R() == pytest.approx(res_vec().rho) and - ref_vec.Phi() == pytest.approx(res_vec().phi)) + assert ref_vec.R() == pytest.approx( + res_vec().rho + ) and ref_vec.Phi() == pytest.approx(res_vec().phi) # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_Unit(constructor, coordinates): ref_vec = ROOT.Math.Polar2DVector(*constructor).Unit() - vec = getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )() + vec = getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() res_vec = vec.unit - assert (ref_vec.R() == pytest.approx(res_vec().rho) and - ref_vec.Phi() == pytest.approx(res_vec().phi)) + assert ref_vec.R() == pytest.approx( + res_vec().rho + ) and ref_vec.Phi() == pytest.approx(res_vec().phi) # Run a test that compares ROOT's 'X()' and 'Y()' with vector's 'x' and 'y' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_X_and_Y(constructor, coordinates): ref_vec = ROOT.Math.Polar2DVector(*constructor) - vec = getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )() - assert (ref_vec.X() == pytest.approx(vec.x) and - ref_vec.Y() == pytest.approx(vec.y)) + vec = getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() + assert ref_vec.X() == pytest.approx(vec.x) and ref_vec.Y() == pytest.approx(vec.y) # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) -def test_X_and_Y(constructor, coordinates): +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) +def test_fuzz_X_and_Y(constructor, coordinates): ref_vec = ROOT.Math.Polar2DVector(*constructor) - vec = getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )() - assert (ref_vec.X() == pytest.approx(vec.x) and - ref_vec.Y() == pytest.approx(vec.y)) + vec = getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() + assert ref_vec.X() == pytest.approx(vec.x) and ref_vec.Y() == pytest.approx(vec.y) # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): - ref_vec = ROOT.Math.Polar2DVector(*constructor).__add__(ROOT.Math.Polar2DVector(*constructor)) + ref_vec = ROOT.Math.Polar2DVector(*constructor).__add__( + ROOT.Math.Polar2DVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)()) - assert (ref_vec.R() == pytest.approx(vec.rho) and - ref_vec.Phi() == pytest.approx(vec.phi)) + )().add( + getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() + ) + assert ref_vec.R() == pytest.approx(vec.rho) and ref_vec.Phi() == pytest.approx( + vec.phi + ) # Run the same tests within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fuzz_add(constructor1, constructor2, coordinates): - ref_vec = ROOT.Math.Polar2DVector(*constructor1).__add__(ROOT.Math.Polar2DVector(*constructor2)) + ref_vec = ROOT.Math.Polar2DVector(*constructor1).__add__( + ROOT.Math.Polar2DVector(*constructor2) + ) vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor1))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor2))), coordinates)()) - assert (ref_vec.R() == pytest.approx(vec.rho) and - ref_vec.Phi() == pytest.approx(vec.phi)) + )().add( + getattr(vector.obj(**dict(zip(["rho", "phi"], constructor2))), coordinates)() + ) + assert ref_vec.R() == pytest.approx(vec.rho) and ref_vec.Phi() == pytest.approx( + vec.phi + ) # Run a test that compares ROOT's '__sub__' with vector's 'subtract' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): - ref_vec = ROOT.Math.Polar2DVector(*constructor).__sub__(ROOT.Math.Polar2DVector(*constructor)) - vec1 = getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )() - vec2 = getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )() + ref_vec = ROOT.Math.Polar2DVector(*constructor).__sub__( + ROOT.Math.Polar2DVector(*constructor) + ) + vec1 = getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() + vec2 = getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() res_vec = vec1.subtract(vec2) - assert (ref_vec.R() == pytest.approx(res_vec.rho) and - ref_vec.Phi() == pytest.approx(res_vec.phi)) + assert ref_vec.R() == pytest.approx(res_vec.rho) and ref_vec.Phi() == pytest.approx( + res_vec.phi + ) # Run the same tests within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fuzz_sub(constructor1, constructor2, coordinates): - ref_vec = ROOT.Math.Polar2DVector(*constructor1).__sub__(ROOT.Math.Polar2DVector(*constructor2)) - vec1 = getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor1))), coordinates - )() - vec2 = getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor2))), coordinates - )() + ref_vec = ROOT.Math.Polar2DVector(*constructor1).__sub__( + ROOT.Math.Polar2DVector(*constructor2) + ) + vec1 = getattr(vector.obj(**dict(zip(["rho", "phi"], constructor1))), coordinates)() + vec2 = getattr(vector.obj(**dict(zip(["rho", "phi"], constructor2))), coordinates)() res_vec = vec1.subtract(vec2) - assert (ref_vec.R() == pytest.approx(res_vec.rho) and - ref_vec.Phi() == pytest.approx(res_vec.phi)) + assert ref_vec.R() == pytest.approx(res_vec.rho) and ref_vec.Phi() == pytest.approx( + res_vec.phi + ) # Run a test that compares ROOT's '__neg__' with vector's '__neg__' for all cases. @@ -322,22 +398,30 @@ def test_neg(constructor, coordinates): vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates )().__neg__ - assert (ref_vec.R() == pytest.approx(vec().rho) and - ref_vec.Phi() == pytest.approx(vec().phi)) + assert ref_vec.R() == pytest.approx(vec().rho) and ref_vec.Phi() == pytest.approx( + vec().phi + ) # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_neg(constructor, coordinates): ref_vec = ROOT.Math.Polar2DVector(*constructor).__neg__() vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates )().__neg__ - assert (ref_vec.R() == pytest.approx(vec().rho) and - ref_vec.Phi() == pytest.approx(vec().phi)) + assert ref_vec.R() == pytest.approx(vec().rho) and ref_vec.Phi() == pytest.approx( + vec().phi + ) # Run a test that compares ROOT's '__mul__' with vector's 'mul' for all cases. @@ -347,24 +431,32 @@ def test_mul(constructor, scalar, coordinates): vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates )().__mul__(scalar) - assert (ref_vec.R() == pytest.approx(vec.rho) and - ref_vec.Phi() == pytest.approx(vec.phi)) + assert ref_vec.R() == pytest.approx(vec.rho) and ref_vec.Phi() == pytest.approx( + vec.phi + ) # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - scalar=st.floats(min_value=-10e7, max_value=10e7) - | st.integers(min_value=-10e7, max_value=10e7)) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + scalar=st.floats(min_value=-10e7, max_value=10e7) + | st.integers(min_value=-10e7, max_value=10e7), +) def test_fuzz_mul(constructor, scalar, coordinates): ref_vec = ROOT.Math.Polar2DVector(*constructor).__mul__(scalar) vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates )().__mul__(scalar) - assert (ref_vec.R() == pytest.approx(vec.rho) and - ref_vec.Phi() == pytest.approx(vec.phi)) + assert ref_vec.R() == pytest.approx(vec.rho) and ref_vec.Phi() == pytest.approx( + vec.phi + ) # Run a test that compares ROOT's '__truediv__' with vector's '__truediv__' for all cases. @@ -374,50 +466,66 @@ def test_truediv(constructor, scalar, coordinates): vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates )().__truediv__(scalar) - assert (ref_vec.R() == pytest.approx(vec.rho) and - ref_vec.Phi() == pytest.approx(vec.phi)) + assert ref_vec.R() == pytest.approx(vec.rho) and ref_vec.Phi() == pytest.approx( + vec.phi + ) # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - scalar=st.floats(min_value=-10e7, max_value=10e7) - | st.integers(min_value=-10e7, max_value=10e7)) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + scalar=st.floats(min_value=-10e7, max_value=10e7) + | st.integers(min_value=-10e7, max_value=10e7), +) def test_fuzz_truediv(constructor, scalar, coordinates): ref_vec = ROOT.Math.Polar2DVector(*constructor).__truediv__(scalar) vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates )().__truediv__(scalar) - assert (ref_vec.R() == pytest.approx(vec.rho) and - ref_vec.Phi() == pytest.approx(vec.phi)) + assert ref_vec.R() == pytest.approx(vec.rho) and ref_vec.Phi() == pytest.approx( + vec.phi + ) # Run a test that compares ROOT's '__eq__' with vector's 'isclose' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_eq(constructor, coordinates): - ref_vec = ROOT.Math.Polar2DVector(*constructor).__eq__(ROOT.Math.Polar2DVector(*constructor)) + ref_vec = ROOT.Math.Polar2DVector(*constructor).__eq__( + ROOT.Math.Polar2DVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )() + )().isclose( + getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() ) assert ref_vec == vec # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_eq(constructor, coordinates): - ref_vec = ROOT.Math.Polar2DVector(*constructor).__eq__(ROOT.Math.Polar2DVector(*constructor)) + ref_vec = ROOT.Math.Polar2DVector(*constructor).__eq__( + ROOT.Math.Polar2DVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )().equal(getattr( - vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates - )() + )().equal( + getattr(vector.obj(**dict(zip(["rho", "phi"], constructor))), coordinates)() ) assert ref_vec == vec diff --git a/tests/root/test_Polar3DVector.py b/tests/root/test_Polar3DVector.py index 0f98249c..4bcb9db8 100644 --- a/tests/root/test_Polar3DVector.py +++ b/tests/root/test_Polar3DVector.py @@ -3,10 +3,10 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. -import pytest -from hypothesis import given, strategies as st - import numpy as np +import pytest +from hypothesis import given +from hypothesis import strategies as st import vector @@ -21,9 +21,9 @@ (1, 0, 0), (1, 10, 0), (1, -10, 0), - (1., 2.5, 2.), - (1, 2.5, 2.), - (1, -2.5, 2.), + (1.0, 2.5, 2.0), + (1, 2.5, 2.0), + (1, -2.5, 2.0), ] # Coordinate conversion methods to apply to the VectorObject2D. @@ -36,10 +36,12 @@ "to_xytheta", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -53,10 +55,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -65,39 +69,61 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. # rho = r*sin(theta) @pytest.mark.parametrize("constructor", constructor) def test_Dot(constructor, coordinates): - assert ROOT.Math.Polar3DVector(*constructor).Dot(ROOT.Math.Polar3DVector(*constructor)) == pytest.approx( + assert ROOT.Math.Polar3DVector(*constructor).Dot( + ROOT.Math.Polar3DVector(*constructor) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates - )()) + )().dot( + getattr( + vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), + coordinates, + )() + ) ) # Run the same tests within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fuzz_Dot(constructor1, constructor2, coordinates): - assert ROOT.Math.Polar3DVector(*constructor1).Dot(ROOT.Math.Polar3DVector(*constructor2)) == pytest.approx( + assert ROOT.Math.Polar3DVector(*constructor1).Dot( + ROOT.Math.Polar3DVector(*constructor2) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["rho", "theta", "phi"], constructor1))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["rho", "theta", "phi"], constructor2))), coordinates - )()) + )().dot( + getattr( + vector.obj(**dict(zip(["rho", "theta", "phi"], constructor2))), + coordinates, + )() + ) ) @@ -115,9 +141,12 @@ def test_Mag2(constructor, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_R(constructor, coordinates): assert ROOT.Math.Polar3DVector(*constructor).R() == pytest.approx( - np.sqrt(getattr( - vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates - )().rho2) + np.sqrt( + getattr( + vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), + coordinates, + )().rho2 + ) ) @@ -134,7 +163,7 @@ def test_Phi(constructor, coordinates): # Run a test that compares ROOT's 'RotateX()' with vector's 'rotateX' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateX(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationX(angle)*ROOT.Math.Polar3DVector(*constructor) + ref_vec = ROOT.Math.RotationX(angle) * ROOT.Math.Polar3DVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates )() @@ -147,7 +176,7 @@ def test_RotateX(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateY()' with vector's 'rotateY' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateY(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationY(angle)*ROOT.Math.Polar3DVector(*constructor) + ref_vec = ROOT.Math.RotationY(angle) * ROOT.Math.Polar3DVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates )() @@ -160,7 +189,7 @@ def test_RotateY(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateZ()' with vector's 'rotateZ' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateZ(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationZ(angle)*ROOT.Math.Polar3DVector(*constructor) + ref_vec = ROOT.Math.RotationZ(angle) * ROOT.Math.Polar3DVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates )() @@ -189,17 +218,24 @@ def test_X_and_Y(constructor, coordinates): vec = getattr( vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates )() - assert (ROOT.Math.Polar3DVector(*constructor).X() == pytest.approx(vec.x) and - ROOT.Math.Polar3DVector(*constructor).Y() == pytest.approx(vec.y)) + assert ROOT.Math.Polar3DVector(*constructor).X() == pytest.approx( + vec.x + ) and ROOT.Math.Polar3DVector(*constructor).Y() == pytest.approx(vec.y) + # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): - ref_vec = ROOT.Math.Polar3DVector(*constructor).__add__(ROOT.Math.Polar3DVector(*constructor)) + ref_vec = ROOT.Math.Polar3DVector(*constructor).__add__( + ROOT.Math.Polar3DVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates)()) + )().add( + getattr( + vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates + )() + ) assert ref_vec.X() == pytest.approx(vec.x) assert ref_vec.Y() == pytest.approx(vec.y) assert ref_vec.Z() == pytest.approx(vec.z) @@ -208,7 +244,9 @@ def test_add(constructor, coordinates): # Run a test that compares ROOT's '__sub__' with vector's 'subtract' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): - ref_vec = ROOT.Math.Polar3DVector(*constructor).__sub__(ROOT.Math.Polar3DVector(*constructor)) + ref_vec = ROOT.Math.Polar3DVector(*constructor).__sub__( + ROOT.Math.Polar3DVector(*constructor) + ) vec1 = getattr( vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates )() @@ -260,11 +298,14 @@ def test_truediv(constructor, scalar, coordinates): # Run a test that compares ROOT's '__eq__' with vector's 'isclose' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_eq(constructor, coordinates): - ref_vec = ROOT.Math.Polar3DVector(*constructor).__eq__(ROOT.Math.Polar3DVector(*constructor)) + ref_vec = ROOT.Math.Polar3DVector(*constructor).__eq__( + ROOT.Math.Polar3DVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates - )() + )().isclose( + getattr( + vector.obj(**dict(zip(["rho", "theta", "phi"], constructor))), coordinates + )() ) assert ref_vec == vec diff --git a/tests/root/test_PtEtaPhiEVector.py b/tests/root/test_PtEtaPhiEVector.py index 24d85b2c..f3b276b4 100644 --- a/tests/root/test_PtEtaPhiEVector.py +++ b/tests/root/test_PtEtaPhiEVector.py @@ -4,7 +4,8 @@ # or https://github.com/scikit-hep/vector for details. import pytest -from hypothesis import given, strategies as st +from hypothesis import given +from hypothesis import strategies as st import vector @@ -14,7 +15,7 @@ # ROOT.Math.PtEtaPhiEVector constructor arguments to get all the weird cases. constructor = [ (0, 0, 0, 0), - (0, 0, 1, 0), # theta == 0.0 + (0, 0, 1, 0), # theta == 0.0 (0, 0, -1, 0), (0, 0, 1, 0), (0, 0, 0, 4294967296), @@ -24,7 +25,7 @@ (1, 2, 3, 0), (1, 2, 3, 10), (1, 2, 3, -10), - (1., 2., 3., 2.5), + (1.0, 2.0, 3.0, 2.5), (1, 2, 3, 2.5), (1, 2, 3, -2.5), ] @@ -32,7 +33,7 @@ # Coordinate conversion methods to apply to the VectorObject4D. coordinate_list = [ "to_xyzt", - "to_xythetat", # may fail for constructor2 + "to_xythetat", # may fail for constructor2 "to_xyetat", "to_rhophizt", "to_rhophithetat", @@ -45,10 +46,12 @@ "to_rhophietatau", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -62,10 +65,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -74,10 +79,12 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. # Dot @pytest.mark.parametrize("constructor", constructor) @@ -88,15 +95,38 @@ def test_Dot(constructor, coordinates): v2 = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates )() - assert ROOT.Math.PtEtaPhiEVector(*constructor).Dot(ROOT.Math.PtEtaPhiEVector(*constructor)) == pytest.approx( - v1.dot(v2) - ) + assert ROOT.Math.PtEtaPhiEVector(*constructor).Dot( + ROOT.Math.PtEtaPhiEVector(*constructor) + ) == pytest.approx(v1.dot(v2)) + # Run the same test within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fizz_Dot(constructor1, constructor2, coordinates): v1 = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor1))), coordinates @@ -104,9 +134,10 @@ def test_fizz_Dot(constructor1, constructor2, coordinates): v2 = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor2))), coordinates )() - assert ROOT.Math.PtEtaPhiEVector(*constructor1).Dot(ROOT.Math.PtEtaPhiEVector(*constructor2)) == pytest.approx( - v1.dot(v2) - ) + assert ROOT.Math.PtEtaPhiEVector(*constructor1).Dot( + ROOT.Math.PtEtaPhiEVector(*constructor2) + ) == pytest.approx(v1.dot(v2)) + # Run a test that compares ROOT's 'M2()' with vector's 'tau2' for all cases. # Mass2 is our tau2 (or mass2 if it's a momentum vector and has kinematic synonyms) @@ -114,35 +145,68 @@ def test_fizz_Dot(constructor1, constructor2, coordinates): def test_M2(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).M2() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().tau2 ) + # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_M2(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).M2() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().tau2 ) + # Run a test that compares ROOT's 'M()' with vector's 'tau' for all cases. # Mass is tau (or mass) @pytest.mark.parametrize("constructor", constructor) def test_M(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).M() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().tau ) + # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_M(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).M() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().tau ) @@ -154,9 +218,10 @@ def test_Mt2(constructor, coordinates): vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates )() assert ROOT.Math.PtEtaPhiEVector(*constructor).Mt2() == pytest.approx( - v.t*v.t - v.z*v.z + v.t * v.t - v.z * v.z ) + # Run a test that compares ROOT's 'Mt()' with vector's 'mt' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Mt(constructor, coordinates): @@ -164,161 +229,197 @@ def test_Mt(constructor, coordinates): vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates )() assert ROOT.Math.PtEtaPhiEVector(*constructor).mt() == pytest.approx( - v.lib.sqrt(v.t*v.t - v.z*v.z) + v.lib.sqrt(v.t * v.t - v.z * v.z) ) + # Run a test that compares ROOT's 'P2()' with vector's 'mag2' for all cases. # P2 is our mag2 (ROOT's 4D mag2 is the dot product with itself, what we call tau or mass) @pytest.mark.parametrize("constructor", constructor) def test_P2(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).P2() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().mag2 ) + # Run a test that compares ROOT's 'P()' with vector's 'mag' for all cases. # P is our mag (same deal) @pytest.mark.parametrize("constructor", constructor) def test_P(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).P() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().mag ) + # Run a test that compares ROOT's 'Perp2()' with vector's 'rho2' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Perp2(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).Perp2() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().rho2 ) + # Run a test that compares ROOT's 'Perp()' with vector's 'rho' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Perp(constructor, coordinates): - assert ROOT.Math.sqrt(ROOT.Math.PtEtaPhiEVector(*constructor).Perp2()) == pytest.approx( + assert ROOT.Math.sqrt( + ROOT.Math.PtEtaPhiEVector(*constructor).Perp2() + ) == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().rho ) + # Run a test that compares ROOT's 'Phi()' with vector's 'phi' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Phi(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).Phi() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().phi ) + # Run a test that compares ROOT's 'Rapidity()' with vector's 'rapidity' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Rapidity(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).Rapidity() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().rapidity ) + # Run a test that compares ROOT's 'Beta()' with vector's 'beta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Beta(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).Beta() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().beta ) + # Run a test that compares ROOT's 'Eta()' with vector's 'eta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Eta(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).Eta() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().eta ) + # Run a test that compares ROOT's 'Gamma()' with vector's 'gamma' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Gamma(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).Gamma() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().gamma ) + # Run a test that compares ROOT's 'isLightlike()' with vector's 'is_lightlike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isLightlike(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).isLightlike() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().is_lightlike() ) + # Run a test that compares ROOT's 'isSpacelike()' with vector's 'is_spacelike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isSpacelike(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).isSpacelike() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().is_spacelike() ) + # Run a test that compares ROOT's 'isTimelike()' with vector's 'is_timelike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isTimelike(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).isTimelike() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().is_timelike() ) + # Run a test that compares ROOT's 'Theta()' with vector's 'theta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Theta(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).Theta() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().theta ) + # Run a test that compares ROOT's 'X()' with vector's 'x' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_X(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).X() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().x ) + # Run a test that compares ROOT's 'Y()' with vector's 'y' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Y(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).Y() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().y ) + # Run a test that compares ROOT's 'Z()' with vector's 'z' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Z(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).Z() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().z ) + # Run a test that compares ROOT's 'T()' with vector's 't' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_T(constructor, coordinates): assert ROOT.Math.PtEtaPhiEVector(*constructor).T() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, )().t ) @@ -326,11 +427,17 @@ def test_T(constructor, coordinates): # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): - ref_vec = ROOT.Math.PtEtaPhiEVector(*constructor).__add__(ROOT.Math.PtEtaPhiEVector(*constructor)) + ref_vec = ROOT.Math.PtEtaPhiEVector(*constructor).__add__( + ROOT.Math.PtEtaPhiEVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates)()) + )().add( + getattr( + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, + )() + ) assert ref_vec.X() == pytest.approx(vec.x) assert ref_vec.Y() == pytest.approx(vec.y) assert ref_vec.Z() == pytest.approx(vec.z) @@ -340,7 +447,9 @@ def test_add(constructor, coordinates): # Run a test that compares ROOT's '__sub__' with vector's 'subtract' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): - ref_vec = ROOT.Math.PtEtaPhiEVector(*constructor).__sub__(ROOT.Math.PtEtaPhiEVector(*constructor)) + ref_vec = ROOT.Math.PtEtaPhiEVector(*constructor).__sub__( + ROOT.Math.PtEtaPhiEVector(*constructor) + ) vec1 = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates )() @@ -353,6 +462,7 @@ def test_sub(constructor, coordinates): assert ref_vec.Z() == pytest.approx(res_vec.z) assert ref_vec.T() == pytest.approx(res_vec.t) + # Run a test that compares ROOT's '__neg__' with vector's '__neg__' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_neg(constructor, coordinates): @@ -395,12 +505,16 @@ def test_truediv(constructor, scalar, coordinates): # Run a test that compares ROOT's '__eq__' with vector's 'isclose' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_eq(constructor, coordinates): - ref_vec = ROOT.Math.PtEtaPhiEVector(*constructor).__eq__(ROOT.Math.PtEtaPhiEVector(*constructor)) + ref_vec = ROOT.Math.PtEtaPhiEVector(*constructor).__eq__( + ROOT.Math.PtEtaPhiEVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates - )() + )().isclose( + getattr( + vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), + coordinates, + )() ) assert ref_vec == vec @@ -408,7 +522,7 @@ def test_eq(constructor, coordinates): # Run a test that compares ROOT's 'RotateX()' with vector's 'rotateX' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateX(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationX(angle)*ROOT.Math.PtEtaPhiEVector(*constructor) + ref_vec = ROOT.Math.RotationX(angle) * ROOT.Math.PtEtaPhiEVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates )() @@ -422,7 +536,7 @@ def test_RotateX(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateY()' with vector's 'rotateY' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateY(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationY(angle)*ROOT.Math.PtEtaPhiEVector(*constructor) + ref_vec = ROOT.Math.RotationY(angle) * ROOT.Math.PtEtaPhiEVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates )() @@ -436,7 +550,7 @@ def test_RotateY(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateZ()' with vector's 'rotateZ' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateZ(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationZ(angle)*ROOT.Math.PtEtaPhiEVector(*constructor) + ref_vec = ROOT.Math.RotationZ(angle) * ROOT.Math.PtEtaPhiEVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "t"], constructor))), coordinates )() diff --git a/tests/root/test_PtEtaPhiMVector.py b/tests/root/test_PtEtaPhiMVector.py index 0447e232..6d70713c 100644 --- a/tests/root/test_PtEtaPhiMVector.py +++ b/tests/root/test_PtEtaPhiMVector.py @@ -4,7 +4,8 @@ # or https://github.com/scikit-hep/vector for details. import pytest -from hypothesis import given, strategies as st +from hypothesis import given +from hypothesis import strategies as st import vector @@ -14,7 +15,7 @@ # ROOT.Math.PtEtaPhiMVector constructor arguments to get all the weird cases. constructor = [ (0, 0, 0, 0), - (0, 0, 1, 0), # theta == 0.0 + (0, 0, 1, 0), # theta == 0.0 (0, 0, -1, 0), (0, 0, 1, 0), (0, 0, 0, 4294967296), @@ -24,7 +25,7 @@ (1, 2, 3, 0), (1, 2, 3, 10), (1, 2, 3, -10), - (1., 2., 3., 2.5), + (1.0, 2.0, 3.0, 2.5), (1, 2, 3, 2.5), (1, 2, 3, -2.5), ] @@ -32,7 +33,7 @@ # Coordinate conversion methods to apply to the VectorObject4D. coordinate_list = [ "to_xyzt", - "to_xythetat", # may fail for constructor2 + "to_xythetat", # may fail for constructor2 "to_xyetat", "to_rhophizt", "to_rhophithetat", @@ -45,10 +46,12 @@ "to_rhophietatau", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -62,10 +65,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -74,10 +79,12 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. # Dot @pytest.mark.parametrize("constructor", constructor) @@ -88,15 +95,38 @@ def test_Dot(constructor, coordinates): v2 = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates )() - assert ROOT.Math.PtEtaPhiMVector(*constructor).Dot(ROOT.Math.PtEtaPhiMVector(*constructor)) == pytest.approx( - v1.dot(v2) - ) + assert ROOT.Math.PtEtaPhiMVector(*constructor).Dot( + ROOT.Math.PtEtaPhiMVector(*constructor) + ) == pytest.approx(v1.dot(v2)) + # Run the same test within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fizz_Dot(constructor1, constructor2, coordinates): v1 = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor1))), coordinates @@ -104,9 +134,10 @@ def test_fizz_Dot(constructor1, constructor2, coordinates): v2 = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor2))), coordinates )() - assert ROOT.Math.PtEtaPhiMVector(*constructor1).Dot(ROOT.Math.PtEtaPhiMVector(*constructor2)) == pytest.approx( - v1.dot(v2) - ) + assert ROOT.Math.PtEtaPhiMVector(*constructor1).Dot( + ROOT.Math.PtEtaPhiMVector(*constructor2) + ) == pytest.approx(v1.dot(v2)) + # Run a test that compares ROOT's 'M2()' with vector's 'tau2' for all cases. # Mass2 is our tau2 (or mass2 if it's a momentum vector and has kinematic synonyms) @@ -114,35 +145,68 @@ def test_fizz_Dot(constructor1, constructor2, coordinates): def test_M2(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).M2() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().tau2 ) + # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_M2(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).M2() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().tau2 ) + # Run a test that compares ROOT's 'M()' with vector's 'tau' for all cases. # Mass is tau (or mass) @pytest.mark.parametrize("constructor", constructor) def test_M(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).M() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().tau ) + # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_M(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).M() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().tau ) @@ -154,9 +218,10 @@ def test_Mt2(constructor, coordinates): vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates )() assert ROOT.Math.PtEtaPhiMVector(*constructor).Mt2() == pytest.approx( - v.t*v.t - v.z*v.z + v.t * v.t - v.z * v.z ) + # Run a test that compares ROOT's 'Mt()' with vector's 'mt' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Mt(constructor, coordinates): @@ -164,161 +229,197 @@ def test_Mt(constructor, coordinates): vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates )() assert ROOT.Math.PtEtaPhiMVector(*constructor).mt() == pytest.approx( - v.lib.sqrt(v.t*v.t - v.z*v.z) + v.lib.sqrt(v.t * v.t - v.z * v.z) ) + # Run a test that compares ROOT's 'P2()' with vector's 'mag2' for all cases. # P2 is our mag2 (ROOT's 4D mag2 is the dot product with itself, what we call tau or mass) @pytest.mark.parametrize("constructor", constructor) def test_P2(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).P2() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().mag2 ) + # Run a test that compares ROOT's 'P()' with vector's 'mag' for all cases. # P is our mag (same deal) @pytest.mark.parametrize("constructor", constructor) def test_P(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).P() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().mag ) + # Run a test that compares ROOT's 'Perp2()' with vector's 'rho2' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Perp2(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).Perp2() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().rho2 ) + # Run a test that compares ROOT's 'Perp()' with vector's 'rho' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Perp(constructor, coordinates): - assert ROOT.Math.sqrt(ROOT.Math.PtEtaPhiMVector(*constructor).Perp2()) == pytest.approx( + assert ROOT.Math.sqrt( + ROOT.Math.PtEtaPhiMVector(*constructor).Perp2() + ) == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().rho ) + # Run a test that compares ROOT's 'Phi()' with vector's 'phi' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Phi(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).Phi() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().phi ) + # Run a test that compares ROOT's 'Rapidity()' with vector's 'rapidity' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Rapidity(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).Rapidity() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().rapidity ) + # Run a test that compares ROOT's 'Beta()' with vector's 'beta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Beta(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).Beta() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().beta ) + # Run a test that compares ROOT's 'Eta()' with vector's 'eta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Eta(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).Eta() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().eta ) + # Run a test that compares ROOT's 'Gamma()' with vector's 'gamma' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Gamma(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).Gamma() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().gamma ) + # Run a test that compares ROOT's 'isLightlike()' with vector's 'is_lightlike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isLightlike(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).isLightlike() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().is_lightlike() ) + # Run a test that compares ROOT's 'isSpacelike()' with vector's 'is_spacelike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isSpacelike(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).isSpacelike() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().is_spacelike() ) + # Run a test that compares ROOT's 'isTimelike()' with vector's 'is_timelike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isTimelike(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).isTimelike() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().is_timelike() ) + # Run a test that compares ROOT's 'Theta()' with vector's 'theta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Theta(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).Theta() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().theta ) + # Run a test that compares ROOT's 'X()' with vector's 'x' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_X(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).X() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().x ) + # Run a test that compares ROOT's 'Y()' with vector's 'y' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Y(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).Y() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().y ) + # Run a test that compares ROOT's 'Z()' with vector's 'z' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Z(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).Z() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().z ) + # Run a test that compares ROOT's 'T()' with vector's 't' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_T(constructor, coordinates): assert ROOT.Math.PtEtaPhiMVector(*constructor).T() == pytest.approx( getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, )().t ) @@ -326,11 +427,17 @@ def test_T(constructor, coordinates): # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): - ref_vec = ROOT.Math.PtEtaPhiMVector(*constructor).__add__(ROOT.Math.PtEtaPhiMVector(*constructor)) + ref_vec = ROOT.Math.PtEtaPhiMVector(*constructor).__add__( + ROOT.Math.PtEtaPhiMVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates)()) + )().add( + getattr( + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, + )() + ) assert ref_vec.X() == pytest.approx(vec.x) assert ref_vec.Y() == pytest.approx(vec.y) assert ref_vec.Z() == pytest.approx(vec.z) @@ -340,7 +447,9 @@ def test_add(constructor, coordinates): # Run a test that compares ROOT's '__sub__' with vector's 'subtract' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): - ref_vec = ROOT.Math.PtEtaPhiMVector(*constructor).__sub__(ROOT.Math.PtEtaPhiMVector(*constructor)) + ref_vec = ROOT.Math.PtEtaPhiMVector(*constructor).__sub__( + ROOT.Math.PtEtaPhiMVector(*constructor) + ) vec1 = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates )() @@ -353,6 +462,7 @@ def test_sub(constructor, coordinates): assert ref_vec.Z() == pytest.approx(res_vec.z) assert ref_vec.T() == pytest.approx(res_vec.t) + # Run a test that compares ROOT's '__neg__' with vector's '__neg__' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_neg(constructor, coordinates): @@ -395,12 +505,16 @@ def test_truediv(constructor, scalar, coordinates): # Run a test that compares ROOT's '__eq__' with vector's 'isclose' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_eq(constructor, coordinates): - ref_vec = ROOT.Math.PtEtaPhiMVector(*constructor).__eq__(ROOT.Math.PtEtaPhiMVector(*constructor)) + ref_vec = ROOT.Math.PtEtaPhiMVector(*constructor).__eq__( + ROOT.Math.PtEtaPhiMVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates - )() + )().isclose( + getattr( + vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), + coordinates, + )() ) assert ref_vec == vec @@ -408,7 +522,7 @@ def test_eq(constructor, coordinates): # Run a test that compares ROOT's 'RotateX()' with vector's 'rotateX' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateX(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationX(angle)*ROOT.Math.PtEtaPhiMVector(*constructor) + ref_vec = ROOT.Math.RotationX(angle) * ROOT.Math.PtEtaPhiMVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates )() @@ -422,7 +536,7 @@ def test_RotateX(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateY()' with vector's 'rotateY' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateY(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationY(angle)*ROOT.Math.PtEtaPhiMVector(*constructor) + ref_vec = ROOT.Math.RotationY(angle) * ROOT.Math.PtEtaPhiMVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates )() @@ -436,7 +550,7 @@ def test_RotateY(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateZ()' with vector's 'rotateZ' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateZ(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationZ(angle)*ROOT.Math.PtEtaPhiMVector(*constructor) + ref_vec = ROOT.Math.RotationZ(angle) * ROOT.Math.PtEtaPhiMVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi", "tau"], constructor))), coordinates )() diff --git a/tests/root/test_PxPyPzEVector.py b/tests/root/test_PxPyPzEVector.py index 6d62dcbb..f22659bf 100644 --- a/tests/root/test_PxPyPzEVector.py +++ b/tests/root/test_PxPyPzEVector.py @@ -4,7 +4,8 @@ # or https://github.com/scikit-hep/vector for details. import pytest -from hypothesis import given, strategies as st +from hypothesis import given +from hypothesis import strategies as st import vector @@ -14,7 +15,7 @@ # ROOT.Math.PxPyPzEVector constructor arguments to get all the weird cases. constructor = [ (0, 0, 0, 0), - (0, 0, 1, 0), # theta == 0.0 + (0, 0, 1, 0), # theta == 0.0 (0, 0, -1, 0), (0, 0, 1, 0), (0, 0, 0, 4294967296), @@ -24,7 +25,7 @@ (1, 2, 3, 0), (1, 2, 3, 10), (1, 2, 3, -10), - (1., 2., 3., 2.5), + (1.0, 2.0, 3.0, 2.5), (1, 2, 3, 2.5), (1, 2, 3, -2.5), ] @@ -32,7 +33,7 @@ # Coordinate conversion methods to apply to the VectorObject4D. coordinate_list = [ "to_xyzt", - "to_xythetat", # may fail for constructor2 + "to_xythetat", # may fail for constructor2 "to_xyetat", "to_rhophizt", "to_rhophithetat", @@ -45,10 +46,12 @@ "to_rhophietatau", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -62,10 +65,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -74,10 +79,12 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. # Dot @pytest.mark.parametrize("constructor", constructor) @@ -88,15 +95,38 @@ def test_Dot(constructor, coordinates): v2 = getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates )() - assert ROOT.Math.PxPyPzEVector(*constructor).Dot(ROOT.Math.PxPyPzEVector(*constructor)) == pytest.approx( - v1.dot(v2) - ) + assert ROOT.Math.PxPyPzEVector(*constructor).Dot( + ROOT.Math.PxPyPzEVector(*constructor) + ) == pytest.approx(v1.dot(v2)) + # Run the same test within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fizz_Dot(constructor1, constructor2, coordinates): v1 = getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor1))), coordinates @@ -104,9 +134,10 @@ def test_fizz_Dot(constructor1, constructor2, coordinates): v2 = getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor2))), coordinates )() - assert ROOT.Math.PxPyPzEVector(*constructor1).Dot(ROOT.Math.PxPyPzEVector(*constructor2)) == pytest.approx( - v1.dot(v2) - ) + assert ROOT.Math.PxPyPzEVector(*constructor1).Dot( + ROOT.Math.PxPyPzEVector(*constructor2) + ) == pytest.approx(v1.dot(v2)) + # Run a test that compares ROOT's 'M2()' with vector's 'tau2' for all cases. # Mass2 is our tau2 (or mass2 if it's a momentum vector and has kinematic synonyms) @@ -118,8 +149,22 @@ def test_M2(constructor, coordinates): )().tau2 ) + # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_M2(constructor, coordinates): assert ROOT.Math.PxPyPzEVector(*constructor).M2() == pytest.approx( getattr( @@ -127,6 +172,7 @@ def test_fuzz_M2(constructor, coordinates): )().tau2 ) + # Run a test that compares ROOT's 'M()' with vector's 'tau' for all cases. # Mass is tau (or mass) @pytest.mark.parametrize("constructor", constructor) @@ -137,8 +183,22 @@ def test_M(constructor, coordinates): )().tau ) + # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_M(constructor, coordinates): assert ROOT.Math.PxPyPzEVector(*constructor).M() == pytest.approx( getattr( @@ -154,9 +214,10 @@ def test_Mt2(constructor, coordinates): vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates )() assert ROOT.Math.PxPyPzEVector(*constructor).Mt2() == pytest.approx( - v.t*v.t - v.z*v.z + v.t * v.t - v.z * v.z ) + # Run a test that compares ROOT's 'Mt()' with vector's 'mt' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Mt(constructor, coordinates): @@ -164,9 +225,10 @@ def test_Mt(constructor, coordinates): vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates )() assert ROOT.Math.PxPyPzEVector(*constructor).mt() == pytest.approx( - v.lib.sqrt(v.t*v.t - v.z*v.z) + v.lib.sqrt(v.t * v.t - v.z * v.z) ) + # Run a test that compares ROOT's 'P2()' with vector's 'mag2' for all cases. # P2 is our mag2 (ROOT's 4D mag2 is the dot product with itself, what we call tau or mass) @pytest.mark.parametrize("constructor", constructor) @@ -177,6 +239,7 @@ def test_P2(constructor, coordinates): )().mag2 ) + # Run a test that compares ROOT's 'P()' with vector's 'mag' for all cases. # P is our mag (same deal) @pytest.mark.parametrize("constructor", constructor) @@ -187,6 +250,7 @@ def test_P(constructor, coordinates): )().mag ) + # Run a test that compares ROOT's 'Perp2()' with vector's 'rho2' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Perp2(constructor, coordinates): @@ -196,15 +260,19 @@ def test_Perp2(constructor, coordinates): )().rho2 ) + # Run a test that compares ROOT's 'Perp()' with vector's 'rho' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Perp(constructor, coordinates): - assert ROOT.Math.sqrt(ROOT.Math.PxPyPzEVector(*constructor).Perp2()) == pytest.approx( + assert ROOT.Math.sqrt( + ROOT.Math.PxPyPzEVector(*constructor).Perp2() + ) == pytest.approx( getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates )().rho ) + # Run a test that compares ROOT's 'Phi()' with vector's 'phi' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Phi(constructor, coordinates): @@ -214,6 +282,7 @@ def test_Phi(constructor, coordinates): )().phi ) + # Run a test that compares ROOT's 'Rapidity()' with vector's 'rapidity' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Rapidity(constructor, coordinates): @@ -223,6 +292,7 @@ def test_Rapidity(constructor, coordinates): )().rapidity ) + # Run a test that compares ROOT's 'Beta()' with vector's 'beta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Beta(constructor, coordinates): @@ -232,6 +302,7 @@ def test_Beta(constructor, coordinates): )().beta ) + # Run a test that compares ROOT's 'Eta()' with vector's 'eta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Eta(constructor, coordinates): @@ -241,6 +312,7 @@ def test_Eta(constructor, coordinates): )().eta ) + # Run a test that compares ROOT's 'Gamma()' with vector's 'gamma' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Gamma(constructor, coordinates): @@ -250,6 +322,7 @@ def test_Gamma(constructor, coordinates): )().gamma ) + # Run a test that compares ROOT's 'isLightlike()' with vector's 'is_lightlike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isLightlike(constructor, coordinates): @@ -259,6 +332,7 @@ def test_isLightlike(constructor, coordinates): )().is_lightlike() ) + # Run a test that compares ROOT's 'isSpacelike()' with vector's 'is_spacelike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isSpacelike(constructor, coordinates): @@ -268,6 +342,7 @@ def test_isSpacelike(constructor, coordinates): )().is_spacelike() ) + # Run a test that compares ROOT's 'isTimelike()' with vector's 'is_timelike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isTimelike(constructor, coordinates): @@ -277,6 +352,7 @@ def test_isTimelike(constructor, coordinates): )().is_timelike() ) + # Run a test that compares ROOT's 'Theta()' with vector's 'theta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Theta(constructor, coordinates): @@ -286,6 +362,7 @@ def test_Theta(constructor, coordinates): )().theta ) + # Run a test that compares ROOT's 'X()' with vector's 'x' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_X(constructor, coordinates): @@ -295,6 +372,7 @@ def test_X(constructor, coordinates): )().x ) + # Run a test that compares ROOT's 'Y()' with vector's 'y' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Y(constructor, coordinates): @@ -304,6 +382,7 @@ def test_Y(constructor, coordinates): )().y ) + # Run a test that compares ROOT's 'Z()' with vector's 'z' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Z(constructor, coordinates): @@ -313,6 +392,7 @@ def test_Z(constructor, coordinates): )().z ) + # Run a test that compares ROOT's 'T()' with vector's 't' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_T(constructor, coordinates): @@ -326,11 +406,16 @@ def test_T(constructor, coordinates): # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): - ref_vec = ROOT.Math.PxPyPzEVector(*constructor).__add__(ROOT.Math.PxPyPzEVector(*constructor)) + ref_vec = ROOT.Math.PxPyPzEVector(*constructor).__add__( + ROOT.Math.PxPyPzEVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates)()) + )().add( + getattr( + vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates + )() + ) assert ref_vec.X() == pytest.approx(vec.x) assert ref_vec.Y() == pytest.approx(vec.y) assert ref_vec.Z() == pytest.approx(vec.z) @@ -340,7 +425,9 @@ def test_add(constructor, coordinates): # Run a test that compares ROOT's '__sub__' with vector's 'subtract' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): - ref_vec = ROOT.Math.PxPyPzEVector(*constructor).__sub__(ROOT.Math.PxPyPzEVector(*constructor)) + ref_vec = ROOT.Math.PxPyPzEVector(*constructor).__sub__( + ROOT.Math.PxPyPzEVector(*constructor) + ) vec1 = getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates )() @@ -353,6 +440,7 @@ def test_sub(constructor, coordinates): assert ref_vec.Z() == pytest.approx(res_vec.z) assert ref_vec.T() == pytest.approx(res_vec.t) + # Run a test that compares ROOT's '__neg__' with vector's '__neg__' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_neg(constructor, coordinates): @@ -395,12 +483,15 @@ def test_truediv(constructor, scalar, coordinates): # Run a test that compares ROOT's '__eq__' with vector's 'isclose' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_eq(constructor, coordinates): - ref_vec = ROOT.Math.PxPyPzEVector(*constructor).__eq__(ROOT.Math.PxPyPzEVector(*constructor)) + ref_vec = ROOT.Math.PxPyPzEVector(*constructor).__eq__( + ROOT.Math.PxPyPzEVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates - )() + )().isclose( + getattr( + vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates + )() ) assert ref_vec == vec @@ -408,7 +499,7 @@ def test_eq(constructor, coordinates): # Run a test that compares ROOT's 'RotateX()' with vector's 'rotateX' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateX(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationX(angle)*ROOT.Math.PxPyPzEVector(*constructor) + ref_vec = ROOT.Math.RotationX(angle) * ROOT.Math.PxPyPzEVector(*constructor) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates )() @@ -422,7 +513,7 @@ def test_RotateX(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateY()' with vector's 'rotateY' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateY(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationY(angle)*ROOT.Math.PxPyPzEVector(*constructor) + ref_vec = ROOT.Math.RotationY(angle) * ROOT.Math.PxPyPzEVector(*constructor) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates )() @@ -436,7 +527,7 @@ def test_RotateY(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateZ()' with vector's 'rotateZ' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateZ(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationZ(angle)*ROOT.Math.PxPyPzEVector(*constructor) + ref_vec = ROOT.Math.RotationZ(angle) * ROOT.Math.PxPyPzEVector(*constructor) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates )() diff --git a/tests/root/test_PxPyPzMVector.py b/tests/root/test_PxPyPzMVector.py index f41d362c..ee545c06 100644 --- a/tests/root/test_PxPyPzMVector.py +++ b/tests/root/test_PxPyPzMVector.py @@ -4,7 +4,8 @@ # or https://github.com/scikit-hep/vector for details. import pytest -from hypothesis import given, strategies as st +from hypothesis import given +from hypothesis import strategies as st import vector @@ -14,7 +15,7 @@ # ROOT.Math.PxPyPzMVector constructor arguments to get all the weird cases. constructor = [ (0, 0, 0, 0), - (0, 0, 1, 0), # theta == 0.0 + (0, 0, 1, 0), # theta == 0.0 (0, 0, -1, 0), (0, 0, 1, 0), (0, 0, 0, 4294967296), @@ -24,7 +25,7 @@ (1, 2, 3, 0), (1, 2, 3, 10), (1, 2, 3, -10), - (1., 2., 3., 2.5), + (1.0, 2.0, 3.0, 2.5), (1, 2, 3, 2.5), (1, 2, 3, -2.5), ] @@ -32,7 +33,7 @@ # Coordinate conversion methods to apply to the VectorObject4D. coordinate_list = [ "to_xyzt", - "to_xythetat", # may fail for constructor2 + "to_xythetat", # may fail for constructor2 "to_xyetat", "to_rhophizt", "to_rhophithetat", @@ -45,10 +46,12 @@ "to_rhophietatau", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -62,10 +65,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -74,10 +79,12 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. # Dot @pytest.mark.parametrize("constructor", constructor) @@ -88,15 +95,38 @@ def test_Dot(constructor, coordinates): v2 = getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates )() - assert ROOT.Math.PxPyPzMVector(*constructor).Dot(ROOT.Math.PxPyPzMVector(*constructor)) == pytest.approx( - v1.dot(v2) - ) + assert ROOT.Math.PxPyPzMVector(*constructor).Dot( + ROOT.Math.PxPyPzMVector(*constructor) + ) == pytest.approx(v1.dot(v2)) + # Run the same test within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fizz_Dot(constructor1, constructor2, coordinates): v1 = getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor1))), coordinates @@ -104,9 +134,10 @@ def test_fizz_Dot(constructor1, constructor2, coordinates): v2 = getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor2))), coordinates )() - assert ROOT.Math.PxPyPzMVector(*constructor1).Dot(ROOT.Math.PxPyPzMVector(*constructor2)) == pytest.approx( - v1.dot(v2) - ) + assert ROOT.Math.PxPyPzMVector(*constructor1).Dot( + ROOT.Math.PxPyPzMVector(*constructor2) + ) == pytest.approx(v1.dot(v2)) + # Run a test that compares ROOT's 'M2()' with vector's 'tau2' for all cases. # Mass2 is our tau2 (or mass2 if it's a momentum vector and has kinematic synonyms) @@ -118,8 +149,22 @@ def test_M2(constructor, coordinates): )().tau2 ) + # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_M2(constructor, coordinates): assert ROOT.Math.PxPyPzMVector(*constructor).M2() == pytest.approx( getattr( @@ -127,6 +172,7 @@ def test_fuzz_M2(constructor, coordinates): )().tau2 ) + # Run a test that compares ROOT's 'M()' with vector's 'tau' for all cases. # Mass is tau (or mass) @pytest.mark.parametrize("constructor", constructor) @@ -137,8 +183,22 @@ def test_M(constructor, coordinates): )().tau ) + # Run the same tests within hypothesis -@given(constructor=st.tuples(st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7), st.floats(min_value=-10e7, max_value=10e7)) | st.tuples(st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7), st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ) +) def test_fuzz_M(constructor, coordinates): assert ROOT.Math.PxPyPzMVector(*constructor).M() == pytest.approx( getattr( @@ -154,9 +214,10 @@ def test_Mt2(constructor, coordinates): vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates )() assert ROOT.Math.PxPyPzMVector(*constructor).Mt2() == pytest.approx( - v.t*v.t - v.z*v.z + v.t * v.t - v.z * v.z ) + # Run a test that compares ROOT's 'Mt()' with vector's 'mt' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Mt(constructor, coordinates): @@ -164,9 +225,10 @@ def test_Mt(constructor, coordinates): vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates )() assert ROOT.Math.PxPyPzMVector(*constructor).mt() == pytest.approx( - v.lib.sqrt(v.t*v.t - v.z*v.z) + v.lib.sqrt(v.t * v.t - v.z * v.z) ) + # Run a test that compares ROOT's 'P2()' with vector's 'mag2' for all cases. # P2 is our mag2 (ROOT's 4D mag2 is the dot product with itself, what we call tau or mass) @pytest.mark.parametrize("constructor", constructor) @@ -177,6 +239,7 @@ def test_P2(constructor, coordinates): )().mag2 ) + # Run a test that compares ROOT's 'P()' with vector's 'mag' for all cases. # P is our mag (same deal) @pytest.mark.parametrize("constructor", constructor) @@ -187,6 +250,7 @@ def test_P(constructor, coordinates): )().mag ) + # Run a test that compares ROOT's 'Perp2()' with vector's 'rho2' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Perp2(constructor, coordinates): @@ -196,15 +260,19 @@ def test_Perp2(constructor, coordinates): )().rho2 ) + # Run a test that compares ROOT's 'Perp()' with vector's 'rho' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Perp(constructor, coordinates): - assert ROOT.Math.sqrt(ROOT.Math.PxPyPzMVector(*constructor).Perp2()) == pytest.approx( + assert ROOT.Math.sqrt( + ROOT.Math.PxPyPzMVector(*constructor).Perp2() + ) == pytest.approx( getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates )().rho ) + # Run a test that compares ROOT's 'Phi()' with vector's 'phi' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Phi(constructor, coordinates): @@ -214,6 +282,7 @@ def test_Phi(constructor, coordinates): )().phi ) + # Run a test that compares ROOT's 'Rapidity()' with vector's 'rapidity' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Rapidity(constructor, coordinates): @@ -223,6 +292,7 @@ def test_Rapidity(constructor, coordinates): )().rapidity ) + # Run a test that compares ROOT's 'Beta()' with vector's 'beta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Beta(constructor, coordinates): @@ -232,6 +302,7 @@ def test_Beta(constructor, coordinates): )().beta ) + # Run a test that compares ROOT's 'Eta()' with vector's 'eta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Eta(constructor, coordinates): @@ -241,6 +312,7 @@ def test_Eta(constructor, coordinates): )().eta ) + # Run a test that compares ROOT's 'Gamma()' with vector's 'gamma' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Gamma(constructor, coordinates): @@ -250,6 +322,7 @@ def test_Gamma(constructor, coordinates): )().gamma ) + # Run a test that compares ROOT's 'isLightlike()' with vector's 'is_lightlike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isLightlike(constructor, coordinates): @@ -259,6 +332,7 @@ def test_isLightlike(constructor, coordinates): )().is_lightlike() ) + # Run a test that compares ROOT's 'isSpacelike()' with vector's 'is_spacelike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isSpacelike(constructor, coordinates): @@ -268,6 +342,7 @@ def test_isSpacelike(constructor, coordinates): )().is_spacelike() ) + # Run a test that compares ROOT's 'isTimelike()' with vector's 'is_timelike' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_isTimelike(constructor, coordinates): @@ -277,6 +352,7 @@ def test_isTimelike(constructor, coordinates): )().is_timelike() ) + # Run a test that compares ROOT's 'Theta()' with vector's 'theta' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Theta(constructor, coordinates): @@ -286,6 +362,7 @@ def test_Theta(constructor, coordinates): )().theta ) + # Run a test that compares ROOT's 'X()' with vector's 'x' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_X(constructor, coordinates): @@ -295,6 +372,7 @@ def test_X(constructor, coordinates): )().x ) + # Run a test that compares ROOT's 'Y()' with vector's 'y' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Y(constructor, coordinates): @@ -304,6 +382,7 @@ def test_Y(constructor, coordinates): )().y ) + # Run a test that compares ROOT's 'Z()' with vector's 'z' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Z(constructor, coordinates): @@ -313,6 +392,7 @@ def test_Z(constructor, coordinates): )().z ) + # Run a test that compares ROOT's 'T()' with vector's 't' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_T(constructor, coordinates): @@ -326,11 +406,16 @@ def test_T(constructor, coordinates): # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): - ref_vec = ROOT.Math.PxPyPzMVector(*constructor).__add__(ROOT.Math.PxPyPzMVector(*constructor)) + ref_vec = ROOT.Math.PxPyPzMVector(*constructor).__add__( + ROOT.Math.PxPyPzMVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates)()) + )().add( + getattr( + vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates + )() + ) assert ref_vec.X() == pytest.approx(vec.x) assert ref_vec.Y() == pytest.approx(vec.y) assert ref_vec.Z() == pytest.approx(vec.z) @@ -340,7 +425,9 @@ def test_add(constructor, coordinates): # Run a test that compares ROOT's '__sub__' with vector's 'subtract' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): - ref_vec = ROOT.Math.PxPyPzMVector(*constructor).__sub__(ROOT.Math.PxPyPzMVector(*constructor)) + ref_vec = ROOT.Math.PxPyPzMVector(*constructor).__sub__( + ROOT.Math.PxPyPzMVector(*constructor) + ) vec1 = getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates )() @@ -353,6 +440,7 @@ def test_sub(constructor, coordinates): assert ref_vec.Z() == pytest.approx(res_vec.z) assert ref_vec.T() == pytest.approx(res_vec.t) + # Run a test that compares ROOT's '__neg__' with vector's '__neg__' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_neg(constructor, coordinates): @@ -395,19 +483,23 @@ def test_truediv(constructor, scalar, coordinates): # Run a test that compares ROOT's '__eq__' with vector's 'isclose' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_eq(constructor, coordinates): - ref_vec = ROOT.Math.PxPyPzMVector(*constructor).__eq__(ROOT.Math.PxPyPzMVector(*constructor)) + ref_vec = ROOT.Math.PxPyPzMVector(*constructor).__eq__( + ROOT.Math.PxPyPzMVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates - )() + )().isclose( + getattr( + vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates + )() ) assert ref_vec == vec + # Run a test that compares ROOT's 'RotateX()' with vector's 'rotateX' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateX(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationX(angle)*ROOT.Math.PxPyPzMVector(*constructor) + ref_vec = ROOT.Math.RotationX(angle) * ROOT.Math.PxPyPzMVector(*constructor) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates )() @@ -417,10 +509,11 @@ def test_RotateX(constructor, angle, coordinates): assert ref_vec.Z() == pytest.approx(res_vec.z) assert ref_vec.T() == pytest.approx(res_vec.t) + # Run a test that compares ROOT's 'RotateY()' with vector's 'rotateY' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateY(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationY(angle)*ROOT.Math.PxPyPzMVector(*constructor) + ref_vec = ROOT.Math.RotationY(angle) * ROOT.Math.PxPyPzMVector(*constructor) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates )() @@ -430,10 +523,11 @@ def test_RotateY(constructor, angle, coordinates): assert ref_vec.Z() == pytest.approx(res_vec.z) assert ref_vec.T() == pytest.approx(res_vec.t) + # Run a test that compares ROOT's 'RotateZ()' with vector's 'rotateZ' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateZ(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationZ(angle)*ROOT.Math.PxPyPzMVector(*constructor) + ref_vec = ROOT.Math.RotationZ(angle) * ROOT.Math.PxPyPzMVector(*constructor) vec = getattr( vector.obj(**dict(zip(["x", "y", "z", "tau"], constructor))), coordinates )() diff --git a/tests/root/test_Quaternion.py b/tests/root/test_Quaternion.py index 53493eca..23f16730 100644 --- a/tests/root/test_Quaternion.py +++ b/tests/root/test_Quaternion.py @@ -4,9 +4,11 @@ # or https://github.com/scikit-hep/vector for details. import pytest -from hypothesis import given, strategies as st -import vector +# from hypothesis import given +# from hypothesis import strategies as st +# +# import vector # If ROOT is not available, skip these tests. ROOT = pytest.importorskip("ROOT") @@ -14,7 +16,7 @@ # ROOT.Math.XYVector constructor arguments to get all the weird cases. constructor = [ (0, 0, 0, 0), - (0, 0, 1, 0), # theta == 0.0 + (0, 0, 1, 0), # theta == 0.0 (0, 0, -1, 0), (0, 0, 1, 0), (0, 0, 0, 4294967296), @@ -24,7 +26,7 @@ (1, 2, 3, 0), (1, 2, 3, 10), (1, 2, 3, -10), - (1., 2., 3., 2.5), + (1.0, 2.0, 3.0, 2.5), (1, 2, 3, 2.5), (1, 2, 3, -2.5), ] @@ -32,7 +34,7 @@ # Coordinate conversion methods to apply to the VectorObject4D. coordinate_list = [ "to_xyzt", - "to_xythetat", # may fail for constructor2 + "to_xythetat", # may fail for constructor2 "to_xyetat", "to_rhophizt", "to_rhophithetat", @@ -45,10 +47,12 @@ "to_rhophietatau", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -62,10 +66,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -74,6 +80,7 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param diff --git a/tests/root/test_RhoEtaPhiVector.py b/tests/root/test_RhoEtaPhiVector.py index 3966b0c9..59640cb0 100644 --- a/tests/root/test_RhoEtaPhiVector.py +++ b/tests/root/test_RhoEtaPhiVector.py @@ -3,10 +3,10 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. -import pytest -from hypothesis import given, strategies as st - import numpy as np +import pytest +from hypothesis import given +from hypothesis import strategies as st import vector @@ -21,9 +21,9 @@ (1, 0, 0), (1, 10, 0), (1, -10, 0), - (1., 2.5, 2.), - (1, 2.5, 2.), - (1, -2.5, 2.), + (1.0, 2.5, 2.0), + (1, 2.5, 2.0), + (1, -2.5, 2.0), ] # Coordinate conversion methods to apply to the VectorObject2D. @@ -36,10 +36,12 @@ "to_xytheta", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -53,10 +55,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -65,38 +69,59 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Dot(constructor, coordinates): - assert ROOT.Math.RhoEtaPhiVector(*constructor).Dot(ROOT.Math.RhoEtaPhiVector(*constructor)) == pytest.approx( + assert ROOT.Math.RhoEtaPhiVector(*constructor).Dot( + ROOT.Math.RhoEtaPhiVector(*constructor) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates - )()) + )().dot( + getattr( + vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates + )() + ) ) # Run the same tests within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fuzz_Dot(constructor1, constructor2, coordinates): - assert ROOT.Math.RhoEtaPhiVector(*constructor1).Dot(ROOT.Math.RhoEtaPhiVector(*constructor2)) == pytest.approx( + assert ROOT.Math.RhoEtaPhiVector(*constructor1).Dot( + ROOT.Math.RhoEtaPhiVector(*constructor2) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["rho", "eta", "phi"], constructor1))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["rho", "eta", "phi"], constructor2))), coordinates - )()) + )().dot( + getattr( + vector.obj(**dict(zip(["rho", "eta", "phi"], constructor2))), + coordinates, + )() + ) ) @@ -114,9 +139,11 @@ def test_Mag2(constructor, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_R(constructor, coordinates): assert ROOT.Math.RhoEtaPhiVector(*constructor).R() == pytest.approx( - np.sqrt(getattr( - vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates - )().rho2) + np.sqrt( + getattr( + vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates + )().rho2 + ) ) @@ -133,7 +160,7 @@ def test_Phi(constructor, coordinates): # Run a test that compares ROOT's 'RotateX()' with vector's 'rotateX' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateX(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationX(angle)*ROOT.Math.RhoEtaPhiVector(*constructor) + ref_vec = ROOT.Math.RotationX(angle) * ROOT.Math.RhoEtaPhiVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates )() @@ -146,7 +173,7 @@ def test_RotateX(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateY()' with vector's 'rotateY' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateY(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationY(angle)*ROOT.Math.RhoEtaPhiVector(*constructor) + ref_vec = ROOT.Math.RotationY(angle) * ROOT.Math.RhoEtaPhiVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates )() @@ -159,7 +186,7 @@ def test_RotateY(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateZ()' with vector's 'rotateZ' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateZ(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationZ(angle)*ROOT.Math.RhoEtaPhiVector(*constructor) + ref_vec = ROOT.Math.RotationZ(angle) * ROOT.Math.RhoEtaPhiVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates )() @@ -188,17 +215,24 @@ def test_X_and_Y(constructor, coordinates): vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates )() - assert (ROOT.Math.RhoEtaPhiVector(*constructor).X() == pytest.approx(vec.x) and - ROOT.Math.RhoEtaPhiVector(*constructor).Y() == pytest.approx(vec.y)) + assert ROOT.Math.RhoEtaPhiVector(*constructor).X() == pytest.approx( + vec.x + ) and ROOT.Math.RhoEtaPhiVector(*constructor).Y() == pytest.approx(vec.y) + # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): - ref_vec = ROOT.Math.RhoEtaPhiVector(*constructor).__add__(ROOT.Math.RhoEtaPhiVector(*constructor)) + ref_vec = ROOT.Math.RhoEtaPhiVector(*constructor).__add__( + ROOT.Math.RhoEtaPhiVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates)()) + )().add( + getattr( + vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates + )() + ) assert ref_vec.X() == pytest.approx(vec.x) assert ref_vec.Y() == pytest.approx(vec.y) assert ref_vec.Z() == pytest.approx(vec.z) @@ -207,7 +241,9 @@ def test_add(constructor, coordinates): # Run a test that compares ROOT's '__sub__' with vector's 'subtract' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): - ref_vec = ROOT.Math.RhoEtaPhiVector(*constructor).__sub__(ROOT.Math.RhoEtaPhiVector(*constructor)) + ref_vec = ROOT.Math.RhoEtaPhiVector(*constructor).__sub__( + ROOT.Math.RhoEtaPhiVector(*constructor) + ) vec1 = getattr( vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates )() @@ -259,11 +295,14 @@ def test_truediv(constructor, scalar, coordinates): # Run a test that compares ROOT's '__eq__' with vector's 'isclose' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_eq(constructor, coordinates): - ref_vec = ROOT.Math.RhoEtaPhiVector(*constructor).__eq__(ROOT.Math.RhoEtaPhiVector(*constructor)) + ref_vec = ROOT.Math.RhoEtaPhiVector(*constructor).__eq__( + ROOT.Math.RhoEtaPhiVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates - )() + )().isclose( + getattr( + vector.obj(**dict(zip(["rho", "eta", "phi"], constructor))), coordinates + )() ) assert ref_vec == vec diff --git a/tests/root/test_RhoZPhiVector.py b/tests/root/test_RhoZPhiVector.py index c772cb55..7b491285 100644 --- a/tests/root/test_RhoZPhiVector.py +++ b/tests/root/test_RhoZPhiVector.py @@ -3,10 +3,10 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. -import pytest -from hypothesis import given, strategies as st - import numpy as np +import pytest +from hypothesis import given +from hypothesis import strategies as st import vector @@ -21,9 +21,9 @@ (1, 0, 0), (1, 10, 0), (1, -10, 0), - (1., 2.5, 2.), - (1, 2.5, 2.), - (1, -2.5, 2.), + (1.0, 2.5, 2.0), + (1, 2.5, 2.0), + (1, -2.5, 2.0), ] # Coordinate conversion methods to apply to the VectorObject2D. @@ -36,10 +36,12 @@ "to_xytheta", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -53,10 +55,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -65,38 +69,58 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Dot(constructor, coordinates): - assert ROOT.Math.RhoZPhiVector(*constructor).Dot(ROOT.Math.RhoZPhiVector(*constructor)) == pytest.approx( + assert ROOT.Math.RhoZPhiVector(*constructor).Dot( + ROOT.Math.RhoZPhiVector(*constructor) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates - )()) + )().dot( + getattr( + vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates + )() + ) ) # Run the same tests within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fuzz_Dot(constructor1, constructor2, coordinates): - assert ROOT.Math.RhoZPhiVector(*constructor1).Dot(ROOT.Math.RhoZPhiVector(*constructor2)) == pytest.approx( + assert ROOT.Math.RhoZPhiVector(*constructor1).Dot( + ROOT.Math.RhoZPhiVector(*constructor2) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["rho", "z", "phi"], constructor1))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["rho", "z", "phi"], constructor2))), coordinates - )()) + )().dot( + getattr( + vector.obj(**dict(zip(["rho", "z", "phi"], constructor2))), coordinates + )() + ) ) @@ -114,9 +138,11 @@ def test_Mag2(constructor, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_R(constructor, coordinates): assert ROOT.Math.RhoZPhiVector(*constructor).R() == pytest.approx( - np.sqrt(getattr( - vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates - )().rho2) + np.sqrt( + getattr( + vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates + )().rho2 + ) ) @@ -133,7 +159,7 @@ def test_Phi(constructor, coordinates): # Run a test that compares ROOT's 'RotateX()' with vector's 'rotateX' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateX(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationX(angle)*ROOT.Math.RhoZPhiVector(*constructor) + ref_vec = ROOT.Math.RotationX(angle) * ROOT.Math.RhoZPhiVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates )() @@ -146,7 +172,7 @@ def test_RotateX(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateY()' with vector's 'rotateY' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateY(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationY(angle)*ROOT.Math.RhoZPhiVector(*constructor) + ref_vec = ROOT.Math.RotationY(angle) * ROOT.Math.RhoZPhiVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates )() @@ -159,7 +185,7 @@ def test_RotateY(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateZ()' with vector's 'rotateZ' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateZ(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationZ(angle)*ROOT.Math.RhoZPhiVector(*constructor) + ref_vec = ROOT.Math.RotationZ(angle) * ROOT.Math.RhoZPhiVector(*constructor) vec = getattr( vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates )() @@ -188,17 +214,24 @@ def test_X_and_Y(constructor, coordinates): vec = getattr( vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates )() - assert (ROOT.Math.RhoZPhiVector(*constructor).X() == pytest.approx(vec.x) and - ROOT.Math.RhoZPhiVector(*constructor).Y() == pytest.approx(vec.y)) + assert ROOT.Math.RhoZPhiVector(*constructor).X() == pytest.approx( + vec.x + ) and ROOT.Math.RhoZPhiVector(*constructor).Y() == pytest.approx(vec.y) + # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): - ref_vec = ROOT.Math.RhoZPhiVector(*constructor).__add__(ROOT.Math.RhoZPhiVector(*constructor)) + ref_vec = ROOT.Math.RhoZPhiVector(*constructor).__add__( + ROOT.Math.RhoZPhiVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates)()) + )().add( + getattr( + vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates + )() + ) assert ref_vec.X() == pytest.approx(vec.x) assert ref_vec.Y() == pytest.approx(vec.y) assert ref_vec.Z() == pytest.approx(vec.z) @@ -207,7 +240,9 @@ def test_add(constructor, coordinates): # Run a test that compares ROOT's '__sub__' with vector's 'subtract' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): - ref_vec = ROOT.Math.RhoZPhiVector(*constructor).__sub__(ROOT.Math.RhoZPhiVector(*constructor)) + ref_vec = ROOT.Math.RhoZPhiVector(*constructor).__sub__( + ROOT.Math.RhoZPhiVector(*constructor) + ) vec1 = getattr( vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates )() @@ -259,11 +294,14 @@ def test_truediv(constructor, scalar, coordinates): # Run a test that compares ROOT's '__eq__' with vector's 'isclose' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_eq(constructor, coordinates): - ref_vec = ROOT.Math.RhoZPhiVector(*constructor).__eq__(ROOT.Math.RhoZPhiVector(*constructor)) + ref_vec = ROOT.Math.RhoZPhiVector(*constructor).__eq__( + ROOT.Math.RhoZPhiVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates - )() + )().isclose( + getattr( + vector.obj(**dict(zip(["rho", "z", "phi"], constructor))), coordinates + )() ) assert ref_vec == vec diff --git a/tests/root/test_XYVector.py b/tests/root/test_XYVector.py index a5114856..a84ff063 100644 --- a/tests/root/test_XYVector.py +++ b/tests/root/test_XYVector.py @@ -3,10 +3,10 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. -import pytest -from hypothesis import given, strategies as st - import numpy as np +import pytest +from hypothesis import given +from hypothesis import strategies as st import vector @@ -21,7 +21,7 @@ (1, 0), (1, 10), (1, -10), - (1., 2.5), + (1.0, 2.5), (1, 2.5), (1, -2.5), ] @@ -32,10 +32,12 @@ "to_rhophi", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -49,10 +51,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -61,38 +65,50 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Dot(constructor, coordinates): - assert ROOT.Math.XYVector(*constructor).Dot(ROOT.Math.XYVector(*constructor)) == pytest.approx( - getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )()) + assert ROOT.Math.XYVector(*constructor).Dot( + ROOT.Math.XYVector(*constructor) + ) == pytest.approx( + getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)().dot( + getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)() + ) ) # Run the same tests within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fuzz_Dot(constructor1, constructor2, coordinates): - assert ROOT.Math.XYVector(*constructor1).Dot(ROOT.Math.XYVector(*constructor2)) == pytest.approx( - getattr( - vector.obj(**dict(zip(["x", "y"], constructor1))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["x", "y"], constructor2))), coordinates - )()) + assert ROOT.Math.XYVector(*constructor1).Dot( + ROOT.Math.XYVector(*constructor2) + ) == pytest.approx( + getattr(vector.obj(**dict(zip(["x", "y"], constructor1))), coordinates)().dot( + getattr(vector.obj(**dict(zip(["x", "y"], constructor2))), coordinates)() + ) ) @@ -100,9 +116,7 @@ def test_fuzz_Dot(constructor1, constructor2, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_Mag2(constructor, coordinates): assert ROOT.Math.XYVector(*constructor).Mag2() == pytest.approx( - getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )().rho2 + getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)().rho2 ) @@ -110,9 +124,11 @@ def test_Mag2(constructor, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_R(constructor, coordinates): assert ROOT.Math.XYVector(*constructor).R() == pytest.approx( - np.sqrt(getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )().rho2) + np.sqrt( + getattr( + vector.obj(**dict(zip(["x", "y"], constructor))), coordinates + )().rho2 + ) ) @@ -120,9 +136,7 @@ def test_R(constructor, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_Phi(constructor, coordinates): assert ROOT.Math.XYVector(*constructor).Phi() == pytest.approx( - getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )().phi + getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)().phi ) @@ -131,9 +145,7 @@ def test_Phi(constructor, coordinates): def test_Rotate(constructor, angle, coordinates): ref_vec = ROOT.Math.XYVector(*constructor) ref_vec.Rotate(angle) - vec = getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )() + vec = getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)() res_vec = vec.rotateZ(angle) assert ref_vec.X() == pytest.approx(res_vec.x) assert ref_vec.Y() == pytest.approx(res_vec.y) @@ -143,9 +155,7 @@ def test_Rotate(constructor, angle, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_Unit(constructor, coordinates): ref_vec = ROOT.Math.XYVector(*constructor).Unit() - vec = getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )() + vec = getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)() res_vec = vec.unit assert ref_vec.X() == pytest.approx(res_vec().x) assert ref_vec.Y() == pytest.approx(res_vec().y) @@ -154,20 +164,19 @@ def test_Unit(constructor, coordinates): # Run a test that compares ROOT's 'X()' and 'Y()' with vector's 'x' and 'y' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_X_and_Y(constructor, coordinates): - vec = getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )() - assert (ROOT.Math.XYVector(*constructor).X() == pytest.approx(vec.x) and - ROOT.Math.XYVector(*constructor).Y() == pytest.approx(vec.y)) + vec = getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)() + assert ROOT.Math.XYVector(*constructor).X() == pytest.approx( + vec.x + ) and ROOT.Math.XYVector(*constructor).Y() == pytest.approx(vec.y) + # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): ref_vec = ROOT.Math.XYVector(*constructor).__add__(ROOT.Math.XYVector(*constructor)) - vec = getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)()) + vec = getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)().add( + getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)() + ) assert ref_vec.X() == pytest.approx(vec.x) assert ref_vec.Y() == pytest.approx(vec.y) @@ -176,12 +185,8 @@ def test_add(constructor, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): ref_vec = ROOT.Math.XYVector(*constructor).__sub__(ROOT.Math.XYVector(*constructor)) - vec1 = getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )() - vec2 = getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )() + vec1 = getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)() + vec2 = getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)() res_vec = vec1.subtract(vec2) assert ref_vec.X() == pytest.approx(res_vec.x) assert ref_vec.Y() == pytest.approx(res_vec.y) @@ -226,8 +231,7 @@ def test_eq(constructor, coordinates): ref_vec = ROOT.Math.XYVector(*constructor).__eq__(ROOT.Math.XYVector(*constructor)) vec = getattr( vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["x", "y"], constructor))), coordinates - )() + )().isclose( + getattr(vector.obj(**dict(zip(["x", "y"], constructor))), coordinates)() ) assert ref_vec == vec diff --git a/tests/root/test_XYZVector.py b/tests/root/test_XYZVector.py index 66aa8612..7cd2880e 100644 --- a/tests/root/test_XYZVector.py +++ b/tests/root/test_XYZVector.py @@ -3,10 +3,10 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. -import pytest -from hypothesis import given, strategies as st - import numpy as np +import pytest +from hypothesis import given +from hypothesis import strategies as st import vector @@ -21,9 +21,9 @@ (1, 0, 0), (1, 10, 0), (1, -10, 0), - (1., 2.5, 2.), - (1, 2.5, 2.), - (1, -2.5, 2.), + (1.0, 2.5, 2.0), + (1, 2.5, 2.0), + (1, -2.5, 2.0), ] # Coordinate conversion methods to apply to the VectorObject2D. @@ -36,10 +36,12 @@ "to_xytheta", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + angle_list = [ 0, 0.0, @@ -53,10 +55,12 @@ def coordinates(request): -6.283185307179586, ] + @pytest.fixture(scope="module", params=angle_list) def angle(request): return request.param + scalar_list = [ 0, -1, @@ -65,38 +69,58 @@ def angle(request): -100000.0000, ] + @pytest.fixture(scope="module", params=scalar_list) def scalar(request): return request.param + # Run a test that compares ROOT's 'Dot()' with vector's 'dot' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_Dot(constructor, coordinates): - assert ROOT.Math.XYZVector(*constructor).Dot(ROOT.Math.XYZVector(*constructor)) == pytest.approx( + assert ROOT.Math.XYZVector(*constructor).Dot( + ROOT.Math.XYZVector(*constructor) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )()) + )().dot( + getattr( + vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates + )() + ) ) # Run the same tests within hypothesis -@given(constructor1=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7)), - constructor2=st.tuples(st.floats(min_value=-10e7, max_value=10e7), - st.floats(min_value=-10e7, max_value=10e7)) - | st.tuples(st.integers(min_value=-10e7, max_value=10e7), - st.integers(min_value=-10e7, max_value=10e7))) +@given( + constructor1=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), + constructor2=st.tuples( + st.floats(min_value=-10e7, max_value=10e7), + st.floats(min_value=-10e7, max_value=10e7), + ) + | st.tuples( + st.integers(min_value=-10e7, max_value=10e7), + st.integers(min_value=-10e7, max_value=10e7), + ), +) def test_fuzz_Dot(constructor1, constructor2, coordinates): - assert ROOT.Math.XYZVector(*constructor1).Dot(ROOT.Math.XYZVector(*constructor2)) == pytest.approx( + assert ROOT.Math.XYZVector(*constructor1).Dot( + ROOT.Math.XYZVector(*constructor2) + ) == pytest.approx( getattr( vector.obj(**dict(zip(["x", "y", "z"], constructor1))), coordinates - )().dot(getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor2))), coordinates - )()) + )().dot( + getattr( + vector.obj(**dict(zip(["x", "y", "z"], constructor2))), coordinates + )() + ) ) @@ -114,9 +138,11 @@ def test_Mag2(constructor, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_R(constructor, coordinates): assert ROOT.Math.XYZVector(*constructor).R() == pytest.approx( - np.sqrt(getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )().rho2) + np.sqrt( + getattr( + vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates + )().rho2 + ) ) @@ -133,10 +159,8 @@ def test_Phi(constructor, coordinates): # Run a test that compares ROOT's 'RotateX()' with vector's 'rotateX' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateX(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationX(angle)*ROOT.Math.XYZVector(*constructor) - vec = getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )() + ref_vec = ROOT.Math.RotationX(angle) * ROOT.Math.XYZVector(*constructor) + vec = getattr(vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)() res_vec = vec.rotateX(angle) assert ref_vec.X() == pytest.approx(res_vec.x) assert ref_vec.Y() == pytest.approx(res_vec.y) @@ -146,10 +170,8 @@ def test_RotateX(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateY()' with vector's 'rotateY' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateY(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationY(angle)*ROOT.Math.XYZVector(*constructor) - vec = getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )() + ref_vec = ROOT.Math.RotationY(angle) * ROOT.Math.XYZVector(*constructor) + vec = getattr(vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)() res_vec = vec.rotateY(angle) assert ref_vec.X() == pytest.approx(res_vec.x) assert ref_vec.Y() == pytest.approx(res_vec.y) @@ -159,10 +181,8 @@ def test_RotateY(constructor, angle, coordinates): # Run a test that compares ROOT's 'RotateZ()' with vector's 'rotateZ' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_RotateZ(constructor, angle, coordinates): - ref_vec = ROOT.Math.RotationZ(angle)*ROOT.Math.XYZVector(*constructor) - vec = getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )() + ref_vec = ROOT.Math.RotationZ(angle) * ROOT.Math.XYZVector(*constructor) + vec = getattr(vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)() res_vec = vec.rotateZ(angle) assert ref_vec.X() == pytest.approx(res_vec.x) assert ref_vec.Y() == pytest.approx(res_vec.y) @@ -173,9 +193,7 @@ def test_RotateZ(constructor, angle, coordinates): @pytest.mark.parametrize("constructor", constructor) def test_Unit(constructor, coordinates): ref_vec = ROOT.Math.XYZVector(*constructor).Unit() - vec = getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )() + vec = getattr(vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)() res_vec = vec.unit assert ref_vec.X() == pytest.approx(res_vec().x) assert ref_vec.Y() == pytest.approx(res_vec().y) @@ -185,20 +203,23 @@ def test_Unit(constructor, coordinates): # Run a test that compares ROOT's 'X()' and 'Y()' with vector's 'x' and 'y' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_X_and_Y(constructor, coordinates): - vec = getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )() - assert (ROOT.Math.XYZVector(*constructor).X() == pytest.approx(vec.x) and - ROOT.Math.XYZVector(*constructor).Y() == pytest.approx(vec.y)) + vec = getattr(vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)() + assert ROOT.Math.XYZVector(*constructor).X() == pytest.approx( + vec.x + ) and ROOT.Math.XYZVector(*constructor).Y() == pytest.approx(vec.y) + # Run a test that compares ROOT's '__add__' with vector's 'add' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_add(constructor, coordinates): - ref_vec = ROOT.Math.XYZVector(*constructor).__add__(ROOT.Math.XYZVector(*constructor)) + ref_vec = ROOT.Math.XYZVector(*constructor).__add__( + ROOT.Math.XYZVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )().add(getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)()) + )().add( + getattr(vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)() + ) assert ref_vec.X() == pytest.approx(vec.x) assert ref_vec.Y() == pytest.approx(vec.y) assert ref_vec.Z() == pytest.approx(vec.z) @@ -207,13 +228,11 @@ def test_add(constructor, coordinates): # Run a test that compares ROOT's '__sub__' with vector's 'subtract' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_sub(constructor, coordinates): - ref_vec = ROOT.Math.XYZVector(*constructor).__sub__(ROOT.Math.XYZVector(*constructor)) - vec1 = getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )() - vec2 = getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )() + ref_vec = ROOT.Math.XYZVector(*constructor).__sub__( + ROOT.Math.XYZVector(*constructor) + ) + vec1 = getattr(vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)() + vec2 = getattr(vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)() res_vec = vec1.subtract(vec2) assert ref_vec.X() == pytest.approx(res_vec.x) assert ref_vec.Y() == pytest.approx(res_vec.y) @@ -259,11 +278,12 @@ def test_truediv(constructor, scalar, coordinates): # Run a test that compares ROOT's '__eq__' with vector's 'isclose' for all cases. @pytest.mark.parametrize("constructor", constructor) def test_eq(constructor, coordinates): - ref_vec = ROOT.Math.XYZVector(*constructor).__eq__(ROOT.Math.XYZVector(*constructor)) + ref_vec = ROOT.Math.XYZVector(*constructor).__eq__( + ROOT.Math.XYZVector(*constructor) + ) vec = getattr( vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )().isclose(getattr( - vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates - )() + )().isclose( + getattr(vector.obj(**dict(zip(["x", "y", "z"], constructor))), coordinates)() ) assert ref_vec == vec diff --git a/tests/root/test_vector.py b/tests/root/test_vector.py index 28990045..6a20169f 100644 --- a/tests/root/test_vector.py +++ b/tests/root/test_vector.py @@ -1,10 +1,11 @@ # This test code was written by the `hypothesis.extra.ghostwriter` module # and is provided under the Creative Commons Zero public domain dedication. -import vector -from hypothesis import given, strategies as st - import pytest +from hypothesis import given +from hypothesis import strategies as st + +import vector # If ROOT is not available, skip these tests. ROOT = pytest.importorskip("ROOT") @@ -25,10 +26,12 @@ "to_rhophietatau", ] + @pytest.fixture(scope="module", params=coordinate_list) def coordinates(request): return request.param + constructor = [ (0, 0, 0, 0), (0, 0, 0, 10), @@ -40,6 +43,7 @@ def coordinates(request): (1, 2, 3, -2.5), ] + @pytest.mark.parametrize("constructor", constructor) def test_M2(constructor, coordinates): assert ROOT.Math.PxPyPzEVector(*constructor).M2() == pytest.approx( @@ -48,7 +52,11 @@ def test_M2(constructor, coordinates): )().tau2 ) -@given(constructor=st.tuples(st.floats(), st.floats(), st.floats(), st.floats()) | st.tuples(st.integers(), st.integers(), st.integers(), st.integers())) + +@given( + constructor=st.tuples(st.floats(), st.floats(), st.floats(), st.floats()) + | st.tuples(st.integers(), st.integers(), st.integers(), st.integers()) +) def test_fuzz_M2(constructor, coordinates): assert ROOT.Math.PxPyPzEVector(*constructor).M2() == pytest.approx( getattr( @@ -56,37 +64,62 @@ def test_fuzz_M2(constructor, coordinates): )().tau2 ) -@given(azimuthal=st.tuples(st.floats(), st.floats()) | st.tuples(st.integers(), st.integers())) + +@given( + azimuthal=st.tuples(st.floats(), st.floats()) + | st.tuples(st.integers(), st.integers()) +) def test_fuzz_MomentumObject2D(azimuthal): - vec = vector.MomentumObject2D(azimuthal=azimuthal) + vector.MomentumObject2D(azimuthal=azimuthal) -@given(azimuthal=st.tuples(st.floats(), st.floats()) | st.tuples(st.integers(), st.integers()), longitudinal=st.floats() | st.integers()) +@given( + azimuthal=st.tuples(st.floats(), st.floats()) + | st.tuples(st.integers(), st.integers()), + longitudinal=st.floats() | st.integers(), +) def test_fuzz_MomentumObject3D(azimuthal, longitudinal): - vec = vector.MomentumObject3D(azimuthal=azimuthal, longitudinal=longitudinal) + vector.MomentumObject3D(azimuthal=azimuthal, longitudinal=longitudinal) -@given(azimuthal=st.tuples(st.floats(), st.floats()) | st.tuples(st.integers(), st.integers()), longitudinal=st.floats() | st.integers(), temporal=st.floats() | st.integers()) +@given( + azimuthal=st.tuples(st.floats(), st.floats()) + | st.tuples(st.integers(), st.integers()), + longitudinal=st.floats() | st.integers(), + temporal=st.floats() | st.integers(), +) def test_fuzz_MomentumObject4D(azimuthal, longitudinal, temporal): - vec = vector.MomentumObject4D( + vector.MomentumObject4D( azimuthal=azimuthal, longitudinal=longitudinal, temporal=temporal ) -@given(azimuthal=st.tuples(st.floats(), st.floats()) | st.tuples(st.integers(), st.integers())) +@given( + azimuthal=st.tuples(st.floats(), st.floats()) + | st.tuples(st.integers(), st.integers()) +) def test_fuzz_VectorObject2D(azimuthal): vector.VectorObject2D(azimuthal=azimuthal) -@given(azimuthal=st.tuples(st.floats(), st.floats()) | st.tuples(st.integers(), st.integers()), longitudinal=st.floats() | st.integers()) +@given( + azimuthal=st.tuples(st.floats(), st.floats()) + | st.tuples(st.integers(), st.integers()), + longitudinal=st.floats() | st.integers(), +) def test_fuzz_VectorObject3D(azimuthal, longitudinal): - vec = vector.VectorObject3D(azimuthal=azimuthal, longitudinal=longitudinal) + vector.VectorObject3D(azimuthal=azimuthal, longitudinal=longitudinal) -@given(azimuthal=st.tuples(st.floats(), st.floats()) | st.tuples(st.integers(), st.integers()), longitudinal=st.floats() | st.integers(), temporal=st.floats() | st.integers()) +@given( + azimuthal=st.tuples(st.floats(), st.floats()) + | st.tuples(st.integers(), st.integers()), + longitudinal=st.floats() | st.integers(), + temporal=st.floats() | st.integers(), +) def test_fuzz_VectorObject4D(azimuthal, longitudinal, temporal): - vec = vector.VectorObject4D( + vector.VectorObject4D( azimuthal=azimuthal, longitudinal=longitudinal, temporal=temporal ) # assert (vector.obj(**dict(zip(["x", "y", "z", "t"], azimuthal[0], azimuthal[1], longitudinal, temporal)))).tau == 0 - #pytest.approx(ROOT.Math.PxPyPzEVector(azimuthal[0], azimuthal[1], longitudinal, temporal).M()) + # pytest.approx(ROOT.Math.PxPyPzEVector(azimuthal[0], azimuthal[1], longitudinal, temporal).M())