From 460c887fdc0f59ba6e845245040a06d3b5a549ef Mon Sep 17 00:00:00 2001 From: Jens Krumsieck Date: Thu, 1 Sep 2022 17:12:43 +0200 Subject: [PATCH] Add Tests for conversion proj --- ChemSharp.sln | 7 +++++ .../ChemSharp.UnitConversion.Tests.csproj | 28 +++++++++++++++++++ .../EnergyConversionTests.cs | 23 +++++++++++++++ .../MagneticConversionTests.cs | 14 ++++++++++ .../MassConversionTests.cs | 21 ++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 Tests/ChemSharp.UnitConversion.Tests/ChemSharp.UnitConversion.Tests.csproj create mode 100644 Tests/ChemSharp.UnitConversion.Tests/EnergyConversionTests.cs create mode 100644 Tests/ChemSharp.UnitConversion.Tests/MagneticConversionTests.cs create mode 100644 Tests/ChemSharp.UnitConversion.Tests/MassConversionTests.cs diff --git a/ChemSharp.sln b/ChemSharp.sln index 635f824..08c03d7 100644 --- a/ChemSharp.sln +++ b/ChemSharp.sln @@ -34,6 +34,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChemSharp.Base.Tests", "Tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChemSharp.Molecules.Generator", "Generators\ChemSharp.Molecules.Generator\ChemSharp.Molecules.Generator.csproj", "{8B774CDC-ECFE-44FF-9EEC-D071D3CD0063}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChemSharp.UnitConversion.Tests", "Tests\ChemSharp.UnitConversion.Tests\ChemSharp.UnitConversion.Tests.csproj", "{A697847B-6A2E-47C7-852A-B48623E4916F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -80,6 +82,10 @@ Global {8B774CDC-ECFE-44FF-9EEC-D071D3CD0063}.Debug|Any CPU.Build.0 = Debug|Any CPU {8B774CDC-ECFE-44FF-9EEC-D071D3CD0063}.Release|Any CPU.ActiveCfg = Release|Any CPU {8B774CDC-ECFE-44FF-9EEC-D071D3CD0063}.Release|Any CPU.Build.0 = Release|Any CPU + {A697847B-6A2E-47C7-852A-B48623E4916F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A697847B-6A2E-47C7-852A-B48623E4916F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A697847B-6A2E-47C7-852A-B48623E4916F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A697847B-6A2E-47C7-852A-B48623E4916F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -89,6 +95,7 @@ Global {0ADAB8C5-8D08-456D-98CE-5D70E5DDC163} = {20F5697B-9414-4F33-88DA-9D84D9983B40} {9E0CBAF5-47D3-4E5C-A5C6-2B72D4AFFAC1} = {20F5697B-9414-4F33-88DA-9D84D9983B40} {8B774CDC-ECFE-44FF-9EEC-D071D3CD0063} = {CA4A529D-2EE9-4196-B069-328706EDE088} + {A697847B-6A2E-47C7-852A-B48623E4916F} = {20F5697B-9414-4F33-88DA-9D84D9983B40} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3C226C1E-BECB-41C3-BB05-E624764E4793} diff --git a/Tests/ChemSharp.UnitConversion.Tests/ChemSharp.UnitConversion.Tests.csproj b/Tests/ChemSharp.UnitConversion.Tests/ChemSharp.UnitConversion.Tests.csproj new file mode 100644 index 0000000..b26f9f4 --- /dev/null +++ b/Tests/ChemSharp.UnitConversion.Tests/ChemSharp.UnitConversion.Tests.csproj @@ -0,0 +1,28 @@ + + + + net6.0 + enable + + false + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/Tests/ChemSharp.UnitConversion.Tests/EnergyConversionTests.cs b/Tests/ChemSharp.UnitConversion.Tests/EnergyConversionTests.cs new file mode 100644 index 0000000..a686aa6 --- /dev/null +++ b/Tests/ChemSharp.UnitConversion.Tests/EnergyConversionTests.cs @@ -0,0 +1,23 @@ +using FluentAssertions; +using Xunit; + +namespace ChemSharp.UnitConversion.Tests; + +public class EnergyConversionTests +{ + [Fact] + public void ElectronVolt_To_Wavenumbers() + { + var converter = new EnergyUnitConverter("eV", "cm^-1"); + converter.Convert(1).Should().BeApproximately(8065.544, 5e-4); + converter.ConvertInverted(1).Should().BeApproximately(1 / 8065.544, 5e-4); + } + + [Fact] + public void Nanometers_To_Wavenumbers() + { + var converter = new EnergyUnitConverter("nm", "cm^-1"); + converter.Convert(500).Should().Be(20000); + converter.ConvertInverted(20000).Should().Be(500); + } +} diff --git a/Tests/ChemSharp.UnitConversion.Tests/MagneticConversionTests.cs b/Tests/ChemSharp.UnitConversion.Tests/MagneticConversionTests.cs new file mode 100644 index 0000000..08d6197 --- /dev/null +++ b/Tests/ChemSharp.UnitConversion.Tests/MagneticConversionTests.cs @@ -0,0 +1,14 @@ +using Xunit; + +namespace ChemSharp.UnitConversion.Tests; + +public class MagneticConversionTests +{ + [Fact] + public void Gauss_To_Millitesla() + { + var converter = new MagneticUnitConverter("G", "mT"); + Assert.Equal(.1, converter.Convert(1)); + Assert.Equal(10, converter.ConvertInverted(1)); + } +} diff --git a/Tests/ChemSharp.UnitConversion.Tests/MassConversionTests.cs b/Tests/ChemSharp.UnitConversion.Tests/MassConversionTests.cs new file mode 100644 index 0000000..6a6c5cd --- /dev/null +++ b/Tests/ChemSharp.UnitConversion.Tests/MassConversionTests.cs @@ -0,0 +1,21 @@ +using FluentAssertions; +using Xunit; + +namespace ChemSharp.UnitConversion.Tests; + +public class MassConversionTests +{ + [Fact] + public void SolarMass_To_EarthMass() + { + var converter = new MassUnitConverter("Solar Mass", "Earth Mass"); + converter.Convert(1).Should().BeApproximately(332946.0487, 1.5); + } + + [Fact] + public void Lbs_to_g() + { + var converter = new MassUnitConverter("lbs", "g"); + converter.Convert(1).Should().Be(453.59237); + } +}