Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand testing of species #479

Open
Gorkowski opened this issue Oct 4, 2024 · 1 comment
Open

Expand testing of species #479

Gorkowski opened this issue Oct 4, 2024 · 1 comment
Labels
sourcery-ai sourcery-ai

Comments

@Gorkowski
Copy link
Collaborator

suggestion (testing): Add edge case tests for GasSpecies

Consider adding tests for edge cases, such as creating a GasSpecies with extreme values (very large or very small) for molar mass or concentration. Also, test the behavior when invalid inputs are provided.

def test_gas_species_builder_single_species():
"""Test building a single gas species with the GasSpeciesBuilder."""
vapor_pressure_strategy = ConstantVaporPressureStrategy(vapor_pressure=101325)
name = "Oxygen"
molar_mass = 0.032 # kg/mol
condensable = False
concentration = 1.2 # kg/m^3

gas_species = GasSpecies(
    name=name,
    molar_mass=molar_mass,
    vapor_pressure_strategy=vapor_pressure_strategy,
    condensable=condensable,
    concentration=concentration
)

assert gas_species.name == name
assert gas_species.get_molar_mass() == molar_mass
assert gas_species.get_condensable() is condensable
assert gas_species.get_concentration() == concentration
assert gas_species.get_pure_vapor_pressure(298) == 101325

def test_gas_species_builder_edge_cases():
"""Test edge cases for GasSpecies creation."""
with pytest.raises(ValueError):
GasSpecies(name="Invalid", molar_mass=-1, vapor_pressure_strategy=None, condensable=True, concentration=0)

large_mass_species = GasSpecies(name="Heavy", molar_mass=1e10, vapor_pressure_strategy=None, condensable=False, concentration=1e-10)
assert large_mass_species.get_molar_mass() == 1e10
assert large_mass_species.get_concentration() == 1e-10
@Gorkowski
Copy link
Collaborator Author

suggestion (testing): Add test for mismatched array lengths

Add a test case where the input arrays (names, molar_masses, etc.) have different lengths to ensure the GasSpecies class handles this scenario correctly, either by raising an appropriate exception or handling it gracefully.

def test_gas_species_builder_array_species():
"""Test building an array of gas species with the GasSpeciesBuilder."""
vapor_pressure_strategy = ConstantVaporPressureStrategy(
vapor_pressure=np.array([101325, 101325]))
names = np.array(["Oxygen", "Nitrogen"])
molar_masses = np.array([0.032, 0.028]) # kg/mol
condensables = np.array([False, False])
concentrations = np.array([1.2, 0.8]) # kg/m^3

gas_species = GasSpecies(
    name=names,
    molar_mass=molar_masses,
    vapor_pressure_strategy=vapor_pressure_strategy,
    condensable=condensables,
    concentration=concentrations
)

assert np.array_equal(gas_species.name, names)
assert np.array_equal(gas_species.get_molar_mass(), molar_masses)
assert np.array_equal(gas_species.get_condensable(), condensables)
assert np.array_equal(gas_species.get_concentration(), concentrations)
assert np.array_equal(gas_species.get_pure_vapor_pressure(
    np.array([298, 300])), np.array([101325, 101325]))

def test_gas_species_builder_mismatched_arrays():
"""Test handling of mismatched array lengths in GasSpecies."""
with pytest.raises(ValueError):
GasSpecies(
name=np.array(["Oxygen", "Nitrogen"]),
molar_mass=np.array([0.032, 0.028, 0.044]),
vapor_pressure_strategy=ConstantVaporPressureStrategy(
vapor_pressure=np.array([101325, 101325])),
condensable=np.array([False, False]),
concentration=np.array([1.2, 0.8])

@mahf708 mahf708 added the sourcery-ai sourcery-ai label Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sourcery-ai sourcery-ai
Projects
None yet
Development

No branches or pull requests

2 participants