Skip to content

Commit

Permalink
tests: added utility functions for model testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MothNik committed May 10, 2024
1 parent a8ecb7d commit 365c5dd
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/test_for_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,76 @@

### Imports ###

from dataclasses import dataclass
from math import isnan
from typing import Tuple

import numpy as np
from scipy.linalg import eigvals_banded
from scipy.sparse import csr_matrix
from scipy.sparse import diags as sp_diags

from chemotools.utils.models import WhittakerSmoothMethods

### Dataclasses ###


@dataclass
class ExpectedWhittakerSmoothLambda:
"""
Dataclass for checking the expected results for the class :class:`WhittakerSmoothLambda`
from the module :mod:`chemotools.utils.models`.
""" # noqa: E501

fixed_lambda: float
auto_bounds: Tuple[float, float]
fit_auto: bool
method_used: WhittakerSmoothMethods
log_auto_bounds: Tuple[float, float] = (0.0, 0.0)


### Utility Functions ###


def float_is_bit_equal(value: float, reference: float) -> bool:
"""
Checks if two floating-point numbers are equal up to the last bit and handles the
case of NaN values as well.
Doctests
--------
>>> # Imports
>>> from tests.test_for_utils.utils import float_is_bit_equal
>>> # Test 1
>>> float_is_bit_equal(value=1.0, reference=1.0)
True
>>> # Test 2
>>> float_is_bit_equal(value=1.0, reference=10.0)
False
>>> # Test 3
>>> float_is_bit_equal(value=1.0, reference=float("nan"))
False
>>> # Test 4
>>> float_is_bit_equal(value=float("nan"), reference=float("nan"))
True
>>> # Test 5
>>> float_is_bit_equal(value=float("nan"), reference=1.0)
False
"""

if isnan(reference):
return isnan(value)

return value == reference


def conv_upper_cho_banded_storage_to_sparse(
ab: np.ndarray,
) -> csr_matrix:
Expand Down

0 comments on commit 365c5dd

Please sign in to comment.