Skip to content

Commit 465b254

Browse files
tmilnthorpangularsen
authored andcommitted
Add AmountOfSubstance.AvogadroConstant (#593)
1 parent 5454102 commit 465b254

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
2222

2323
using System;
24+
using Xunit;
2425

2526
namespace UnitsNet.Tests.CustomCode
2627
{
@@ -41,5 +42,21 @@ public class AmountOfSubstanceTests : AmountOfSubstanceTestsBase
4142
protected override double NanopoundMolesInOneMole => 0.002204622621848776 * 1e9;
4243
protected override double PoundMolesInOneMole => 0.002204622621848776;
4344
protected override double MegamolesInOneMole => 1e-6;
45+
46+
[Fact]
47+
public void NumberOfParticlesInOneMoleEqualsAvogadroConstant()
48+
{
49+
var oneMole = AmountOfSubstance.FromMoles(1);
50+
var numberOfParticles = oneMole.NumberOfParticles();
51+
Assert.Equal(AmountOfSubstance.AvogadroConstant, numberOfParticles);
52+
}
53+
54+
[Fact]
55+
public void NumberOfParticlesInTwoMolesIsDoubleAvogadroConstant()
56+
{
57+
var twoMoles = AmountOfSubstance.FromMoles(2);
58+
var numberOfParticles = twoMoles.NumberOfParticles();
59+
Assert.Equal(AmountOfSubstance.AvogadroConstant * 2, numberOfParticles);
60+
}
4461
}
4562
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
2+
// https://github.com/angularsen/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
// ReSharper disable once CheckNamespace
23+
24+
using UnitsNet.Units;
25+
26+
namespace UnitsNet
27+
{
28+
public partial struct AmountOfSubstance
29+
{
30+
/// <summary>
31+
/// The Avogadro constant is the number of constituent particles, usually molecules,
32+
/// atoms or ions that are contained in the amount of substance given by one mole. It is the proportionality factor that relates
33+
/// 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
34+
/// 6.02214076e23 mol−1 in the International System of Units (SI).
35+
/// </summary>
36+
/// <remarks>
37+
/// Pending revisions in the base set of SI units necessitated redefinitions of the concepts of chemical quantity. The Avogadro number,
38+
/// and its definition, was deprecated in favor of the Avogadro constant and its definition. Based on measurements made through the
39+
/// middle of 2017 which calculated a value for the Avogadro constant of NA = 6.022140758(62)×1023 mol−1, the redefinition of SI units
40+
/// is planned to take effect on 20 May 2019. The value of the constant will be fixed to exactly 6.02214076×1023 mol−1.
41+
/// See here: https://www.bipm.org/utils/common/pdf/CGPM-2018/26th-CGPM-Resolutions.pdf
42+
/// </remarks>
43+
public static double AvogadroConstant { get; } = 6.02214076e23;
44+
45+
/// <summary>
46+
/// Calculates the number of particles (atoms or molecules) in this amount of substance using the <see cref="AvogadroConstant"/>.
47+
/// </summary>
48+
/// <returns>The number of particles (atoms or molecules) in this amount of substance.</returns>
49+
public double NumberOfParticles()
50+
{
51+
var moles = AsBaseNumericType(AmountOfSubstanceUnit.Mole);
52+
return AvogadroConstant * moles;
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)