From cb3328635efd4be49f535487a172a7f675bcd85d Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Tue, 29 Jan 2019 09:33:50 -0500 Subject: [PATCH 1/7] Adding Avogadro Constant --- .../CustomCode/AmountOfSubstanceTests.cs | 17 +++++++ .../Quantities/AmountOfSubstance.extra.cs | 50 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs diff --git a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs index d284b7f023..3d655c3e84 100644 --- a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs +++ b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs @@ -39,6 +39,7 @@ // THE SOFTWARE. using System; +using Xunit; namespace UnitsNet.Tests.CustomCode { @@ -59,5 +60,21 @@ public class AmountOfSubstanceTests : AmountOfSubstanceTestsBase protected override double NanopoundMolesInOneMole => 0.002204622621848776 * 1e9; protected override double PoundMolesInOneMole => 0.002204622621848776; protected override double MegamolesInOneMole => 1e-6; + + [Fact] + public void NumberOfParticlesInOneMoleEqualsAvogadroConstant() + { + var oneMole = AmountOfSubstance.FromMoles(1); + var numberOfParticles = oneMole.NumberOfParticles(); + Assert.Equal(AmountOfSubstance.AvogadroConstant, numberOfParticles); + } + + [Fact] + public void NumberOfParticlesInTwoMolesIsDoubleAvogadroConstant() + { + var oneMole = AmountOfSubstance.FromMoles(2); + var numberOfParticles = oneMole.NumberOfParticles(); + Assert.Equal(AmountOfSubstance.AvogadroConstant * 2, numberOfParticles); + } } } diff --git a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs new file mode 100644 index 0000000000..0f96bc75b3 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs @@ -0,0 +1,50 @@ +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// ReSharper disable once CheckNamespace + +using System; +using UnitsNet.Units; + +namespace UnitsNet +{ + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class AmountOfSubstance +#else + public partial struct AmountOfSubstance +#endif + { + public const double AvogadroConstant = 6.02214076e23; + + /// + /// Calculates the number of particles (atoms or molecules) in this amount of substance using the . + /// + /// The number of particles (atoms or molecules) in this amount of substance. + public double NumberOfParticles() + { + var moles = AsBaseNumericType(AmountOfSubstanceUnit.Mole); + return AvogadroConstant * moles; + } + } +} From d90a58cc579d39726d67e4a5b60f758460e885d1 Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Tue, 29 Jan 2019 09:50:04 -0500 Subject: [PATCH 2/7] Making AvogadroConstant a static readonly property for WRC --- UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs index 0f96bc75b3..91a05800e2 100644 --- a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs +++ b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs @@ -35,7 +35,7 @@ public sealed partial class AmountOfSubstance public partial struct AmountOfSubstance #endif { - public const double AvogadroConstant = 6.02214076e23; + public static double AvogadroConstant { get; } = 6.02214076e23; /// /// Calculates the number of particles (atoms or molecules) in this amount of substance using the . From a428c75b0bea8d4d3747047f873448b5eda36327 Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Mon, 18 Feb 2019 14:05:43 -0500 Subject: [PATCH 3/7] Removing WRC checks after WRC split --- UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs index 91a05800e2..af4b052336 100644 --- a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs +++ b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs @@ -21,19 +21,11 @@ // ReSharper disable once CheckNamespace -using System; using UnitsNet.Units; namespace UnitsNet { - // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components - // Public structures can't have any members other than public fields, and those fields must be value types or strings. - // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. -#if WINDOWS_UWP - public sealed partial class AmountOfSubstance -#else public partial struct AmountOfSubstance -#endif { public static double AvogadroConstant { get; } = 6.02214076e23; From ff6c9fb13d82dd75bbd87557b3e099b60e069684 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sat, 23 Feb 2019 22:26:55 +0100 Subject: [PATCH 4/7] Rename to twoMoles --- UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs index 3d655c3e84..088f3f3810 100644 --- a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs +++ b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs @@ -72,8 +72,8 @@ public void NumberOfParticlesInOneMoleEqualsAvogadroConstant() [Fact] public void NumberOfParticlesInTwoMolesIsDoubleAvogadroConstant() { - var oneMole = AmountOfSubstance.FromMoles(2); - var numberOfParticles = oneMole.NumberOfParticles(); + var twoMoles = AmountOfSubstance.FromMoles(2); + var numberOfParticles = twoMoles.NumberOfParticles(); Assert.Equal(AmountOfSubstance.AvogadroConstant * 2, numberOfParticles); } } From d72abbe6df3791435fd5f9e4585d4f060be27f08 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sat, 23 Feb 2019 22:36:47 +0100 Subject: [PATCH 5/7] Add xmldoc --- UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs index af4b052336..bc2c426357 100644 --- a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs +++ b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs @@ -27,6 +27,11 @@ namespace UnitsNet { public partial struct AmountOfSubstance { + /// + /// The Avogadro constant is the number of constituent particles, usually molecules, + /// atoms or ions that are contained in the amount of substance given by one mole. It is the proportionality factor that relates + /// the molar mass of a substance to the mass of a sample, is designated with the symbol NA or L[1], and has the value + /// 6.02214085774e23 mol−1 in the International System of Units (SI). public static double AvogadroConstant { get; } = 6.02214076e23; /// From 9463a059dedb9fe3d3b0e76198f2b963d10fc5b4 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sat, 23 Feb 2019 22:39:59 +0100 Subject: [PATCH 6/7] Add closing summary tag in xmldoc --- UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs index bc2c426357..f832264de4 100644 --- a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs +++ b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs @@ -32,6 +32,7 @@ public partial struct AmountOfSubstance /// atoms or ions that are contained in the amount of substance given by one mole. It is the proportionality factor that relates /// the molar mass of a substance to the mass of a sample, is designated with the symbol NA or L[1], and has the value /// 6.02214085774e23 mol−1 in the International System of Units (SI). + /// public static double AvogadroConstant { get; } = 6.02214076e23; /// From a9ce56dd12efbccc163896ca9779adea11ce563f Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Mon, 25 Feb 2019 15:24:17 -0500 Subject: [PATCH 7/7] Add doc --- .../CustomCode/Quantities/AmountOfSubstance.extra.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs index f832264de4..a4e1de64f8 100644 --- a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs +++ b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs @@ -31,8 +31,15 @@ public partial struct AmountOfSubstance /// The Avogadro constant is the number of constituent particles, usually molecules, /// atoms or ions that are contained in the amount of substance given by one mole. It is the proportionality factor that relates /// the molar mass of a substance to the mass of a sample, is designated with the symbol NA or L[1], and has the value - /// 6.02214085774e23 mol−1 in the International System of Units (SI). + /// 6.02214076e23 mol−1 in the International System of Units (SI). /// + /// + /// Pending revisions in the base set of SI units necessitated redefinitions of the concepts of chemical quantity. The Avogadro number, + /// and its definition, was deprecated in favor of the Avogadro constant and its definition. Based on measurements made through the + /// middle of 2017 which calculated a value for the Avogadro constant of NA = 6.022140758(62)×1023 mol−1, the redefinition of SI units + /// is planned to take effect on 20 May 2019. The value of the constant will be fixed to exactly 6.02214076×1023 mol−1. + /// See here: https://www.bipm.org/utils/common/pdf/CGPM-2018/26th-CGPM-Resolutions.pdf + /// public static double AvogadroConstant { get; } = 6.02214076e23; ///