Skip to content

Commit

Permalink
927 Update tests for seed functions
Browse files Browse the repository at this point in the history
#927

[author: carhc]

This PR updates some tests in
`invisible_cities/reco/krmap_functions_test.py` of PR 872.

[reviewer: gonzaponte]

Perfect! Good job.
  • Loading branch information
gonzaponte authored and jwaiton committed Jan 7, 2025
2 parents a15daa4 + 1e855da commit e8ce81d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions invisible_cities/reco/krmap_functions_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest

import numpy as np
import numpy.testing as npt
import pandas as pd
import scipy.optimize as so

from pytest import raises
from pytest import fixture, mark
from hypothesis import given, settings
from hypothesis.strategies import floats, integers

Expand All @@ -18,7 +18,7 @@
floats(min_value = 10, max_value = 20),
floats(min_value = 1, max_value = 100),
floats(min_value = 0, max_value = 10))
def test_lin_function_output_values(x_min, x_max, a, b):
def test_lin_seed_output_values(x_min, x_max, a, b):
x = np.array([x_min, x_max])
y = a + b * x
a_test, b_test = krf.lin_seed(x, y)
Expand All @@ -27,6 +27,15 @@ def test_lin_function_output_values(x_min, x_max, a, b):
assert np.isclose(b_test, b)


def test_lin_seed_same_x_values():
x = np.ones(20)
y = np.ones(20) * 123
a_test, b_test = krf.lin_seed(x, y)

assert a_test == 123
assert b_test == 0


@given(floats(min_value = 1, max_value = 10),
floats(min_value = 1000, max_value = 1600),
floats(min_value = 1e4, max_value = 1e5),
Expand All @@ -40,7 +49,14 @@ def test_expo_seed_output_values(zmin, zmax, elt, e0):
assert np.isclose(elt_test, elt, rtol=0.1)


@pytest.fixture
@mark.parametrize('y', ([-1, 1, 1, 1, 1], [1, 1, 1, 1, -1]))
def test_expo_seed_negative_y_values(y):
x = np.ones(5)
with raises(ValueError, match = 'y data must be > 0'):
a_test, b_test = krf.expo_seed(x, y)


@fixture
def sample_df():
data = {'DT' : [10, 20, 30, 40, 50],
'S2e': [50, 45, 42, 41, 41]}
Expand Down

0 comments on commit e8ce81d

Please sign in to comment.