Exemple #1
0
def test_known_values():
    """Run a few tests with known answers to ensure
    calculate_G_on_W_m2() is giving the expected output.

    These known values are estimated from Duffie & Beckman (2006) Figure 1.4.1.
    """
    assert calculate_G_on_W_m2(B_degrees=calculate_B_degrees(1),
                               G_sc=1_367) == pytest.approx(1_414.9134)
    assert calculate_G_on_W_m2(B_degrees=calculate_B_degrees(180),
                               G_sc=1_367) == pytest.approx(1_321.5236)
Exemple #2
0
def test_invalid_range():
    """Test to ensure a ValueError is raised when a value
    outside the specified range is provided to
    calculate_B_degrees()."""
    with pytest.raises(ValueError):
        # Test with too-low value
        assert calculate_B_degrees(day_number=-10)
    with pytest.raises(ValueError):
        # Test with too-high value
        assert calculate_B_degrees(day_number=1_000)
def test_known_values():
    """Run a few tests with known answers to ensure
    calculate_E_min() is giving the expected output.

    These known values are taken from:
    1) Duffie & Beckman (2006) Example 1.5.1, and
    2) Estimated from Duffie & Beckman (2006) Figure 1.5.1
    """
    assert calculate_E_min(
        B_degrees=calculate_B_degrees(day_number=34)
    ) == pytest.approx(-13.488457)
    assert calculate_E_min(
        B_degrees=calculate_B_degrees(day_number=304)
    ) == pytest.approx(16.37505)
def test_known_values():
    """Run a few tests with known answers to ensure
    calculate_declination_degrees() is giving the expected output.

    These known values are taken from Duffie & Beckman (2006)
    Table 1.6.1.
    """
    assert calculate_declination_degrees(
        B_degrees=calculate_B_degrees(day_number=17)
    ) == pytest.approx(-20.903603)
    assert calculate_declination_degrees(
        B_degrees=calculate_B_degrees(day_number=105)
    ) == pytest.approx(9.480771)
    assert calculate_declination_degrees(
        B_degrees=calculate_B_degrees(day_number=288)
    ) == pytest.approx(-8.217747)
Exemple #5
0
def test_invalid_type():
    """Test to ensure a TypeError or ValueError is raised
    when an invalid value is provided to calculate_B_degrees()."""
    with pytest.raises(TypeError):
        # Test with float value
        assert calculate_B_degrees(day_number=123.5)
    with pytest.raises(ValueError):
        # Test with NaN value
        assert calculate_B_degrees(day_number=nan)
    with pytest.raises(ValueError):
        # Test with infinite value
        assert calculate_B_degrees(day_number=inf)
    with pytest.raises(TypeError):
        # Test with string value
        assert calculate_B_degrees(day_number="blah")
    with pytest.raises(TypeError):
        # Test with datetime object
        assert calculate_B_degrees(day_number=datetime(2020, 1, 1))
import numpy as np
import pytest
from hypothesis import given
from hypothesis.strategies import floats

from pysoleng.solar_geom import (
    calculate_B_degrees,
    calculate_declination_degrees,
)


@pytest.mark.solar_geom
@given(
    floats(
        min_value=calculate_B_degrees(1),
        max_value=calculate_B_degrees(366),
        allow_nan=False,
        allow_infinity=False,
        exclude_min=True,
        exclude_max=True,
    )
)
def test_calculate_declination_degrees(B):
    """Functional test to ensure the calculate_declination_degrees() method
    runs properly given a valid argument."""
    assert isinstance(calculate_declination_degrees(B_degrees=B), float)


@pytest.mark.solar_geom
def test_calculate_declination_degrees_iterable():
Exemple #7
0
def test_known_values():
    """Run a few tests with known answers to ensure
    calculate_B_degrees() is giving the expected output."""
    assert calculate_B_degrees(day_number=1) == 0
    assert calculate_B_degrees(day_number=74) == 72
    assert calculate_B_degrees(day_number=366) == 360
Exemple #8
0
def test_calculate_B_degrees_iterable():
    """Functional test to ensure the calculate_B_degrees() method
    runs properly on integer iterables in the correct range."""
    assert isinstance(calculate_B_degrees(day_number=[1, 10, 20]), np.ndarray)
Exemple #9
0
def test_calculate_B_degrees(value):
    """Functional test to ensure the calculate_B_degrees() method
    runs properly on integer values in the correct range."""
    assert isinstance(calculate_B_degrees(day_number=value), float)