Skip to content

Feature: MolarEnergy #309

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

Merged
merged 2 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions UnitsNet.Tests/CustomCode/MolarEnergyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated (once) by \generate-code.bat, but will not be
// regenerated when it already exists. The purpose of creating this file is to make
// it easier to remember to implement all the unit conversion test cases.
//
// Whenever a new unit is added to this quantity and \generate-code.bat is run,
// the base test class will get a new abstract property and cause a compile error
// in this derived class, reminding the developer to implement the test case
// for the new unit.
//
// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
//
// Add CustomCode\Quantities\MyUnit.extra.cs files to add code to generated quantities.
// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities.
//
// </auto-generated>
//------------------------------------------------------------------------------

// Copyright (c) 2007 Andreas Gullberg Larsen ([email protected]).
// 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.


using System;

namespace UnitsNet.Tests.CustomCode
{
public class MolarEnergyTests : MolarEnergyTestsBase
{
protected override double JoulesPerMoleInOneJoulePerMole => 1e0;
protected override double KilojoulesPerMoleInOneJoulePerMole => 1e-3;
protected override double MegajoulesPerMoleInOneJoulePerMole => 1e-6;
}
}
191 changes: 191 additions & 0 deletions UnitsNet.Tests/GeneratedCode/MolarEnergyTestsBase.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by \generate-code.bat.
//
// Changes to this file will be lost when the code is regenerated.
// The build server regenerates the code before each build and a pre-build
// step will regenerate the code on each local build.
//
// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
//
// Add CustomCode\Quantities\MyUnit.extra.cs files to add code to generated quantities.
// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities.
//
// </auto-generated>
//------------------------------------------------------------------------------

// Copyright (c) 2007 Andreas Gullberg Larsen ([email protected]).
// 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.

using System;
using UnitsNet.Units;
using Xunit;

// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else?
#pragma warning disable 1718

// ReSharper disable once CheckNamespace
namespace UnitsNet.Tests
{
/// <summary>
/// Test of MolarEnergy.
/// </summary>
// ReSharper disable once PartialTypeWithSinglePart
public abstract partial class MolarEnergyTestsBase
{
protected abstract double JoulesPerMoleInOneJoulePerMole { get; }
protected abstract double KilojoulesPerMoleInOneJoulePerMole { get; }
protected abstract double MegajoulesPerMoleInOneJoulePerMole { get; }

// ReSharper disable VirtualMemberNeverOverriden.Global
protected virtual double JoulesPerMoleTolerance { get { return 1e-5; } }
protected virtual double KilojoulesPerMoleTolerance { get { return 1e-5; } }
protected virtual double MegajoulesPerMoleTolerance { get { return 1e-5; } }
// ReSharper restore VirtualMemberNeverOverriden.Global

[Fact]
public void JoulePerMoleToMolarEnergyUnits()
{
MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1);
AssertEx.EqualTolerance(JoulesPerMoleInOneJoulePerMole, joulepermole.JoulesPerMole, JoulesPerMoleTolerance);
AssertEx.EqualTolerance(KilojoulesPerMoleInOneJoulePerMole, joulepermole.KilojoulesPerMole, KilojoulesPerMoleTolerance);
AssertEx.EqualTolerance(MegajoulesPerMoleInOneJoulePerMole, joulepermole.MegajoulesPerMole, MegajoulesPerMoleTolerance);
}

[Fact]
public void FromValueAndUnit()
{
AssertEx.EqualTolerance(1, MolarEnergy.From(1, MolarEnergyUnit.JoulePerMole).JoulesPerMole, JoulesPerMoleTolerance);
AssertEx.EqualTolerance(1, MolarEnergy.From(1, MolarEnergyUnit.KilojoulePerMole).KilojoulesPerMole, KilojoulesPerMoleTolerance);
AssertEx.EqualTolerance(1, MolarEnergy.From(1, MolarEnergyUnit.MegajoulePerMole).MegajoulesPerMole, MegajoulesPerMoleTolerance);
}

[Fact]
public void As()
{
var joulepermole = MolarEnergy.FromJoulesPerMole(1);
AssertEx.EqualTolerance(JoulesPerMoleInOneJoulePerMole, joulepermole.As(MolarEnergyUnit.JoulePerMole), JoulesPerMoleTolerance);
AssertEx.EqualTolerance(KilojoulesPerMoleInOneJoulePerMole, joulepermole.As(MolarEnergyUnit.KilojoulePerMole), KilojoulesPerMoleTolerance);
AssertEx.EqualTolerance(MegajoulesPerMoleInOneJoulePerMole, joulepermole.As(MolarEnergyUnit.MegajoulePerMole), MegajoulesPerMoleTolerance);
}

[Fact]
public void ConversionRoundTrip()
{
MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1);
AssertEx.EqualTolerance(1, MolarEnergy.FromJoulesPerMole(joulepermole.JoulesPerMole).JoulesPerMole, JoulesPerMoleTolerance);
AssertEx.EqualTolerance(1, MolarEnergy.FromKilojoulesPerMole(joulepermole.KilojoulesPerMole).JoulesPerMole, KilojoulesPerMoleTolerance);
AssertEx.EqualTolerance(1, MolarEnergy.FromMegajoulesPerMole(joulepermole.MegajoulesPerMole).JoulesPerMole, MegajoulesPerMoleTolerance);
}

[Fact]
public void ArithmeticOperators()
{
MolarEnergy v = MolarEnergy.FromJoulesPerMole(1);
AssertEx.EqualTolerance(-1, -v.JoulesPerMole, JoulesPerMoleTolerance);
AssertEx.EqualTolerance(2, (MolarEnergy.FromJoulesPerMole(3)-v).JoulesPerMole, JoulesPerMoleTolerance);
AssertEx.EqualTolerance(2, (v + v).JoulesPerMole, JoulesPerMoleTolerance);
AssertEx.EqualTolerance(10, (v*10).JoulesPerMole, JoulesPerMoleTolerance);
AssertEx.EqualTolerance(10, (10*v).JoulesPerMole, JoulesPerMoleTolerance);
AssertEx.EqualTolerance(2, (MolarEnergy.FromJoulesPerMole(10)/5).JoulesPerMole, JoulesPerMoleTolerance);
AssertEx.EqualTolerance(2, MolarEnergy.FromJoulesPerMole(10)/MolarEnergy.FromJoulesPerMole(5), JoulesPerMoleTolerance);
}

[Fact]
public void ComparisonOperators()
{
MolarEnergy oneJoulePerMole = MolarEnergy.FromJoulesPerMole(1);
MolarEnergy twoJoulesPerMole = MolarEnergy.FromJoulesPerMole(2);

Assert.True(oneJoulePerMole < twoJoulesPerMole);
Assert.True(oneJoulePerMole <= twoJoulesPerMole);
Assert.True(twoJoulesPerMole > oneJoulePerMole);
Assert.True(twoJoulesPerMole >= oneJoulePerMole);

Assert.False(oneJoulePerMole > twoJoulesPerMole);
Assert.False(oneJoulePerMole >= twoJoulesPerMole);
Assert.False(twoJoulesPerMole < oneJoulePerMole);
Assert.False(twoJoulesPerMole <= oneJoulePerMole);
}

[Fact]
public void CompareToIsImplemented()
{
MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1);
Assert.Equal(0, joulepermole.CompareTo(joulepermole));
Assert.True(joulepermole.CompareTo(MolarEnergy.Zero) > 0);
Assert.True(MolarEnergy.Zero.CompareTo(joulepermole) < 0);
}

[Fact]
public void CompareToThrowsOnTypeMismatch()
{
MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1);
Assert.Throws<ArgumentException>(() => joulepermole.CompareTo(new object()));
}

[Fact]
public void CompareToThrowsOnNull()
{
MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1);
Assert.Throws<ArgumentNullException>(() => joulepermole.CompareTo(null));
}


[Fact]
public void EqualityOperators()
{
MolarEnergy a = MolarEnergy.FromJoulesPerMole(1);
MolarEnergy b = MolarEnergy.FromJoulesPerMole(2);

// ReSharper disable EqualExpressionComparison
Assert.True(a == a);
Assert.True(a != b);

Assert.False(a == b);
Assert.False(a != a);
// ReSharper restore EqualExpressionComparison
}

[Fact]
public void EqualsIsImplemented()
{
MolarEnergy v = MolarEnergy.FromJoulesPerMole(1);
Assert.True(v.Equals(MolarEnergy.FromJoulesPerMole(1)));
Assert.False(v.Equals(MolarEnergy.Zero));
}

[Fact]
public void EqualsReturnsFalseOnTypeMismatch()
{
MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1);
Assert.False(joulepermole.Equals(new object()));
}

[Fact]
public void EqualsReturnsFalseOnNull()
{
MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1);
Assert.False(joulepermole.Equals(null));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by \generate-code.bat.
//
// Changes to this file will be lost when the code is regenerated.
// The build server regenerates the code before each build and a pre-build
// step will regenerate the code on each local build.
//
// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
//
// Add CustomCode\Quantities\MyUnit.extra.cs files to add code to generated quantities.
// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities.
//
// </auto-generated>
//------------------------------------------------------------------------------

// Copyright (c) 2007 Andreas Gullberg Larsen ([email protected]).
// 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.

using System;

// Windows Runtime Component does not support extension methods and method overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
#if !WINDOWS_UWP
namespace UnitsNet.Extensions.NumberToMolarEnergy
{
public static class NumberToMolarEnergyExtensions
{
#region JoulePerMole

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double)"/>
public static MolarEnergy JoulesPerMole(this int value) => MolarEnergy.FromJoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double?)"/>
public static MolarEnergy? JoulesPerMole(this int? value) => MolarEnergy.FromJoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double)"/>
public static MolarEnergy JoulesPerMole(this long value) => MolarEnergy.FromJoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double?)"/>
public static MolarEnergy? JoulesPerMole(this long? value) => MolarEnergy.FromJoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double)"/>
public static MolarEnergy JoulesPerMole(this double value) => MolarEnergy.FromJoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double?)"/>
public static MolarEnergy? JoulesPerMole(this double? value) => MolarEnergy.FromJoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double)"/>
public static MolarEnergy JoulesPerMole(this float value) => MolarEnergy.FromJoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double?)"/>
public static MolarEnergy? JoulesPerMole(this float? value) => MolarEnergy.FromJoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double)"/>
public static MolarEnergy JoulesPerMole(this decimal value) => MolarEnergy.FromJoulesPerMole(Convert.ToDouble(value));

/// <inheritdoc cref="MolarEnergy.FromJoulesPerMole(double?)"/>
public static MolarEnergy? JoulesPerMole(this decimal? value) => MolarEnergy.FromJoulesPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

#region KilojoulePerMole

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double)"/>
public static MolarEnergy KilojoulesPerMole(this int value) => MolarEnergy.FromKilojoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double?)"/>
public static MolarEnergy? KilojoulesPerMole(this int? value) => MolarEnergy.FromKilojoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double)"/>
public static MolarEnergy KilojoulesPerMole(this long value) => MolarEnergy.FromKilojoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double?)"/>
public static MolarEnergy? KilojoulesPerMole(this long? value) => MolarEnergy.FromKilojoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double)"/>
public static MolarEnergy KilojoulesPerMole(this double value) => MolarEnergy.FromKilojoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double?)"/>
public static MolarEnergy? KilojoulesPerMole(this double? value) => MolarEnergy.FromKilojoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double)"/>
public static MolarEnergy KilojoulesPerMole(this float value) => MolarEnergy.FromKilojoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double?)"/>
public static MolarEnergy? KilojoulesPerMole(this float? value) => MolarEnergy.FromKilojoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double)"/>
public static MolarEnergy KilojoulesPerMole(this decimal value) => MolarEnergy.FromKilojoulesPerMole(Convert.ToDouble(value));

/// <inheritdoc cref="MolarEnergy.FromKilojoulesPerMole(double?)"/>
public static MolarEnergy? KilojoulesPerMole(this decimal? value) => MolarEnergy.FromKilojoulesPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

#region MegajoulePerMole

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double)"/>
public static MolarEnergy MegajoulesPerMole(this int value) => MolarEnergy.FromMegajoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double?)"/>
public static MolarEnergy? MegajoulesPerMole(this int? value) => MolarEnergy.FromMegajoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double)"/>
public static MolarEnergy MegajoulesPerMole(this long value) => MolarEnergy.FromMegajoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double?)"/>
public static MolarEnergy? MegajoulesPerMole(this long? value) => MolarEnergy.FromMegajoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double)"/>
public static MolarEnergy MegajoulesPerMole(this double value) => MolarEnergy.FromMegajoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double?)"/>
public static MolarEnergy? MegajoulesPerMole(this double? value) => MolarEnergy.FromMegajoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double)"/>
public static MolarEnergy MegajoulesPerMole(this float value) => MolarEnergy.FromMegajoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double?)"/>
public static MolarEnergy? MegajoulesPerMole(this float? value) => MolarEnergy.FromMegajoulesPerMole(value);

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double)"/>
public static MolarEnergy MegajoulesPerMole(this decimal value) => MolarEnergy.FromMegajoulesPerMole(Convert.ToDouble(value));

/// <inheritdoc cref="MolarEnergy.FromMegajoulesPerMole(double?)"/>
public static MolarEnergy? MegajoulesPerMole(this decimal? value) => MolarEnergy.FromMegajoulesPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

}
}
#endif
Loading