Пример #1
0
class TestNumpyXMatrix:
    @given(data(), shape_matrix())
    def test_input_as_tuples(self, data, shape):
        X = data.draw(numpy_X_matrices(shape))
        assert X.shape == shape

    @given(data())
    def test_input_as_strategy(self, data):
        data.draw(numpy_X_matrices(shape_matrix()))

    @given(data())
    def test_error_shape_0_smaller_shape_1(self, data):
        with pytest.raises(ValueError):
            data.draw(numpy_X_matrices([10, 20]))

    @given(data(), shape_matrix(), ordered_pair(32, 47))
    def test_min_max_values(self, data, shape, min_max_values):
        min_value, max_value = min_max_values
        X = data.draw(numpy_X_matrices(shape, min_value=min_value, max_value=max_value))
        assert X.min() >= min_value
        assert X.max() <= max_value

    @given(data(), shape_matrix())
    def test_no_nan(self, data, shape):
        X = data.draw(numpy_X_matrices(shape, allow_nan=False, allow_infinity=True))
        assert not np.isnan(X).any()

    @given(data(), shape_matrix())
    def test_no_infinity(self, data, shape):
        X = data.draw(numpy_X_matrices(shape, allow_nan=True, allow_infinity=False))
        assert not np.isinf(X).any()
Пример #2
0
class TestNumpyXyMatrices:
    @given(data(), shape_X_y_matrices())
    def test_input_as_tuples(self, data, shape_X_y):
        X, y = data.draw(numpy_X_y_matrices(shape_X_y))
        assert X.shape == shape_X_y[0]
        assert y.shape == shape_X_y[1]
        assert len(y.shape) == 1

    @given(data(), shape_X_y_matrices(y_as_vector=False))
    def test_input_as_tuples_y_matrix(self, data, shape_X_y):
        X, y = data.draw(numpy_X_y_matrices(shape_X_y))
        assert X.shape == shape_X_y[0]
        assert y.shape == shape_X_y[1]
        assert len(y.shape) == 2

    @given(data())
    def test_input_as_strategy(self, data):
        data.draw(numpy_X_y_matrices(shape_X_y_matrices()))

    @given(data())
    def test_error_shape_0_smaller_shape_1(self, data):
        with pytest.raises(ValueError):
            data.draw(numpy_X_y_matrices([[10, 20], [10, 1]]))

    @given(data())
    def test_error_shape_0_different(self, data):
        with pytest.raises(ValueError):
            data.draw(numpy_X_y_matrices([[10, 5], [4, 1]]))

    @given(data(), shape_X_y_matrices(), ordered_pair(32, 47))
    def test_min_max_values(self, data, shape_X_y, min_max_values):
        min_value, max_value = min_max_values
        X, y = data.draw(
            numpy_X_y_matrices(shape_X_y, min_value=min_value, max_value=max_value)
        )
        assert X.min() >= min_value
        assert y.min() >= min_value
        assert X.max() <= max_value
        assert y.max() <= max_value

    @given(data(), shape_X_y_matrices())
    def test_no_nan(self, data, shape_X_y):
        X, y = data.draw(
            numpy_X_y_matrices(shape_X_y, allow_nan=False, allow_infinity=True)
        )
        assert not np.isnan(X).any()
        assert not np.isnan(y).any()

    @given(data(), shape_X_y_matrices())
    def test_no_infinity(self, data, shape_X_y):
        X, y = data.draw(
            numpy_X_y_matrices(shape_X_y, allow_nan=True, allow_infinity=False)
        )
        assert not np.isinf(X).any()
        assert not np.isinf(y).any()
Пример #3
0
def test_ordered_pair_min_equal_max(data, value):
    with pytest.raises(ValueError):
        data.draw(ordered_pair(value, value))
Пример #4
0
from typing import Tuple

import pytest
from hypothesis import given
from hypothesis.strategies import integers, data

from gtime.utils.hypothesis.general_strategies import (
    ordered_pair,
    shape_matrix,
    shape_X_y_matrices,
)


@given(ordered_pair(0, 10))
def test_ordered_pair(pair: Tuple[int, int]):
    assert pair[0] < pair[1]


@given(ordered_pair(27, 132))
def test_ordered_pair_values(pair: Tuple[int, int]):
    assert pair[0] >= 27
    assert pair[1] <= 132


@given(data=data(), value=integers(0, 10))
def test_ordered_pair_min_equal_max(data, value):
    with pytest.raises(ValueError):
        data.draw(ordered_pair(value, value))


@given(data=data(), shape_0=ordered_pair(10, 100), shape_1=ordered_pair(1, 8))