uncscode / particula

a simple, fast, and powerful particle simulator
https://uncscode.github.io/particula
MIT License
6 stars 9 forks source link

Expand testing of species #479

Open Gorkowski opened 1 month ago

Gorkowski commented 1 month ago

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 commented 1 month ago

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])