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

Add concentration units (mixtures/solutions) #646

Merged
merged 10 commits into from
Apr 21, 2019
Merged

Add concentration units (mixtures/solutions) #646

merged 10 commits into from
Apr 21, 2019

Conversation

lipchev
Copy link
Collaborator

@lipchev lipchev commented Apr 3, 2019

Added the following Concentration Units:

Modified the existing Molarity unit (AKA Molar Concentration):

  • Some operations that were originally based on the Density units now use the MassConcentration units instead (Note: despite the fact that they share the same measurement units- the Density is a distinct Quantity Type from the Mass Concentration)
  • Marked all operators involving Molarity from Density as Obsolete

Defined some basic operations that were missing from the AmountOfSubstance/MolarMass/Mass units

Defined the triangular operations involving Mass/Molar/Volume concentrations (using the solute's Density and/or Molar Mass)

All unit tests included, most were defined by actual chemists (which I AM NOT).
Note: one of the tests (QuantityIFormattableTests.VFormatEqualsValueToString)- was failing on my machine- it passes if I add CultureInfo.CurrentUICulture to the value.ToString() - as I presume was the intended behavior

Added the following Concentration Units:
- MassConcentration: SI = kg/m3, typically mg/l
- VolumeConcentration : dimensionless, typically %
- MassFraction: SI = kg/kg, typically mg/kg

Modified the existing Molarity unit:
- Some operations that were originally based on the Density units now use the MassConcentration units instead (Note: despite the fact that they share the same measurement units- the Density is a distnct QuantyType from the MassConcentration)
- Removed all operators involving Molarity from the Density units

Defined some basic operations that were missing from the AmountOfSubstance/MolarMass/Mass units

Defined the triangular operations involving Mass/Molar/Volume concentrations (& the corresponding component's Density & MolarMass)

All unit tests included most were defined by actual chemists(which I AM NOT).
Note: one of the tests (QuantityIFormattableTests.VFormatEqualsValueToString)- was failing on my machine- it passes if I add CultureInfo.CurrentUICulture to the value.ToString() - as I presume was the intended behavior
@angularsen
Copy link
Owner

angularsen commented Apr 10, 2019

Thanks for contributing, I'm a bit busy these days but me or @tmilnthorp will get around to review it soon.

Copy link
Owner

@angularsen angularsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the JSON files now, leaving the rest for now until we conclude on some discussions first.
Awesome job by the way! Pretty much perfectly following the conventions.

The only thing I would advise you for next time is to do smaller pull requests. It will take much less time to review and complete in smaller chunks :-)

Common/UnitDefinitions/MassConcentration.json Outdated Show resolved Hide resolved
Common/UnitDefinitions/MassConcentration.json Outdated Show resolved Hide resolved
Common/UnitDefinitions/MassConcentration.json Outdated Show resolved Hide resolved
Common/UnitDefinitions/MassConcentration.json Outdated Show resolved Hide resolved
Common/UnitDefinitions/MassConcentration.json Show resolved Hide resolved
Common/UnitDefinitions/MassFraction.json Show resolved Hide resolved
Common/UnitDefinitions/Molarity.json Outdated Show resolved Hide resolved
lipchev added 2 commits April 13, 2019 07:38
- updated liter abbreviations for g/l, g/dl, g/ml & kg/l to uppercase 'L'  (TODO Density?)
- added base units to all units in MassConcentration & Molarity (TODO Density?)
Common/UnitDefinitions/MassConcentration.json Outdated Show resolved Hide resolved
Common/UnitDefinitions/MassConcentration.json Outdated Show resolved Hide resolved
Common/UnitDefinitions/MassConcentration.json Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MassFractionTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MolarMassTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MolarMassTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MolarityTests.cs Outdated Show resolved Hide resolved
Common/UnitDefinitions/MassFraction.json Show resolved Hide resolved
Copy link
Owner

@angularsen angularsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get through it all, but most of it. Please see my feedback.

UnitsNet.Tests/CustomCode/MolarityTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MolarityTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MolarityTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MolarityTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MolarMassTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/QuantityIFormattableTests.cs Show resolved Hide resolved
UnitsNet/CustomCode/Quantities/Density.extra.cs Outdated Show resolved Hide resolved
lipchev added 2 commits April 15, 2019 00:15
- corrected the BaseUnits for MassConcentration
- marked the invalid methods from Molarity/Density as Obsolete (were previously omitted)
- some cosmetic changes to the Unit Tests
- MolesPerLiter: fixed the BaseUnits (default) to Deimeter/Mole
- Molar: removed in favor of using the alternative abbreviation 'M"
- MolarityTests - OneMilliMolarFromStringParsedCorrectly skipped while awaiting fix for #344
lipchev added 3 commits April 16, 2019 00:55
- added a KnownQuantities class with a few constants that were used in multiple tests
- replaced the usages in MassConcentrationTests MolarityTests * VolumeConcentrationTests
- converted two of the MassConcentration tests to using Theory + InlineData
Copy link
Owner

@angularsen angularsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nearing done now, just some comments for you to look over.
Mostly it is about naming conventions and structuring tests to communicate better what they are testing.

Common/UnitDefinitions/MassConcentration.json Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MassConcentrationTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MassConcentrationTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MassConcentrationTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MassConcentrationTests.cs Outdated Show resolved Hide resolved
UnitsNet.Tests/CustomCode/MolarMassTests.cs Outdated Show resolved Hide resolved
- removed BaseUnits from GramPerDeciliter(not exact + overlap), kept it in GramPerLiter (as exact & non-overlapping), also kept it for GramPerMilliliter(exact + overlapping) because I thought it would be useful to have at least one such case for future testing
- moved the Mass/MolarMass operator to the Mass class (removing the MolarMass.extra)
- all tests refactored using Theory + Inline Data
- moved one or two tests to the appropriate .Test file
- removed a few redundant tests
@angularsen
Copy link
Owner

Very nice, I'm at the cabin this weekend and may not have the opportunity to look at this before Sunday.

Copy link
Owner

@angularsen angularsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good now, thanks a lot for the effort!

[Fact]
public void HClSolutionVolumeIsEqualToExpected()
[Theory]
[InlineData(5, MassUnit.Gram,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, this is fine, but I didn't mean that [InlineData] was my preferred method of testing. Only that the values would be inlined/inserted into the test code itself, so that you can read all the numbers that go into the calculation for each test method rather than reusing fields. [Fact] is probably more "correct" than [Theory] + [InlineData] if there is only one test case. If you have multiple test cases/inputs, then [InlineData] is a good fit.

At any rate, this works and I'm not going to bother you to change it again.

@angularsen angularsen merged commit b834a1c into angularsen:master Apr 21, 2019
@angularsen angularsen changed the title Concentration Units (mixtures/solutions) Add concentration units (mixtures/solutions) Apr 21, 2019
@angularsen
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants