Skip to content

Commit

Permalink
tests that wrapper rise error if invalid args
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeZ committed Jul 6, 2020
1 parent ad37fda commit 8915efb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyspectra/pyspectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def eigensolver(


def eigensolverh(
mat: np.ndarray, nvalues: int, selection_rule: str,
mat: np.ndarray, nvalues: int, selection_rule: Optional[str] = None,
search_space: Optional[int] = None, generalized: np.ndarray = None,
shift: Optional[Union[np.float, np.complex]] = None) -> EigenPair:
"""Compute ``nvalues`` eigenvalues for the symmetric matrix ``mat``.
Expand Down
20 changes: 19 additions & 1 deletion tests/test_pyspectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Callable, List, Optional, Tuple, TypeVar, Union

import numpy as np
import pytest

from pyspectra import eigensolver, eigensolverh

Expand Down Expand Up @@ -84,4 +85,21 @@ def test_eigensolverh():

print(f"default search space and shift = {SIGMA.real}")
run_test(eigensolverh, mat, nvalues, rules,
search_space=None, shift=SIGMA.real)
search_space=None, shift=SIGMA.real)


def test_invalid_argument():
"""Check that an error is raised if the arguments are invalid."""
mat = create_symmetic_matrix(SIZE)
nvalues = 2
print("wrong name for selection rule")
with pytest.raises(RuntimeError):
eigensolverh(mat, nvalues, selection_rule="Boom")

print("more eigenpairs requested than columns")
with pytest.raises(RuntimeError):
eigensolverh(mat, SIZE + 1)

print("Shift is not an scalar")
with pytest.raises(RuntimeError):
eigensolverh(mat, nvalues, shift="1.0")

0 comments on commit 8915efb

Please sign in to comment.