diff --git a/UnitsNet.Tests/GeneratedCode/.gitignore b/UnitsNet.Tests/GeneratedCode/.gitignore new file mode 100644 index 0000000000..6dd350f428 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/.gitignore @@ -0,0 +1,4 @@ +*.g.cs +!InformationTestsBase.g.cs +!LengthTestsBase.g.cs +!LevelTestsBase.g.cs diff --git a/UnitsNet.Tests/GeneratedCode/AccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/AccelerationTestsBase.g.cs deleted file mode 100644 index a2265bb678..0000000000 --- a/UnitsNet.Tests/GeneratedCode/AccelerationTestsBase.g.cs +++ /dev/null @@ -1,344 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Acceleration. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AccelerationTestsBase - { - protected abstract double CentimetersPerSecondSquaredInOneMeterPerSecondSquared { get; } - protected abstract double DecimetersPerSecondSquaredInOneMeterPerSecondSquared { get; } - protected abstract double FeetPerSecondSquaredInOneMeterPerSecondSquared { get; } - protected abstract double InchesPerSecondSquaredInOneMeterPerSecondSquared { get; } - protected abstract double KilometersPerSecondSquaredInOneMeterPerSecondSquared { get; } - protected abstract double KnotsPerHourInOneMeterPerSecondSquared { get; } - protected abstract double KnotsPerMinuteInOneMeterPerSecondSquared { get; } - protected abstract double KnotsPerSecondInOneMeterPerSecondSquared { get; } - protected abstract double MetersPerSecondSquaredInOneMeterPerSecondSquared { get; } - protected abstract double MicrometersPerSecondSquaredInOneMeterPerSecondSquared { get; } - protected abstract double MillimetersPerSecondSquaredInOneMeterPerSecondSquared { get; } - protected abstract double NanometersPerSecondSquaredInOneMeterPerSecondSquared { get; } - protected abstract double StandardGravityInOneMeterPerSecondSquared { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentimetersPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double DecimetersPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double FeetPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double InchesPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double KilometersPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double KnotsPerHourTolerance { get { return 1e-5; } } - protected virtual double KnotsPerMinuteTolerance { get { return 1e-5; } } - protected virtual double KnotsPerSecondTolerance { get { return 1e-5; } } - protected virtual double MetersPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double MicrometersPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double MillimetersPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double NanometersPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double StandardGravityTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Acceleration((double)0.0, AccelerationUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Acceleration(double.PositiveInfinity, AccelerationUnit.MeterPerSecondSquared)); - Assert.Throws(() => new Acceleration(double.NegativeInfinity, AccelerationUnit.MeterPerSecondSquared)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Acceleration(double.NaN, AccelerationUnit.MeterPerSecondSquared)); - } - - [Fact] - public void MeterPerSecondSquaredToAccelerationUnits() - { - Acceleration meterpersecondsquared = Acceleration.FromMetersPerSecondSquared(1); - AssertEx.EqualTolerance(CentimetersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.CentimetersPerSecondSquared, CentimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(DecimetersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.DecimetersPerSecondSquared, DecimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(FeetPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.FeetPerSecondSquared, FeetPerSecondSquaredTolerance); - AssertEx.EqualTolerance(InchesPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.InchesPerSecondSquared, InchesPerSecondSquaredTolerance); - AssertEx.EqualTolerance(KilometersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.KilometersPerSecondSquared, KilometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(KnotsPerHourInOneMeterPerSecondSquared, meterpersecondsquared.KnotsPerHour, KnotsPerHourTolerance); - AssertEx.EqualTolerance(KnotsPerMinuteInOneMeterPerSecondSquared, meterpersecondsquared.KnotsPerMinute, KnotsPerMinuteTolerance); - AssertEx.EqualTolerance(KnotsPerSecondInOneMeterPerSecondSquared, meterpersecondsquared.KnotsPerSecond, KnotsPerSecondTolerance); - AssertEx.EqualTolerance(MetersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(MicrometersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.MicrometersPerSecondSquared, MicrometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(MillimetersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.MillimetersPerSecondSquared, MillimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(NanometersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.NanometersPerSecondSquared, NanometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(StandardGravityInOneMeterPerSecondSquared, meterpersecondsquared.StandardGravity, StandardGravityTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.CentimeterPerSecondSquared).CentimetersPerSecondSquared, CentimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.DecimeterPerSecondSquared).DecimetersPerSecondSquared, DecimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.FootPerSecondSquared).FeetPerSecondSquared, FeetPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.InchPerSecondSquared).InchesPerSecondSquared, InchesPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.KilometerPerSecondSquared).KilometersPerSecondSquared, KilometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.KnotPerHour).KnotsPerHour, KnotsPerHourTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.KnotPerMinute).KnotsPerMinute, KnotsPerMinuteTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.KnotPerSecond).KnotsPerSecond, KnotsPerSecondTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.MeterPerSecondSquared).MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.MicrometerPerSecondSquared).MicrometersPerSecondSquared, MicrometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.MillimeterPerSecondSquared).MillimetersPerSecondSquared, MillimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.NanometerPerSecondSquared).NanometersPerSecondSquared, NanometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.From(1, AccelerationUnit.StandardGravity).StandardGravity, StandardGravityTolerance); - } - - [Fact] - public void FromMetersPerSecondSquared_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Acceleration.FromMetersPerSecondSquared(double.PositiveInfinity)); - Assert.Throws(() => Acceleration.FromMetersPerSecondSquared(double.NegativeInfinity)); - } - - [Fact] - public void FromMetersPerSecondSquared_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Acceleration.FromMetersPerSecondSquared(double.NaN)); - } - - [Fact] - public void As() - { - var meterpersecondsquared = Acceleration.FromMetersPerSecondSquared(1); - AssertEx.EqualTolerance(CentimetersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.CentimeterPerSecondSquared), CentimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(DecimetersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.DecimeterPerSecondSquared), DecimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(FeetPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.FootPerSecondSquared), FeetPerSecondSquaredTolerance); - AssertEx.EqualTolerance(InchesPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.InchPerSecondSquared), InchesPerSecondSquaredTolerance); - AssertEx.EqualTolerance(KilometersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.KilometerPerSecondSquared), KilometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(KnotsPerHourInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.KnotPerHour), KnotsPerHourTolerance); - AssertEx.EqualTolerance(KnotsPerMinuteInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.KnotPerMinute), KnotsPerMinuteTolerance); - AssertEx.EqualTolerance(KnotsPerSecondInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.KnotPerSecond), KnotsPerSecondTolerance); - AssertEx.EqualTolerance(MetersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.MeterPerSecondSquared), MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(MicrometersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.MicrometerPerSecondSquared), MicrometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(MillimetersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.MillimeterPerSecondSquared), MillimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(NanometersPerSecondSquaredInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.NanometerPerSecondSquared), NanometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(StandardGravityInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.StandardGravity), StandardGravityTolerance); - } - - [Fact] - public void ToUnit() - { - var meterpersecondsquared = Acceleration.FromMetersPerSecondSquared(1); - - var centimeterpersecondsquaredQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.CentimeterPerSecondSquared); - AssertEx.EqualTolerance(CentimetersPerSecondSquaredInOneMeterPerSecondSquared, (double)centimeterpersecondsquaredQuantity.Value, CentimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.CentimeterPerSecondSquared, centimeterpersecondsquaredQuantity.Unit); - - var decimeterpersecondsquaredQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.DecimeterPerSecondSquared); - AssertEx.EqualTolerance(DecimetersPerSecondSquaredInOneMeterPerSecondSquared, (double)decimeterpersecondsquaredQuantity.Value, DecimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.DecimeterPerSecondSquared, decimeterpersecondsquaredQuantity.Unit); - - var footpersecondsquaredQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.FootPerSecondSquared); - AssertEx.EqualTolerance(FeetPerSecondSquaredInOneMeterPerSecondSquared, (double)footpersecondsquaredQuantity.Value, FeetPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.FootPerSecondSquared, footpersecondsquaredQuantity.Unit); - - var inchpersecondsquaredQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.InchPerSecondSquared); - AssertEx.EqualTolerance(InchesPerSecondSquaredInOneMeterPerSecondSquared, (double)inchpersecondsquaredQuantity.Value, InchesPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.InchPerSecondSquared, inchpersecondsquaredQuantity.Unit); - - var kilometerpersecondsquaredQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.KilometerPerSecondSquared); - AssertEx.EqualTolerance(KilometersPerSecondSquaredInOneMeterPerSecondSquared, (double)kilometerpersecondsquaredQuantity.Value, KilometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.KilometerPerSecondSquared, kilometerpersecondsquaredQuantity.Unit); - - var knotperhourQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.KnotPerHour); - AssertEx.EqualTolerance(KnotsPerHourInOneMeterPerSecondSquared, (double)knotperhourQuantity.Value, KnotsPerHourTolerance); - Assert.Equal(AccelerationUnit.KnotPerHour, knotperhourQuantity.Unit); - - var knotperminuteQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.KnotPerMinute); - AssertEx.EqualTolerance(KnotsPerMinuteInOneMeterPerSecondSquared, (double)knotperminuteQuantity.Value, KnotsPerMinuteTolerance); - Assert.Equal(AccelerationUnit.KnotPerMinute, knotperminuteQuantity.Unit); - - var knotpersecondQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.KnotPerSecond); - AssertEx.EqualTolerance(KnotsPerSecondInOneMeterPerSecondSquared, (double)knotpersecondQuantity.Value, KnotsPerSecondTolerance); - Assert.Equal(AccelerationUnit.KnotPerSecond, knotpersecondQuantity.Unit); - - var meterpersecondsquaredQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.MeterPerSecondSquared); - AssertEx.EqualTolerance(MetersPerSecondSquaredInOneMeterPerSecondSquared, (double)meterpersecondsquaredQuantity.Value, MetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MeterPerSecondSquared, meterpersecondsquaredQuantity.Unit); - - var micrometerpersecondsquaredQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.MicrometerPerSecondSquared); - AssertEx.EqualTolerance(MicrometersPerSecondSquaredInOneMeterPerSecondSquared, (double)micrometerpersecondsquaredQuantity.Value, MicrometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MicrometerPerSecondSquared, micrometerpersecondsquaredQuantity.Unit); - - var millimeterpersecondsquaredQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.MillimeterPerSecondSquared); - AssertEx.EqualTolerance(MillimetersPerSecondSquaredInOneMeterPerSecondSquared, (double)millimeterpersecondsquaredQuantity.Value, MillimetersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.MillimeterPerSecondSquared, millimeterpersecondsquaredQuantity.Unit); - - var nanometerpersecondsquaredQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.NanometerPerSecondSquared); - AssertEx.EqualTolerance(NanometersPerSecondSquaredInOneMeterPerSecondSquared, (double)nanometerpersecondsquaredQuantity.Value, NanometersPerSecondSquaredTolerance); - Assert.Equal(AccelerationUnit.NanometerPerSecondSquared, nanometerpersecondsquaredQuantity.Unit); - - var standardgravityQuantity = meterpersecondsquared.ToUnit(AccelerationUnit.StandardGravity); - AssertEx.EqualTolerance(StandardGravityInOneMeterPerSecondSquared, (double)standardgravityQuantity.Value, StandardGravityTolerance); - Assert.Equal(AccelerationUnit.StandardGravity, standardgravityQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Acceleration meterpersecondsquared = Acceleration.FromMetersPerSecondSquared(1); - AssertEx.EqualTolerance(1, Acceleration.FromCentimetersPerSecondSquared(meterpersecondsquared.CentimetersPerSecondSquared).MetersPerSecondSquared, CentimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromDecimetersPerSecondSquared(meterpersecondsquared.DecimetersPerSecondSquared).MetersPerSecondSquared, DecimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromFeetPerSecondSquared(meterpersecondsquared.FeetPerSecondSquared).MetersPerSecondSquared, FeetPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromInchesPerSecondSquared(meterpersecondsquared.InchesPerSecondSquared).MetersPerSecondSquared, InchesPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromKilometersPerSecondSquared(meterpersecondsquared.KilometersPerSecondSquared).MetersPerSecondSquared, KilometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromKnotsPerHour(meterpersecondsquared.KnotsPerHour).MetersPerSecondSquared, KnotsPerHourTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromKnotsPerMinute(meterpersecondsquared.KnotsPerMinute).MetersPerSecondSquared, KnotsPerMinuteTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromKnotsPerSecond(meterpersecondsquared.KnotsPerSecond).MetersPerSecondSquared, KnotsPerSecondTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromMetersPerSecondSquared(meterpersecondsquared.MetersPerSecondSquared).MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromMicrometersPerSecondSquared(meterpersecondsquared.MicrometersPerSecondSquared).MetersPerSecondSquared, MicrometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromMillimetersPerSecondSquared(meterpersecondsquared.MillimetersPerSecondSquared).MetersPerSecondSquared, MillimetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromNanometersPerSecondSquared(meterpersecondsquared.NanometersPerSecondSquared).MetersPerSecondSquared, NanometersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, Acceleration.FromStandardGravity(meterpersecondsquared.StandardGravity).MetersPerSecondSquared, StandardGravityTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Acceleration v = Acceleration.FromMetersPerSecondSquared(1); - AssertEx.EqualTolerance(-1, -v.MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(2, (Acceleration.FromMetersPerSecondSquared(3)-v).MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(2, (v + v).MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(10, (v*10).MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(10, (10*v).MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(2, (Acceleration.FromMetersPerSecondSquared(10)/5).MetersPerSecondSquared, MetersPerSecondSquaredTolerance); - AssertEx.EqualTolerance(2, Acceleration.FromMetersPerSecondSquared(10)/Acceleration.FromMetersPerSecondSquared(5), MetersPerSecondSquaredTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Acceleration oneMeterPerSecondSquared = Acceleration.FromMetersPerSecondSquared(1); - Acceleration twoMetersPerSecondSquared = Acceleration.FromMetersPerSecondSquared(2); - - Assert.True(oneMeterPerSecondSquared < twoMetersPerSecondSquared); - Assert.True(oneMeterPerSecondSquared <= twoMetersPerSecondSquared); - Assert.True(twoMetersPerSecondSquared > oneMeterPerSecondSquared); - Assert.True(twoMetersPerSecondSquared >= oneMeterPerSecondSquared); - - Assert.False(oneMeterPerSecondSquared > twoMetersPerSecondSquared); - Assert.False(oneMeterPerSecondSquared >= twoMetersPerSecondSquared); - Assert.False(twoMetersPerSecondSquared < oneMeterPerSecondSquared); - Assert.False(twoMetersPerSecondSquared <= oneMeterPerSecondSquared); - } - - [Fact] - public void CompareToIsImplemented() - { - Acceleration meterpersecondsquared = Acceleration.FromMetersPerSecondSquared(1); - Assert.Equal(0, meterpersecondsquared.CompareTo(meterpersecondsquared)); - Assert.True(meterpersecondsquared.CompareTo(Acceleration.Zero) > 0); - Assert.True(Acceleration.Zero.CompareTo(meterpersecondsquared) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Acceleration meterpersecondsquared = Acceleration.FromMetersPerSecondSquared(1); - Assert.Throws(() => meterpersecondsquared.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Acceleration meterpersecondsquared = Acceleration.FromMetersPerSecondSquared(1); - Assert.Throws(() => meterpersecondsquared.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Acceleration v = Acceleration.FromMetersPerSecondSquared(1); - Assert.True(v.Equals(Acceleration.FromMetersPerSecondSquared(1), MetersPerSecondSquaredTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Acceleration.Zero, MetersPerSecondSquaredTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Acceleration meterpersecondsquared = Acceleration.FromMetersPerSecondSquared(1); - Assert.False(meterpersecondsquared.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Acceleration meterpersecondsquared = Acceleration.FromMetersPerSecondSquared(1); - Assert.False(meterpersecondsquared.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(AccelerationUnit.Undefined, Acceleration.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(AccelerationUnit)).Cast(); - foreach(var unit in units) - { - if(unit == AccelerationUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/AmountOfSubstanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/AmountOfSubstanceTestsBase.g.cs deleted file mode 100644 index e72fb73a08..0000000000 --- a/UnitsNet.Tests/GeneratedCode/AmountOfSubstanceTestsBase.g.cs +++ /dev/null @@ -1,354 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of AmountOfSubstance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AmountOfSubstanceTestsBase - { - protected abstract double CentimolesInOneMole { get; } - protected abstract double CentipoundMolesInOneMole { get; } - protected abstract double DecimolesInOneMole { get; } - protected abstract double DecipoundMolesInOneMole { get; } - protected abstract double KilomolesInOneMole { get; } - protected abstract double KilopoundMolesInOneMole { get; } - protected abstract double MicromolesInOneMole { get; } - protected abstract double MicropoundMolesInOneMole { get; } - protected abstract double MillimolesInOneMole { get; } - protected abstract double MillipoundMolesInOneMole { get; } - protected abstract double MolesInOneMole { get; } - protected abstract double NanomolesInOneMole { get; } - protected abstract double NanopoundMolesInOneMole { get; } - protected abstract double PoundMolesInOneMole { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentimolesTolerance { get { return 1e-5; } } - protected virtual double CentipoundMolesTolerance { get { return 1e-5; } } - protected virtual double DecimolesTolerance { get { return 1e-5; } } - protected virtual double DecipoundMolesTolerance { get { return 1e-5; } } - protected virtual double KilomolesTolerance { get { return 1e-5; } } - protected virtual double KilopoundMolesTolerance { get { return 1e-5; } } - protected virtual double MicromolesTolerance { get { return 1e-5; } } - protected virtual double MicropoundMolesTolerance { get { return 1e-5; } } - protected virtual double MillimolesTolerance { get { return 1e-5; } } - protected virtual double MillipoundMolesTolerance { get { return 1e-5; } } - protected virtual double MolesTolerance { get { return 1e-5; } } - protected virtual double NanomolesTolerance { get { return 1e-5; } } - protected virtual double NanopoundMolesTolerance { get { return 1e-5; } } - protected virtual double PoundMolesTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new AmountOfSubstance((double)0.0, AmountOfSubstanceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new AmountOfSubstance(double.PositiveInfinity, AmountOfSubstanceUnit.Mole)); - Assert.Throws(() => new AmountOfSubstance(double.NegativeInfinity, AmountOfSubstanceUnit.Mole)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new AmountOfSubstance(double.NaN, AmountOfSubstanceUnit.Mole)); - } - - [Fact] - public void MoleToAmountOfSubstanceUnits() - { - AmountOfSubstance mole = AmountOfSubstance.FromMoles(1); - AssertEx.EqualTolerance(CentimolesInOneMole, mole.Centimoles, CentimolesTolerance); - AssertEx.EqualTolerance(CentipoundMolesInOneMole, mole.CentipoundMoles, CentipoundMolesTolerance); - AssertEx.EqualTolerance(DecimolesInOneMole, mole.Decimoles, DecimolesTolerance); - AssertEx.EqualTolerance(DecipoundMolesInOneMole, mole.DecipoundMoles, DecipoundMolesTolerance); - AssertEx.EqualTolerance(KilomolesInOneMole, mole.Kilomoles, KilomolesTolerance); - AssertEx.EqualTolerance(KilopoundMolesInOneMole, mole.KilopoundMoles, KilopoundMolesTolerance); - AssertEx.EqualTolerance(MicromolesInOneMole, mole.Micromoles, MicromolesTolerance); - AssertEx.EqualTolerance(MicropoundMolesInOneMole, mole.MicropoundMoles, MicropoundMolesTolerance); - AssertEx.EqualTolerance(MillimolesInOneMole, mole.Millimoles, MillimolesTolerance); - AssertEx.EqualTolerance(MillipoundMolesInOneMole, mole.MillipoundMoles, MillipoundMolesTolerance); - AssertEx.EqualTolerance(MolesInOneMole, mole.Moles, MolesTolerance); - AssertEx.EqualTolerance(NanomolesInOneMole, mole.Nanomoles, NanomolesTolerance); - AssertEx.EqualTolerance(NanopoundMolesInOneMole, mole.NanopoundMoles, NanopoundMolesTolerance); - AssertEx.EqualTolerance(PoundMolesInOneMole, mole.PoundMoles, PoundMolesTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.Centimole).Centimoles, CentimolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.CentipoundMole).CentipoundMoles, CentipoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.Decimole).Decimoles, DecimolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.DecipoundMole).DecipoundMoles, DecipoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.Kilomole).Kilomoles, KilomolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.KilopoundMole).KilopoundMoles, KilopoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.Micromole).Micromoles, MicromolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.MicropoundMole).MicropoundMoles, MicropoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.Millimole).Millimoles, MillimolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.MillipoundMole).MillipoundMoles, MillipoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.Mole).Moles, MolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.Nanomole).Nanomoles, NanomolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.NanopoundMole).NanopoundMoles, NanopoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.From(1, AmountOfSubstanceUnit.PoundMole).PoundMoles, PoundMolesTolerance); - } - - [Fact] - public void FromMoles_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => AmountOfSubstance.FromMoles(double.PositiveInfinity)); - Assert.Throws(() => AmountOfSubstance.FromMoles(double.NegativeInfinity)); - } - - [Fact] - public void FromMoles_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => AmountOfSubstance.FromMoles(double.NaN)); - } - - [Fact] - public void As() - { - var mole = AmountOfSubstance.FromMoles(1); - AssertEx.EqualTolerance(CentimolesInOneMole, mole.As(AmountOfSubstanceUnit.Centimole), CentimolesTolerance); - AssertEx.EqualTolerance(CentipoundMolesInOneMole, mole.As(AmountOfSubstanceUnit.CentipoundMole), CentipoundMolesTolerance); - AssertEx.EqualTolerance(DecimolesInOneMole, mole.As(AmountOfSubstanceUnit.Decimole), DecimolesTolerance); - AssertEx.EqualTolerance(DecipoundMolesInOneMole, mole.As(AmountOfSubstanceUnit.DecipoundMole), DecipoundMolesTolerance); - AssertEx.EqualTolerance(KilomolesInOneMole, mole.As(AmountOfSubstanceUnit.Kilomole), KilomolesTolerance); - AssertEx.EqualTolerance(KilopoundMolesInOneMole, mole.As(AmountOfSubstanceUnit.KilopoundMole), KilopoundMolesTolerance); - AssertEx.EqualTolerance(MicromolesInOneMole, mole.As(AmountOfSubstanceUnit.Micromole), MicromolesTolerance); - AssertEx.EqualTolerance(MicropoundMolesInOneMole, mole.As(AmountOfSubstanceUnit.MicropoundMole), MicropoundMolesTolerance); - AssertEx.EqualTolerance(MillimolesInOneMole, mole.As(AmountOfSubstanceUnit.Millimole), MillimolesTolerance); - AssertEx.EqualTolerance(MillipoundMolesInOneMole, mole.As(AmountOfSubstanceUnit.MillipoundMole), MillipoundMolesTolerance); - AssertEx.EqualTolerance(MolesInOneMole, mole.As(AmountOfSubstanceUnit.Mole), MolesTolerance); - AssertEx.EqualTolerance(NanomolesInOneMole, mole.As(AmountOfSubstanceUnit.Nanomole), NanomolesTolerance); - AssertEx.EqualTolerance(NanopoundMolesInOneMole, mole.As(AmountOfSubstanceUnit.NanopoundMole), NanopoundMolesTolerance); - AssertEx.EqualTolerance(PoundMolesInOneMole, mole.As(AmountOfSubstanceUnit.PoundMole), PoundMolesTolerance); - } - - [Fact] - public void ToUnit() - { - var mole = AmountOfSubstance.FromMoles(1); - - var centimoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Centimole); - AssertEx.EqualTolerance(CentimolesInOneMole, (double)centimoleQuantity.Value, CentimolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Centimole, centimoleQuantity.Unit); - - var centipoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.CentipoundMole); - AssertEx.EqualTolerance(CentipoundMolesInOneMole, (double)centipoundmoleQuantity.Value, CentipoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.CentipoundMole, centipoundmoleQuantity.Unit); - - var decimoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Decimole); - AssertEx.EqualTolerance(DecimolesInOneMole, (double)decimoleQuantity.Value, DecimolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Decimole, decimoleQuantity.Unit); - - var decipoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.DecipoundMole); - AssertEx.EqualTolerance(DecipoundMolesInOneMole, (double)decipoundmoleQuantity.Value, DecipoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.DecipoundMole, decipoundmoleQuantity.Unit); - - var kilomoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Kilomole); - AssertEx.EqualTolerance(KilomolesInOneMole, (double)kilomoleQuantity.Value, KilomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Kilomole, kilomoleQuantity.Unit); - - var kilopoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.KilopoundMole); - AssertEx.EqualTolerance(KilopoundMolesInOneMole, (double)kilopoundmoleQuantity.Value, KilopoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.KilopoundMole, kilopoundmoleQuantity.Unit); - - var micromoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Micromole); - AssertEx.EqualTolerance(MicromolesInOneMole, (double)micromoleQuantity.Value, MicromolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Micromole, micromoleQuantity.Unit); - - var micropoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.MicropoundMole); - AssertEx.EqualTolerance(MicropoundMolesInOneMole, (double)micropoundmoleQuantity.Value, MicropoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.MicropoundMole, micropoundmoleQuantity.Unit); - - var millimoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Millimole); - AssertEx.EqualTolerance(MillimolesInOneMole, (double)millimoleQuantity.Value, MillimolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Millimole, millimoleQuantity.Unit); - - var millipoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.MillipoundMole); - AssertEx.EqualTolerance(MillipoundMolesInOneMole, (double)millipoundmoleQuantity.Value, MillipoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.MillipoundMole, millipoundmoleQuantity.Unit); - - var moleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Mole); - AssertEx.EqualTolerance(MolesInOneMole, (double)moleQuantity.Value, MolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Mole, moleQuantity.Unit); - - var nanomoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.Nanomole); - AssertEx.EqualTolerance(NanomolesInOneMole, (double)nanomoleQuantity.Value, NanomolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.Nanomole, nanomoleQuantity.Unit); - - var nanopoundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.NanopoundMole); - AssertEx.EqualTolerance(NanopoundMolesInOneMole, (double)nanopoundmoleQuantity.Value, NanopoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.NanopoundMole, nanopoundmoleQuantity.Unit); - - var poundmoleQuantity = mole.ToUnit(AmountOfSubstanceUnit.PoundMole); - AssertEx.EqualTolerance(PoundMolesInOneMole, (double)poundmoleQuantity.Value, PoundMolesTolerance); - Assert.Equal(AmountOfSubstanceUnit.PoundMole, poundmoleQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - AmountOfSubstance mole = AmountOfSubstance.FromMoles(1); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromCentimoles(mole.Centimoles).Moles, CentimolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromCentipoundMoles(mole.CentipoundMoles).Moles, CentipoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromDecimoles(mole.Decimoles).Moles, DecimolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromDecipoundMoles(mole.DecipoundMoles).Moles, DecipoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromKilomoles(mole.Kilomoles).Moles, KilomolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromKilopoundMoles(mole.KilopoundMoles).Moles, KilopoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromMicromoles(mole.Micromoles).Moles, MicromolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromMicropoundMoles(mole.MicropoundMoles).Moles, MicropoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromMillimoles(mole.Millimoles).Moles, MillimolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromMillipoundMoles(mole.MillipoundMoles).Moles, MillipoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromMoles(mole.Moles).Moles, MolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromNanomoles(mole.Nanomoles).Moles, NanomolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromNanopoundMoles(mole.NanopoundMoles).Moles, NanopoundMolesTolerance); - AssertEx.EqualTolerance(1, AmountOfSubstance.FromPoundMoles(mole.PoundMoles).Moles, PoundMolesTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - AmountOfSubstance v = AmountOfSubstance.FromMoles(1); - AssertEx.EqualTolerance(-1, -v.Moles, MolesTolerance); - AssertEx.EqualTolerance(2, (AmountOfSubstance.FromMoles(3)-v).Moles, MolesTolerance); - AssertEx.EqualTolerance(2, (v + v).Moles, MolesTolerance); - AssertEx.EqualTolerance(10, (v*10).Moles, MolesTolerance); - AssertEx.EqualTolerance(10, (10*v).Moles, MolesTolerance); - AssertEx.EqualTolerance(2, (AmountOfSubstance.FromMoles(10)/5).Moles, MolesTolerance); - AssertEx.EqualTolerance(2, AmountOfSubstance.FromMoles(10)/AmountOfSubstance.FromMoles(5), MolesTolerance); - } - - [Fact] - public void ComparisonOperators() - { - AmountOfSubstance oneMole = AmountOfSubstance.FromMoles(1); - AmountOfSubstance twoMoles = AmountOfSubstance.FromMoles(2); - - Assert.True(oneMole < twoMoles); - Assert.True(oneMole <= twoMoles); - Assert.True(twoMoles > oneMole); - Assert.True(twoMoles >= oneMole); - - Assert.False(oneMole > twoMoles); - Assert.False(oneMole >= twoMoles); - Assert.False(twoMoles < oneMole); - Assert.False(twoMoles <= oneMole); - } - - [Fact] - public void CompareToIsImplemented() - { - AmountOfSubstance mole = AmountOfSubstance.FromMoles(1); - Assert.Equal(0, mole.CompareTo(mole)); - Assert.True(mole.CompareTo(AmountOfSubstance.Zero) > 0); - Assert.True(AmountOfSubstance.Zero.CompareTo(mole) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - AmountOfSubstance mole = AmountOfSubstance.FromMoles(1); - Assert.Throws(() => mole.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - AmountOfSubstance mole = AmountOfSubstance.FromMoles(1); - Assert.Throws(() => mole.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - AmountOfSubstance v = AmountOfSubstance.FromMoles(1); - Assert.True(v.Equals(AmountOfSubstance.FromMoles(1), MolesTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(AmountOfSubstance.Zero, MolesTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - AmountOfSubstance mole = AmountOfSubstance.FromMoles(1); - Assert.False(mole.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - AmountOfSubstance mole = AmountOfSubstance.FromMoles(1); - Assert.False(mole.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(AmountOfSubstanceUnit.Undefined, AmountOfSubstance.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(AmountOfSubstanceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == AmountOfSubstanceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/AmplitudeRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/AmplitudeRatioTestsBase.g.cs deleted file mode 100644 index cfdaee8eca..0000000000 --- a/UnitsNet.Tests/GeneratedCode/AmplitudeRatioTestsBase.g.cs +++ /dev/null @@ -1,259 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of AmplitudeRatio. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AmplitudeRatioTestsBase - { - protected abstract double DecibelMicrovoltsInOneDecibelVolt { get; } - protected abstract double DecibelMillivoltsInOneDecibelVolt { get; } - protected abstract double DecibelsUnloadedInOneDecibelVolt { get; } - protected abstract double DecibelVoltsInOneDecibelVolt { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DecibelMicrovoltsTolerance { get { return 1e-5; } } - protected virtual double DecibelMillivoltsTolerance { get { return 1e-5; } } - protected virtual double DecibelsUnloadedTolerance { get { return 1e-5; } } - protected virtual double DecibelVoltsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new AmplitudeRatio((double)0.0, AmplitudeRatioUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new AmplitudeRatio(double.PositiveInfinity, AmplitudeRatioUnit.DecibelVolt)); - Assert.Throws(() => new AmplitudeRatio(double.NegativeInfinity, AmplitudeRatioUnit.DecibelVolt)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new AmplitudeRatio(double.NaN, AmplitudeRatioUnit.DecibelVolt)); - } - - [Fact] - public void DecibelVoltToAmplitudeRatioUnits() - { - AmplitudeRatio decibelvolt = AmplitudeRatio.FromDecibelVolts(1); - AssertEx.EqualTolerance(DecibelMicrovoltsInOneDecibelVolt, decibelvolt.DecibelMicrovolts, DecibelMicrovoltsTolerance); - AssertEx.EqualTolerance(DecibelMillivoltsInOneDecibelVolt, decibelvolt.DecibelMillivolts, DecibelMillivoltsTolerance); - AssertEx.EqualTolerance(DecibelsUnloadedInOneDecibelVolt, decibelvolt.DecibelsUnloaded, DecibelsUnloadedTolerance); - AssertEx.EqualTolerance(DecibelVoltsInOneDecibelVolt, decibelvolt.DecibelVolts, DecibelVoltsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, AmplitudeRatio.From(1, AmplitudeRatioUnit.DecibelMicrovolt).DecibelMicrovolts, DecibelMicrovoltsTolerance); - AssertEx.EqualTolerance(1, AmplitudeRatio.From(1, AmplitudeRatioUnit.DecibelMillivolt).DecibelMillivolts, DecibelMillivoltsTolerance); - AssertEx.EqualTolerance(1, AmplitudeRatio.From(1, AmplitudeRatioUnit.DecibelUnloaded).DecibelsUnloaded, DecibelsUnloadedTolerance); - AssertEx.EqualTolerance(1, AmplitudeRatio.From(1, AmplitudeRatioUnit.DecibelVolt).DecibelVolts, DecibelVoltsTolerance); - } - - [Fact] - public void FromDecibelVolts_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => AmplitudeRatio.FromDecibelVolts(double.PositiveInfinity)); - Assert.Throws(() => AmplitudeRatio.FromDecibelVolts(double.NegativeInfinity)); - } - - [Fact] - public void FromDecibelVolts_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => AmplitudeRatio.FromDecibelVolts(double.NaN)); - } - - [Fact] - public void As() - { - var decibelvolt = AmplitudeRatio.FromDecibelVolts(1); - AssertEx.EqualTolerance(DecibelMicrovoltsInOneDecibelVolt, decibelvolt.As(AmplitudeRatioUnit.DecibelMicrovolt), DecibelMicrovoltsTolerance); - AssertEx.EqualTolerance(DecibelMillivoltsInOneDecibelVolt, decibelvolt.As(AmplitudeRatioUnit.DecibelMillivolt), DecibelMillivoltsTolerance); - AssertEx.EqualTolerance(DecibelsUnloadedInOneDecibelVolt, decibelvolt.As(AmplitudeRatioUnit.DecibelUnloaded), DecibelsUnloadedTolerance); - AssertEx.EqualTolerance(DecibelVoltsInOneDecibelVolt, decibelvolt.As(AmplitudeRatioUnit.DecibelVolt), DecibelVoltsTolerance); - } - - [Fact] - public void ToUnit() - { - var decibelvolt = AmplitudeRatio.FromDecibelVolts(1); - - var decibelmicrovoltQuantity = decibelvolt.ToUnit(AmplitudeRatioUnit.DecibelMicrovolt); - AssertEx.EqualTolerance(DecibelMicrovoltsInOneDecibelVolt, (double)decibelmicrovoltQuantity.Value, DecibelMicrovoltsTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelMicrovolt, decibelmicrovoltQuantity.Unit); - - var decibelmillivoltQuantity = decibelvolt.ToUnit(AmplitudeRatioUnit.DecibelMillivolt); - AssertEx.EqualTolerance(DecibelMillivoltsInOneDecibelVolt, (double)decibelmillivoltQuantity.Value, DecibelMillivoltsTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelMillivolt, decibelmillivoltQuantity.Unit); - - var decibelunloadedQuantity = decibelvolt.ToUnit(AmplitudeRatioUnit.DecibelUnloaded); - AssertEx.EqualTolerance(DecibelsUnloadedInOneDecibelVolt, (double)decibelunloadedQuantity.Value, DecibelsUnloadedTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelUnloaded, decibelunloadedQuantity.Unit); - - var decibelvoltQuantity = decibelvolt.ToUnit(AmplitudeRatioUnit.DecibelVolt); - AssertEx.EqualTolerance(DecibelVoltsInOneDecibelVolt, (double)decibelvoltQuantity.Value, DecibelVoltsTolerance); - Assert.Equal(AmplitudeRatioUnit.DecibelVolt, decibelvoltQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - AmplitudeRatio decibelvolt = AmplitudeRatio.FromDecibelVolts(1); - AssertEx.EqualTolerance(1, AmplitudeRatio.FromDecibelMicrovolts(decibelvolt.DecibelMicrovolts).DecibelVolts, DecibelMicrovoltsTolerance); - AssertEx.EqualTolerance(1, AmplitudeRatio.FromDecibelMillivolts(decibelvolt.DecibelMillivolts).DecibelVolts, DecibelMillivoltsTolerance); - AssertEx.EqualTolerance(1, AmplitudeRatio.FromDecibelsUnloaded(decibelvolt.DecibelsUnloaded).DecibelVolts, DecibelsUnloadedTolerance); - AssertEx.EqualTolerance(1, AmplitudeRatio.FromDecibelVolts(decibelvolt.DecibelVolts).DecibelVolts, DecibelVoltsTolerance); - } - - [Fact] - public void LogarithmicArithmeticOperators() - { - AmplitudeRatio v = AmplitudeRatio.FromDecibelVolts(40); - AssertEx.EqualTolerance(-40, -v.DecibelVolts, DecibelVoltsTolerance); - AssertLogarithmicAddition(); - AssertLogarithmicSubtraction(); - AssertEx.EqualTolerance(50, (v*10).DecibelVolts, DecibelVoltsTolerance); - AssertEx.EqualTolerance(50, (10*v).DecibelVolts, DecibelVoltsTolerance); - AssertEx.EqualTolerance(35, (v/5).DecibelVolts, DecibelVoltsTolerance); - AssertEx.EqualTolerance(35, v/AmplitudeRatio.FromDecibelVolts(5), DecibelVoltsTolerance); - } - - protected abstract void AssertLogarithmicAddition(); - - protected abstract void AssertLogarithmicSubtraction(); - - - [Fact] - public void ComparisonOperators() - { - AmplitudeRatio oneDecibelVolt = AmplitudeRatio.FromDecibelVolts(1); - AmplitudeRatio twoDecibelVolts = AmplitudeRatio.FromDecibelVolts(2); - - Assert.True(oneDecibelVolt < twoDecibelVolts); - Assert.True(oneDecibelVolt <= twoDecibelVolts); - Assert.True(twoDecibelVolts > oneDecibelVolt); - Assert.True(twoDecibelVolts >= oneDecibelVolt); - - Assert.False(oneDecibelVolt > twoDecibelVolts); - Assert.False(oneDecibelVolt >= twoDecibelVolts); - Assert.False(twoDecibelVolts < oneDecibelVolt); - Assert.False(twoDecibelVolts <= oneDecibelVolt); - } - - [Fact] - public void CompareToIsImplemented() - { - AmplitudeRatio decibelvolt = AmplitudeRatio.FromDecibelVolts(1); - Assert.Equal(0, decibelvolt.CompareTo(decibelvolt)); - Assert.True(decibelvolt.CompareTo(AmplitudeRatio.Zero) > 0); - Assert.True(AmplitudeRatio.Zero.CompareTo(decibelvolt) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - AmplitudeRatio decibelvolt = AmplitudeRatio.FromDecibelVolts(1); - Assert.Throws(() => decibelvolt.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - AmplitudeRatio decibelvolt = AmplitudeRatio.FromDecibelVolts(1); - Assert.Throws(() => decibelvolt.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - AmplitudeRatio v = AmplitudeRatio.FromDecibelVolts(1); - Assert.True(v.Equals(AmplitudeRatio.FromDecibelVolts(1), DecibelVoltsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(AmplitudeRatio.Zero, DecibelVoltsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - AmplitudeRatio decibelvolt = AmplitudeRatio.FromDecibelVolts(1); - Assert.False(decibelvolt.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - AmplitudeRatio decibelvolt = AmplitudeRatio.FromDecibelVolts(1); - Assert.False(decibelvolt.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(AmplitudeRatioUnit.Undefined, AmplitudeRatio.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(AmplitudeRatioUnit)).Cast(); - foreach(var unit in units) - { - if(unit == AmplitudeRatioUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/AngleTestsBase.g.cs deleted file mode 100644 index 8ef19e88cc..0000000000 --- a/UnitsNet.Tests/GeneratedCode/AngleTestsBase.g.cs +++ /dev/null @@ -1,354 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Angle. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AngleTestsBase - { - protected abstract double ArcminutesInOneDegree { get; } - protected abstract double ArcsecondsInOneDegree { get; } - protected abstract double CentiradiansInOneDegree { get; } - protected abstract double DeciradiansInOneDegree { get; } - protected abstract double DegreesInOneDegree { get; } - protected abstract double GradiansInOneDegree { get; } - protected abstract double MicrodegreesInOneDegree { get; } - protected abstract double MicroradiansInOneDegree { get; } - protected abstract double MillidegreesInOneDegree { get; } - protected abstract double MilliradiansInOneDegree { get; } - protected abstract double NanodegreesInOneDegree { get; } - protected abstract double NanoradiansInOneDegree { get; } - protected abstract double RadiansInOneDegree { get; } - protected abstract double RevolutionsInOneDegree { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double ArcminutesTolerance { get { return 1e-5; } } - protected virtual double ArcsecondsTolerance { get { return 1e-5; } } - protected virtual double CentiradiansTolerance { get { return 1e-5; } } - protected virtual double DeciradiansTolerance { get { return 1e-5; } } - protected virtual double DegreesTolerance { get { return 1e-5; } } - protected virtual double GradiansTolerance { get { return 1e-5; } } - protected virtual double MicrodegreesTolerance { get { return 1e-5; } } - protected virtual double MicroradiansTolerance { get { return 1e-5; } } - protected virtual double MillidegreesTolerance { get { return 1e-5; } } - protected virtual double MilliradiansTolerance { get { return 1e-5; } } - protected virtual double NanodegreesTolerance { get { return 1e-5; } } - protected virtual double NanoradiansTolerance { get { return 1e-5; } } - protected virtual double RadiansTolerance { get { return 1e-5; } } - protected virtual double RevolutionsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Angle((double)0.0, AngleUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Angle(double.PositiveInfinity, AngleUnit.Degree)); - Assert.Throws(() => new Angle(double.NegativeInfinity, AngleUnit.Degree)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Angle(double.NaN, AngleUnit.Degree)); - } - - [Fact] - public void DegreeToAngleUnits() - { - Angle degree = Angle.FromDegrees(1); - AssertEx.EqualTolerance(ArcminutesInOneDegree, degree.Arcminutes, ArcminutesTolerance); - AssertEx.EqualTolerance(ArcsecondsInOneDegree, degree.Arcseconds, ArcsecondsTolerance); - AssertEx.EqualTolerance(CentiradiansInOneDegree, degree.Centiradians, CentiradiansTolerance); - AssertEx.EqualTolerance(DeciradiansInOneDegree, degree.Deciradians, DeciradiansTolerance); - AssertEx.EqualTolerance(DegreesInOneDegree, degree.Degrees, DegreesTolerance); - AssertEx.EqualTolerance(GradiansInOneDegree, degree.Gradians, GradiansTolerance); - AssertEx.EqualTolerance(MicrodegreesInOneDegree, degree.Microdegrees, MicrodegreesTolerance); - AssertEx.EqualTolerance(MicroradiansInOneDegree, degree.Microradians, MicroradiansTolerance); - AssertEx.EqualTolerance(MillidegreesInOneDegree, degree.Millidegrees, MillidegreesTolerance); - AssertEx.EqualTolerance(MilliradiansInOneDegree, degree.Milliradians, MilliradiansTolerance); - AssertEx.EqualTolerance(NanodegreesInOneDegree, degree.Nanodegrees, NanodegreesTolerance); - AssertEx.EqualTolerance(NanoradiansInOneDegree, degree.Nanoradians, NanoradiansTolerance); - AssertEx.EqualTolerance(RadiansInOneDegree, degree.Radians, RadiansTolerance); - AssertEx.EqualTolerance(RevolutionsInOneDegree, degree.Revolutions, RevolutionsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Arcminute).Arcminutes, ArcminutesTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Arcsecond).Arcseconds, ArcsecondsTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Centiradian).Centiradians, CentiradiansTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Deciradian).Deciradians, DeciradiansTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Degree).Degrees, DegreesTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Gradian).Gradians, GradiansTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Microdegree).Microdegrees, MicrodegreesTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Microradian).Microradians, MicroradiansTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Millidegree).Millidegrees, MillidegreesTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Milliradian).Milliradians, MilliradiansTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Nanodegree).Nanodegrees, NanodegreesTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Nanoradian).Nanoradians, NanoradiansTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Radian).Radians, RadiansTolerance); - AssertEx.EqualTolerance(1, Angle.From(1, AngleUnit.Revolution).Revolutions, RevolutionsTolerance); - } - - [Fact] - public void FromDegrees_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Angle.FromDegrees(double.PositiveInfinity)); - Assert.Throws(() => Angle.FromDegrees(double.NegativeInfinity)); - } - - [Fact] - public void FromDegrees_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Angle.FromDegrees(double.NaN)); - } - - [Fact] - public void As() - { - var degree = Angle.FromDegrees(1); - AssertEx.EqualTolerance(ArcminutesInOneDegree, degree.As(AngleUnit.Arcminute), ArcminutesTolerance); - AssertEx.EqualTolerance(ArcsecondsInOneDegree, degree.As(AngleUnit.Arcsecond), ArcsecondsTolerance); - AssertEx.EqualTolerance(CentiradiansInOneDegree, degree.As(AngleUnit.Centiradian), CentiradiansTolerance); - AssertEx.EqualTolerance(DeciradiansInOneDegree, degree.As(AngleUnit.Deciradian), DeciradiansTolerance); - AssertEx.EqualTolerance(DegreesInOneDegree, degree.As(AngleUnit.Degree), DegreesTolerance); - AssertEx.EqualTolerance(GradiansInOneDegree, degree.As(AngleUnit.Gradian), GradiansTolerance); - AssertEx.EqualTolerance(MicrodegreesInOneDegree, degree.As(AngleUnit.Microdegree), MicrodegreesTolerance); - AssertEx.EqualTolerance(MicroradiansInOneDegree, degree.As(AngleUnit.Microradian), MicroradiansTolerance); - AssertEx.EqualTolerance(MillidegreesInOneDegree, degree.As(AngleUnit.Millidegree), MillidegreesTolerance); - AssertEx.EqualTolerance(MilliradiansInOneDegree, degree.As(AngleUnit.Milliradian), MilliradiansTolerance); - AssertEx.EqualTolerance(NanodegreesInOneDegree, degree.As(AngleUnit.Nanodegree), NanodegreesTolerance); - AssertEx.EqualTolerance(NanoradiansInOneDegree, degree.As(AngleUnit.Nanoradian), NanoradiansTolerance); - AssertEx.EqualTolerance(RadiansInOneDegree, degree.As(AngleUnit.Radian), RadiansTolerance); - AssertEx.EqualTolerance(RevolutionsInOneDegree, degree.As(AngleUnit.Revolution), RevolutionsTolerance); - } - - [Fact] - public void ToUnit() - { - var degree = Angle.FromDegrees(1); - - var arcminuteQuantity = degree.ToUnit(AngleUnit.Arcminute); - AssertEx.EqualTolerance(ArcminutesInOneDegree, (double)arcminuteQuantity.Value, ArcminutesTolerance); - Assert.Equal(AngleUnit.Arcminute, arcminuteQuantity.Unit); - - var arcsecondQuantity = degree.ToUnit(AngleUnit.Arcsecond); - AssertEx.EqualTolerance(ArcsecondsInOneDegree, (double)arcsecondQuantity.Value, ArcsecondsTolerance); - Assert.Equal(AngleUnit.Arcsecond, arcsecondQuantity.Unit); - - var centiradianQuantity = degree.ToUnit(AngleUnit.Centiradian); - AssertEx.EqualTolerance(CentiradiansInOneDegree, (double)centiradianQuantity.Value, CentiradiansTolerance); - Assert.Equal(AngleUnit.Centiradian, centiradianQuantity.Unit); - - var deciradianQuantity = degree.ToUnit(AngleUnit.Deciradian); - AssertEx.EqualTolerance(DeciradiansInOneDegree, (double)deciradianQuantity.Value, DeciradiansTolerance); - Assert.Equal(AngleUnit.Deciradian, deciradianQuantity.Unit); - - var degreeQuantity = degree.ToUnit(AngleUnit.Degree); - AssertEx.EqualTolerance(DegreesInOneDegree, (double)degreeQuantity.Value, DegreesTolerance); - Assert.Equal(AngleUnit.Degree, degreeQuantity.Unit); - - var gradianQuantity = degree.ToUnit(AngleUnit.Gradian); - AssertEx.EqualTolerance(GradiansInOneDegree, (double)gradianQuantity.Value, GradiansTolerance); - Assert.Equal(AngleUnit.Gradian, gradianQuantity.Unit); - - var microdegreeQuantity = degree.ToUnit(AngleUnit.Microdegree); - AssertEx.EqualTolerance(MicrodegreesInOneDegree, (double)microdegreeQuantity.Value, MicrodegreesTolerance); - Assert.Equal(AngleUnit.Microdegree, microdegreeQuantity.Unit); - - var microradianQuantity = degree.ToUnit(AngleUnit.Microradian); - AssertEx.EqualTolerance(MicroradiansInOneDegree, (double)microradianQuantity.Value, MicroradiansTolerance); - Assert.Equal(AngleUnit.Microradian, microradianQuantity.Unit); - - var millidegreeQuantity = degree.ToUnit(AngleUnit.Millidegree); - AssertEx.EqualTolerance(MillidegreesInOneDegree, (double)millidegreeQuantity.Value, MillidegreesTolerance); - Assert.Equal(AngleUnit.Millidegree, millidegreeQuantity.Unit); - - var milliradianQuantity = degree.ToUnit(AngleUnit.Milliradian); - AssertEx.EqualTolerance(MilliradiansInOneDegree, (double)milliradianQuantity.Value, MilliradiansTolerance); - Assert.Equal(AngleUnit.Milliradian, milliradianQuantity.Unit); - - var nanodegreeQuantity = degree.ToUnit(AngleUnit.Nanodegree); - AssertEx.EqualTolerance(NanodegreesInOneDegree, (double)nanodegreeQuantity.Value, NanodegreesTolerance); - Assert.Equal(AngleUnit.Nanodegree, nanodegreeQuantity.Unit); - - var nanoradianQuantity = degree.ToUnit(AngleUnit.Nanoradian); - AssertEx.EqualTolerance(NanoradiansInOneDegree, (double)nanoradianQuantity.Value, NanoradiansTolerance); - Assert.Equal(AngleUnit.Nanoradian, nanoradianQuantity.Unit); - - var radianQuantity = degree.ToUnit(AngleUnit.Radian); - AssertEx.EqualTolerance(RadiansInOneDegree, (double)radianQuantity.Value, RadiansTolerance); - Assert.Equal(AngleUnit.Radian, radianQuantity.Unit); - - var revolutionQuantity = degree.ToUnit(AngleUnit.Revolution); - AssertEx.EqualTolerance(RevolutionsInOneDegree, (double)revolutionQuantity.Value, RevolutionsTolerance); - Assert.Equal(AngleUnit.Revolution, revolutionQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Angle degree = Angle.FromDegrees(1); - AssertEx.EqualTolerance(1, Angle.FromArcminutes(degree.Arcminutes).Degrees, ArcminutesTolerance); - AssertEx.EqualTolerance(1, Angle.FromArcseconds(degree.Arcseconds).Degrees, ArcsecondsTolerance); - AssertEx.EqualTolerance(1, Angle.FromCentiradians(degree.Centiradians).Degrees, CentiradiansTolerance); - AssertEx.EqualTolerance(1, Angle.FromDeciradians(degree.Deciradians).Degrees, DeciradiansTolerance); - AssertEx.EqualTolerance(1, Angle.FromDegrees(degree.Degrees).Degrees, DegreesTolerance); - AssertEx.EqualTolerance(1, Angle.FromGradians(degree.Gradians).Degrees, GradiansTolerance); - AssertEx.EqualTolerance(1, Angle.FromMicrodegrees(degree.Microdegrees).Degrees, MicrodegreesTolerance); - AssertEx.EqualTolerance(1, Angle.FromMicroradians(degree.Microradians).Degrees, MicroradiansTolerance); - AssertEx.EqualTolerance(1, Angle.FromMillidegrees(degree.Millidegrees).Degrees, MillidegreesTolerance); - AssertEx.EqualTolerance(1, Angle.FromMilliradians(degree.Milliradians).Degrees, MilliradiansTolerance); - AssertEx.EqualTolerance(1, Angle.FromNanodegrees(degree.Nanodegrees).Degrees, NanodegreesTolerance); - AssertEx.EqualTolerance(1, Angle.FromNanoradians(degree.Nanoradians).Degrees, NanoradiansTolerance); - AssertEx.EqualTolerance(1, Angle.FromRadians(degree.Radians).Degrees, RadiansTolerance); - AssertEx.EqualTolerance(1, Angle.FromRevolutions(degree.Revolutions).Degrees, RevolutionsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Angle v = Angle.FromDegrees(1); - AssertEx.EqualTolerance(-1, -v.Degrees, DegreesTolerance); - AssertEx.EqualTolerance(2, (Angle.FromDegrees(3)-v).Degrees, DegreesTolerance); - AssertEx.EqualTolerance(2, (v + v).Degrees, DegreesTolerance); - AssertEx.EqualTolerance(10, (v*10).Degrees, DegreesTolerance); - AssertEx.EqualTolerance(10, (10*v).Degrees, DegreesTolerance); - AssertEx.EqualTolerance(2, (Angle.FromDegrees(10)/5).Degrees, DegreesTolerance); - AssertEx.EqualTolerance(2, Angle.FromDegrees(10)/Angle.FromDegrees(5), DegreesTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Angle oneDegree = Angle.FromDegrees(1); - Angle twoDegrees = Angle.FromDegrees(2); - - Assert.True(oneDegree < twoDegrees); - Assert.True(oneDegree <= twoDegrees); - Assert.True(twoDegrees > oneDegree); - Assert.True(twoDegrees >= oneDegree); - - Assert.False(oneDegree > twoDegrees); - Assert.False(oneDegree >= twoDegrees); - Assert.False(twoDegrees < oneDegree); - Assert.False(twoDegrees <= oneDegree); - } - - [Fact] - public void CompareToIsImplemented() - { - Angle degree = Angle.FromDegrees(1); - Assert.Equal(0, degree.CompareTo(degree)); - Assert.True(degree.CompareTo(Angle.Zero) > 0); - Assert.True(Angle.Zero.CompareTo(degree) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Angle degree = Angle.FromDegrees(1); - Assert.Throws(() => degree.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Angle degree = Angle.FromDegrees(1); - Assert.Throws(() => degree.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Angle v = Angle.FromDegrees(1); - Assert.True(v.Equals(Angle.FromDegrees(1), DegreesTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Angle.Zero, DegreesTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Angle degree = Angle.FromDegrees(1); - Assert.False(degree.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Angle degree = Angle.FromDegrees(1); - Assert.False(degree.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(AngleUnit.Undefined, Angle.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(AngleUnit)).Cast(); - foreach(var unit in units) - { - if(unit == AngleUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ApparentEnergyTestsBase.g.cs deleted file mode 100644 index fa4c403cd7..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ApparentEnergyTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ApparentEnergy. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ApparentEnergyTestsBase - { - protected abstract double KilovoltampereHoursInOneVoltampereHour { get; } - protected abstract double MegavoltampereHoursInOneVoltampereHour { get; } - protected abstract double VoltampereHoursInOneVoltampereHour { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilovoltampereHoursTolerance { get { return 1e-5; } } - protected virtual double MegavoltampereHoursTolerance { get { return 1e-5; } } - protected virtual double VoltampereHoursTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ApparentEnergy((double)0.0, ApparentEnergyUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ApparentEnergy(double.PositiveInfinity, ApparentEnergyUnit.VoltampereHour)); - Assert.Throws(() => new ApparentEnergy(double.NegativeInfinity, ApparentEnergyUnit.VoltampereHour)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ApparentEnergy(double.NaN, ApparentEnergyUnit.VoltampereHour)); - } - - [Fact] - public void VoltampereHourToApparentEnergyUnits() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - AssertEx.EqualTolerance(KilovoltampereHoursInOneVoltampereHour, voltamperehour.KilovoltampereHours, KilovoltampereHoursTolerance); - AssertEx.EqualTolerance(MegavoltampereHoursInOneVoltampereHour, voltamperehour.MegavoltampereHours, MegavoltampereHoursTolerance); - AssertEx.EqualTolerance(VoltampereHoursInOneVoltampereHour, voltamperehour.VoltampereHours, VoltampereHoursTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ApparentEnergy.From(1, ApparentEnergyUnit.KilovoltampereHour).KilovoltampereHours, KilovoltampereHoursTolerance); - AssertEx.EqualTolerance(1, ApparentEnergy.From(1, ApparentEnergyUnit.MegavoltampereHour).MegavoltampereHours, MegavoltampereHoursTolerance); - AssertEx.EqualTolerance(1, ApparentEnergy.From(1, ApparentEnergyUnit.VoltampereHour).VoltampereHours, VoltampereHoursTolerance); - } - - [Fact] - public void FromVoltampereHours_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ApparentEnergy.FromVoltampereHours(double.PositiveInfinity)); - Assert.Throws(() => ApparentEnergy.FromVoltampereHours(double.NegativeInfinity)); - } - - [Fact] - public void FromVoltampereHours_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ApparentEnergy.FromVoltampereHours(double.NaN)); - } - - [Fact] - public void As() - { - var voltamperehour = ApparentEnergy.FromVoltampereHours(1); - AssertEx.EqualTolerance(KilovoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.KilovoltampereHour), KilovoltampereHoursTolerance); - AssertEx.EqualTolerance(MegavoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.MegavoltampereHour), MegavoltampereHoursTolerance); - AssertEx.EqualTolerance(VoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.VoltampereHour), VoltampereHoursTolerance); - } - - [Fact] - public void ToUnit() - { - var voltamperehour = ApparentEnergy.FromVoltampereHours(1); - - var kilovoltamperehourQuantity = voltamperehour.ToUnit(ApparentEnergyUnit.KilovoltampereHour); - AssertEx.EqualTolerance(KilovoltampereHoursInOneVoltampereHour, (double)kilovoltamperehourQuantity.Value, KilovoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.KilovoltampereHour, kilovoltamperehourQuantity.Unit); - - var megavoltamperehourQuantity = voltamperehour.ToUnit(ApparentEnergyUnit.MegavoltampereHour); - AssertEx.EqualTolerance(MegavoltampereHoursInOneVoltampereHour, (double)megavoltamperehourQuantity.Value, MegavoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.MegavoltampereHour, megavoltamperehourQuantity.Unit); - - var voltamperehourQuantity = voltamperehour.ToUnit(ApparentEnergyUnit.VoltampereHour); - AssertEx.EqualTolerance(VoltampereHoursInOneVoltampereHour, (double)voltamperehourQuantity.Value, VoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.VoltampereHour, voltamperehourQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - AssertEx.EqualTolerance(1, ApparentEnergy.FromKilovoltampereHours(voltamperehour.KilovoltampereHours).VoltampereHours, KilovoltampereHoursTolerance); - AssertEx.EqualTolerance(1, ApparentEnergy.FromMegavoltampereHours(voltamperehour.MegavoltampereHours).VoltampereHours, MegavoltampereHoursTolerance); - AssertEx.EqualTolerance(1, ApparentEnergy.FromVoltampereHours(voltamperehour.VoltampereHours).VoltampereHours, VoltampereHoursTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ApparentEnergy v = ApparentEnergy.FromVoltampereHours(1); - AssertEx.EqualTolerance(-1, -v.VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(2, (ApparentEnergy.FromVoltampereHours(3)-v).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(2, (ApparentEnergy.FromVoltampereHours(10)/5).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(2, ApparentEnergy.FromVoltampereHours(10)/ApparentEnergy.FromVoltampereHours(5), VoltampereHoursTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ApparentEnergy oneVoltampereHour = ApparentEnergy.FromVoltampereHours(1); - ApparentEnergy twoVoltampereHours = ApparentEnergy.FromVoltampereHours(2); - - Assert.True(oneVoltampereHour < twoVoltampereHours); - Assert.True(oneVoltampereHour <= twoVoltampereHours); - Assert.True(twoVoltampereHours > oneVoltampereHour); - Assert.True(twoVoltampereHours >= oneVoltampereHour); - - Assert.False(oneVoltampereHour > twoVoltampereHours); - Assert.False(oneVoltampereHour >= twoVoltampereHours); - Assert.False(twoVoltampereHours < oneVoltampereHour); - Assert.False(twoVoltampereHours <= oneVoltampereHour); - } - - [Fact] - public void CompareToIsImplemented() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.Equal(0, voltamperehour.CompareTo(voltamperehour)); - Assert.True(voltamperehour.CompareTo(ApparentEnergy.Zero) > 0); - Assert.True(ApparentEnergy.Zero.CompareTo(voltamperehour) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.Throws(() => voltamperehour.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.Throws(() => voltamperehour.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ApparentEnergy v = ApparentEnergy.FromVoltampereHours(1); - Assert.True(v.Equals(ApparentEnergy.FromVoltampereHours(1), VoltampereHoursTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ApparentEnergy.Zero, VoltampereHoursTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.False(voltamperehour.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.False(voltamperehour.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ApparentEnergyUnit.Undefined, ApparentEnergy.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ApparentEnergyUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ApparentEnergyUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ApparentPowerTestsBase.g.cs deleted file mode 100644 index 061fbb9aae..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ApparentPowerTestsBase.g.cs +++ /dev/null @@ -1,254 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ApparentPower. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ApparentPowerTestsBase - { - protected abstract double GigavoltamperesInOneVoltampere { get; } - protected abstract double KilovoltamperesInOneVoltampere { get; } - protected abstract double MegavoltamperesInOneVoltampere { get; } - protected abstract double VoltamperesInOneVoltampere { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double GigavoltamperesTolerance { get { return 1e-5; } } - protected virtual double KilovoltamperesTolerance { get { return 1e-5; } } - protected virtual double MegavoltamperesTolerance { get { return 1e-5; } } - protected virtual double VoltamperesTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ApparentPower((double)0.0, ApparentPowerUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ApparentPower(double.PositiveInfinity, ApparentPowerUnit.Voltampere)); - Assert.Throws(() => new ApparentPower(double.NegativeInfinity, ApparentPowerUnit.Voltampere)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ApparentPower(double.NaN, ApparentPowerUnit.Voltampere)); - } - - [Fact] - public void VoltampereToApparentPowerUnits() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - AssertEx.EqualTolerance(GigavoltamperesInOneVoltampere, voltampere.Gigavoltamperes, GigavoltamperesTolerance); - AssertEx.EqualTolerance(KilovoltamperesInOneVoltampere, voltampere.Kilovoltamperes, KilovoltamperesTolerance); - AssertEx.EqualTolerance(MegavoltamperesInOneVoltampere, voltampere.Megavoltamperes, MegavoltamperesTolerance); - AssertEx.EqualTolerance(VoltamperesInOneVoltampere, voltampere.Voltamperes, VoltamperesTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ApparentPower.From(1, ApparentPowerUnit.Gigavoltampere).Gigavoltamperes, GigavoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.From(1, ApparentPowerUnit.Kilovoltampere).Kilovoltamperes, KilovoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.From(1, ApparentPowerUnit.Megavoltampere).Megavoltamperes, MegavoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.From(1, ApparentPowerUnit.Voltampere).Voltamperes, VoltamperesTolerance); - } - - [Fact] - public void FromVoltamperes_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ApparentPower.FromVoltamperes(double.PositiveInfinity)); - Assert.Throws(() => ApparentPower.FromVoltamperes(double.NegativeInfinity)); - } - - [Fact] - public void FromVoltamperes_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ApparentPower.FromVoltamperes(double.NaN)); - } - - [Fact] - public void As() - { - var voltampere = ApparentPower.FromVoltamperes(1); - AssertEx.EqualTolerance(GigavoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Gigavoltampere), GigavoltamperesTolerance); - AssertEx.EqualTolerance(KilovoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Kilovoltampere), KilovoltamperesTolerance); - AssertEx.EqualTolerance(MegavoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Megavoltampere), MegavoltamperesTolerance); - AssertEx.EqualTolerance(VoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Voltampere), VoltamperesTolerance); - } - - [Fact] - public void ToUnit() - { - var voltampere = ApparentPower.FromVoltamperes(1); - - var gigavoltampereQuantity = voltampere.ToUnit(ApparentPowerUnit.Gigavoltampere); - AssertEx.EqualTolerance(GigavoltamperesInOneVoltampere, (double)gigavoltampereQuantity.Value, GigavoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Gigavoltampere, gigavoltampereQuantity.Unit); - - var kilovoltampereQuantity = voltampere.ToUnit(ApparentPowerUnit.Kilovoltampere); - AssertEx.EqualTolerance(KilovoltamperesInOneVoltampere, (double)kilovoltampereQuantity.Value, KilovoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Kilovoltampere, kilovoltampereQuantity.Unit); - - var megavoltampereQuantity = voltampere.ToUnit(ApparentPowerUnit.Megavoltampere); - AssertEx.EqualTolerance(MegavoltamperesInOneVoltampere, (double)megavoltampereQuantity.Value, MegavoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Megavoltampere, megavoltampereQuantity.Unit); - - var voltampereQuantity = voltampere.ToUnit(ApparentPowerUnit.Voltampere); - AssertEx.EqualTolerance(VoltamperesInOneVoltampere, (double)voltampereQuantity.Value, VoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Voltampere, voltampereQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - AssertEx.EqualTolerance(1, ApparentPower.FromGigavoltamperes(voltampere.Gigavoltamperes).Voltamperes, GigavoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.FromKilovoltamperes(voltampere.Kilovoltamperes).Voltamperes, KilovoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.FromMegavoltamperes(voltampere.Megavoltamperes).Voltamperes, MegavoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.FromVoltamperes(voltampere.Voltamperes).Voltamperes, VoltamperesTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ApparentPower v = ApparentPower.FromVoltamperes(1); - AssertEx.EqualTolerance(-1, -v.Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(2, (ApparentPower.FromVoltamperes(3)-v).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(2, (v + v).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(10, (v*10).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(10, (10*v).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(2, (ApparentPower.FromVoltamperes(10)/5).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(2, ApparentPower.FromVoltamperes(10)/ApparentPower.FromVoltamperes(5), VoltamperesTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ApparentPower oneVoltampere = ApparentPower.FromVoltamperes(1); - ApparentPower twoVoltamperes = ApparentPower.FromVoltamperes(2); - - Assert.True(oneVoltampere < twoVoltamperes); - Assert.True(oneVoltampere <= twoVoltamperes); - Assert.True(twoVoltamperes > oneVoltampere); - Assert.True(twoVoltamperes >= oneVoltampere); - - Assert.False(oneVoltampere > twoVoltamperes); - Assert.False(oneVoltampere >= twoVoltamperes); - Assert.False(twoVoltamperes < oneVoltampere); - Assert.False(twoVoltamperes <= oneVoltampere); - } - - [Fact] - public void CompareToIsImplemented() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.Equal(0, voltampere.CompareTo(voltampere)); - Assert.True(voltampere.CompareTo(ApparentPower.Zero) > 0); - Assert.True(ApparentPower.Zero.CompareTo(voltampere) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.Throws(() => voltampere.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.Throws(() => voltampere.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ApparentPower v = ApparentPower.FromVoltamperes(1); - Assert.True(v.Equals(ApparentPower.FromVoltamperes(1), VoltamperesTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ApparentPower.Zero, VoltamperesTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.False(voltampere.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.False(voltampere.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ApparentPowerUnit.Undefined, ApparentPower.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ApparentPowerUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ApparentPowerUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/AreaDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/AreaDensityTestsBase.g.cs deleted file mode 100644 index b6120fd28a..0000000000 --- a/UnitsNet.Tests/GeneratedCode/AreaDensityTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of AreaDensity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AreaDensityTestsBase - { - protected abstract double KilogramsPerSquareMeterInOneKilogramPerSquareMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilogramsPerSquareMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new AreaDensity((double)0.0, AreaDensityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new AreaDensity(double.PositiveInfinity, AreaDensityUnit.KilogramPerSquareMeter)); - Assert.Throws(() => new AreaDensity(double.NegativeInfinity, AreaDensityUnit.KilogramPerSquareMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new AreaDensity(double.NaN, AreaDensityUnit.KilogramPerSquareMeter)); - } - - [Fact] - public void KilogramPerSquareMeterToAreaDensityUnits() - { - AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1); - AssertEx.EqualTolerance(KilogramsPerSquareMeterInOneKilogramPerSquareMeter, kilogrampersquaremeter.KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, AreaDensity.From(1, AreaDensityUnit.KilogramPerSquareMeter).KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - } - - [Fact] - public void FromKilogramsPerSquareMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => AreaDensity.FromKilogramsPerSquareMeter(double.PositiveInfinity)); - Assert.Throws(() => AreaDensity.FromKilogramsPerSquareMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromKilogramsPerSquareMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => AreaDensity.FromKilogramsPerSquareMeter(double.NaN)); - } - - [Fact] - public void As() - { - var kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1); - AssertEx.EqualTolerance(KilogramsPerSquareMeterInOneKilogramPerSquareMeter, kilogrampersquaremeter.As(AreaDensityUnit.KilogramPerSquareMeter), KilogramsPerSquareMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1); - - var kilogrampersquaremeterQuantity = kilogrampersquaremeter.ToUnit(AreaDensityUnit.KilogramPerSquareMeter); - AssertEx.EqualTolerance(KilogramsPerSquareMeterInOneKilogramPerSquareMeter, (double)kilogrampersquaremeterQuantity.Value, KilogramsPerSquareMeterTolerance); - Assert.Equal(AreaDensityUnit.KilogramPerSquareMeter, kilogrampersquaremeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1); - AssertEx.EqualTolerance(1, AreaDensity.FromKilogramsPerSquareMeter(kilogrampersquaremeter.KilogramsPerSquareMeter).KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - AreaDensity v = AreaDensity.FromKilogramsPerSquareMeter(1); - AssertEx.EqualTolerance(-1, -v.KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (AreaDensity.FromKilogramsPerSquareMeter(3)-v).KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (AreaDensity.FromKilogramsPerSquareMeter(10)/5).KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, AreaDensity.FromKilogramsPerSquareMeter(10)/AreaDensity.FromKilogramsPerSquareMeter(5), KilogramsPerSquareMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - AreaDensity oneKilogramPerSquareMeter = AreaDensity.FromKilogramsPerSquareMeter(1); - AreaDensity twoKilogramsPerSquareMeter = AreaDensity.FromKilogramsPerSquareMeter(2); - - Assert.True(oneKilogramPerSquareMeter < twoKilogramsPerSquareMeter); - Assert.True(oneKilogramPerSquareMeter <= twoKilogramsPerSquareMeter); - Assert.True(twoKilogramsPerSquareMeter > oneKilogramPerSquareMeter); - Assert.True(twoKilogramsPerSquareMeter >= oneKilogramPerSquareMeter); - - Assert.False(oneKilogramPerSquareMeter > twoKilogramsPerSquareMeter); - Assert.False(oneKilogramPerSquareMeter >= twoKilogramsPerSquareMeter); - Assert.False(twoKilogramsPerSquareMeter < oneKilogramPerSquareMeter); - Assert.False(twoKilogramsPerSquareMeter <= oneKilogramPerSquareMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1); - Assert.Equal(0, kilogrampersquaremeter.CompareTo(kilogrampersquaremeter)); - Assert.True(kilogrampersquaremeter.CompareTo(AreaDensity.Zero) > 0); - Assert.True(AreaDensity.Zero.CompareTo(kilogrampersquaremeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1); - Assert.Throws(() => kilogrampersquaremeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1); - Assert.Throws(() => kilogrampersquaremeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - AreaDensity v = AreaDensity.FromKilogramsPerSquareMeter(1); - Assert.True(v.Equals(AreaDensity.FromKilogramsPerSquareMeter(1), KilogramsPerSquareMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(AreaDensity.Zero, KilogramsPerSquareMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1); - Assert.False(kilogrampersquaremeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1); - Assert.False(kilogrampersquaremeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(AreaDensityUnit.Undefined, AreaDensity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(AreaDensityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == AreaDensityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/AreaMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/AreaMomentOfInertiaTestsBase.g.cs deleted file mode 100644 index 10207a9f29..0000000000 --- a/UnitsNet.Tests/GeneratedCode/AreaMomentOfInertiaTestsBase.g.cs +++ /dev/null @@ -1,274 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of AreaMomentOfInertia. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AreaMomentOfInertiaTestsBase - { - protected abstract double CentimetersToTheFourthInOneMeterToTheFourth { get; } - protected abstract double DecimetersToTheFourthInOneMeterToTheFourth { get; } - protected abstract double FeetToTheFourthInOneMeterToTheFourth { get; } - protected abstract double InchesToTheFourthInOneMeterToTheFourth { get; } - protected abstract double MetersToTheFourthInOneMeterToTheFourth { get; } - protected abstract double MillimetersToTheFourthInOneMeterToTheFourth { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentimetersToTheFourthTolerance { get { return 1e-5; } } - protected virtual double DecimetersToTheFourthTolerance { get { return 1e-5; } } - protected virtual double FeetToTheFourthTolerance { get { return 1e-5; } } - protected virtual double InchesToTheFourthTolerance { get { return 1e-5; } } - protected virtual double MetersToTheFourthTolerance { get { return 1e-5; } } - protected virtual double MillimetersToTheFourthTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new AreaMomentOfInertia((double)0.0, AreaMomentOfInertiaUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new AreaMomentOfInertia(double.PositiveInfinity, AreaMomentOfInertiaUnit.MeterToTheFourth)); - Assert.Throws(() => new AreaMomentOfInertia(double.NegativeInfinity, AreaMomentOfInertiaUnit.MeterToTheFourth)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new AreaMomentOfInertia(double.NaN, AreaMomentOfInertiaUnit.MeterToTheFourth)); - } - - [Fact] - public void MeterToTheFourthToAreaMomentOfInertiaUnits() - { - AreaMomentOfInertia metertothefourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - AssertEx.EqualTolerance(CentimetersToTheFourthInOneMeterToTheFourth, metertothefourth.CentimetersToTheFourth, CentimetersToTheFourthTolerance); - AssertEx.EqualTolerance(DecimetersToTheFourthInOneMeterToTheFourth, metertothefourth.DecimetersToTheFourth, DecimetersToTheFourthTolerance); - AssertEx.EqualTolerance(FeetToTheFourthInOneMeterToTheFourth, metertothefourth.FeetToTheFourth, FeetToTheFourthTolerance); - AssertEx.EqualTolerance(InchesToTheFourthInOneMeterToTheFourth, metertothefourth.InchesToTheFourth, InchesToTheFourthTolerance); - AssertEx.EqualTolerance(MetersToTheFourthInOneMeterToTheFourth, metertothefourth.MetersToTheFourth, MetersToTheFourthTolerance); - AssertEx.EqualTolerance(MillimetersToTheFourthInOneMeterToTheFourth, metertothefourth.MillimetersToTheFourth, MillimetersToTheFourthTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, AreaMomentOfInertia.From(1, AreaMomentOfInertiaUnit.CentimeterToTheFourth).CentimetersToTheFourth, CentimetersToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.From(1, AreaMomentOfInertiaUnit.DecimeterToTheFourth).DecimetersToTheFourth, DecimetersToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.From(1, AreaMomentOfInertiaUnit.FootToTheFourth).FeetToTheFourth, FeetToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.From(1, AreaMomentOfInertiaUnit.InchToTheFourth).InchesToTheFourth, InchesToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.From(1, AreaMomentOfInertiaUnit.MeterToTheFourth).MetersToTheFourth, MetersToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.From(1, AreaMomentOfInertiaUnit.MillimeterToTheFourth).MillimetersToTheFourth, MillimetersToTheFourthTolerance); - } - - [Fact] - public void FromMetersToTheFourth_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => AreaMomentOfInertia.FromMetersToTheFourth(double.PositiveInfinity)); - Assert.Throws(() => AreaMomentOfInertia.FromMetersToTheFourth(double.NegativeInfinity)); - } - - [Fact] - public void FromMetersToTheFourth_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => AreaMomentOfInertia.FromMetersToTheFourth(double.NaN)); - } - - [Fact] - public void As() - { - var metertothefourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - AssertEx.EqualTolerance(CentimetersToTheFourthInOneMeterToTheFourth, metertothefourth.As(AreaMomentOfInertiaUnit.CentimeterToTheFourth), CentimetersToTheFourthTolerance); - AssertEx.EqualTolerance(DecimetersToTheFourthInOneMeterToTheFourth, metertothefourth.As(AreaMomentOfInertiaUnit.DecimeterToTheFourth), DecimetersToTheFourthTolerance); - AssertEx.EqualTolerance(FeetToTheFourthInOneMeterToTheFourth, metertothefourth.As(AreaMomentOfInertiaUnit.FootToTheFourth), FeetToTheFourthTolerance); - AssertEx.EqualTolerance(InchesToTheFourthInOneMeterToTheFourth, metertothefourth.As(AreaMomentOfInertiaUnit.InchToTheFourth), InchesToTheFourthTolerance); - AssertEx.EqualTolerance(MetersToTheFourthInOneMeterToTheFourth, metertothefourth.As(AreaMomentOfInertiaUnit.MeterToTheFourth), MetersToTheFourthTolerance); - AssertEx.EqualTolerance(MillimetersToTheFourthInOneMeterToTheFourth, metertothefourth.As(AreaMomentOfInertiaUnit.MillimeterToTheFourth), MillimetersToTheFourthTolerance); - } - - [Fact] - public void ToUnit() - { - var metertothefourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - - var centimetertothefourthQuantity = metertothefourth.ToUnit(AreaMomentOfInertiaUnit.CentimeterToTheFourth); - AssertEx.EqualTolerance(CentimetersToTheFourthInOneMeterToTheFourth, (double)centimetertothefourthQuantity.Value, CentimetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.CentimeterToTheFourth, centimetertothefourthQuantity.Unit); - - var decimetertothefourthQuantity = metertothefourth.ToUnit(AreaMomentOfInertiaUnit.DecimeterToTheFourth); - AssertEx.EqualTolerance(DecimetersToTheFourthInOneMeterToTheFourth, (double)decimetertothefourthQuantity.Value, DecimetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.DecimeterToTheFourth, decimetertothefourthQuantity.Unit); - - var foottothefourthQuantity = metertothefourth.ToUnit(AreaMomentOfInertiaUnit.FootToTheFourth); - AssertEx.EqualTolerance(FeetToTheFourthInOneMeterToTheFourth, (double)foottothefourthQuantity.Value, FeetToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.FootToTheFourth, foottothefourthQuantity.Unit); - - var inchtothefourthQuantity = metertothefourth.ToUnit(AreaMomentOfInertiaUnit.InchToTheFourth); - AssertEx.EqualTolerance(InchesToTheFourthInOneMeterToTheFourth, (double)inchtothefourthQuantity.Value, InchesToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.InchToTheFourth, inchtothefourthQuantity.Unit); - - var metertothefourthQuantity = metertothefourth.ToUnit(AreaMomentOfInertiaUnit.MeterToTheFourth); - AssertEx.EqualTolerance(MetersToTheFourthInOneMeterToTheFourth, (double)metertothefourthQuantity.Value, MetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.MeterToTheFourth, metertothefourthQuantity.Unit); - - var millimetertothefourthQuantity = metertothefourth.ToUnit(AreaMomentOfInertiaUnit.MillimeterToTheFourth); - AssertEx.EqualTolerance(MillimetersToTheFourthInOneMeterToTheFourth, (double)millimetertothefourthQuantity.Value, MillimetersToTheFourthTolerance); - Assert.Equal(AreaMomentOfInertiaUnit.MillimeterToTheFourth, millimetertothefourthQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - AreaMomentOfInertia metertothefourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.FromCentimetersToTheFourth(metertothefourth.CentimetersToTheFourth).MetersToTheFourth, CentimetersToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.FromDecimetersToTheFourth(metertothefourth.DecimetersToTheFourth).MetersToTheFourth, DecimetersToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.FromFeetToTheFourth(metertothefourth.FeetToTheFourth).MetersToTheFourth, FeetToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.FromInchesToTheFourth(metertothefourth.InchesToTheFourth).MetersToTheFourth, InchesToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.FromMetersToTheFourth(metertothefourth.MetersToTheFourth).MetersToTheFourth, MetersToTheFourthTolerance); - AssertEx.EqualTolerance(1, AreaMomentOfInertia.FromMillimetersToTheFourth(metertothefourth.MillimetersToTheFourth).MetersToTheFourth, MillimetersToTheFourthTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - AreaMomentOfInertia v = AreaMomentOfInertia.FromMetersToTheFourth(1); - AssertEx.EqualTolerance(-1, -v.MetersToTheFourth, MetersToTheFourthTolerance); - AssertEx.EqualTolerance(2, (AreaMomentOfInertia.FromMetersToTheFourth(3)-v).MetersToTheFourth, MetersToTheFourthTolerance); - AssertEx.EqualTolerance(2, (v + v).MetersToTheFourth, MetersToTheFourthTolerance); - AssertEx.EqualTolerance(10, (v*10).MetersToTheFourth, MetersToTheFourthTolerance); - AssertEx.EqualTolerance(10, (10*v).MetersToTheFourth, MetersToTheFourthTolerance); - AssertEx.EqualTolerance(2, (AreaMomentOfInertia.FromMetersToTheFourth(10)/5).MetersToTheFourth, MetersToTheFourthTolerance); - AssertEx.EqualTolerance(2, AreaMomentOfInertia.FromMetersToTheFourth(10)/AreaMomentOfInertia.FromMetersToTheFourth(5), MetersToTheFourthTolerance); - } - - [Fact] - public void ComparisonOperators() - { - AreaMomentOfInertia oneMeterToTheFourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - AreaMomentOfInertia twoMetersToTheFourth = AreaMomentOfInertia.FromMetersToTheFourth(2); - - Assert.True(oneMeterToTheFourth < twoMetersToTheFourth); - Assert.True(oneMeterToTheFourth <= twoMetersToTheFourth); - Assert.True(twoMetersToTheFourth > oneMeterToTheFourth); - Assert.True(twoMetersToTheFourth >= oneMeterToTheFourth); - - Assert.False(oneMeterToTheFourth > twoMetersToTheFourth); - Assert.False(oneMeterToTheFourth >= twoMetersToTheFourth); - Assert.False(twoMetersToTheFourth < oneMeterToTheFourth); - Assert.False(twoMetersToTheFourth <= oneMeterToTheFourth); - } - - [Fact] - public void CompareToIsImplemented() - { - AreaMomentOfInertia metertothefourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - Assert.Equal(0, metertothefourth.CompareTo(metertothefourth)); - Assert.True(metertothefourth.CompareTo(AreaMomentOfInertia.Zero) > 0); - Assert.True(AreaMomentOfInertia.Zero.CompareTo(metertothefourth) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - AreaMomentOfInertia metertothefourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - Assert.Throws(() => metertothefourth.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - AreaMomentOfInertia metertothefourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - Assert.Throws(() => metertothefourth.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - AreaMomentOfInertia v = AreaMomentOfInertia.FromMetersToTheFourth(1); - Assert.True(v.Equals(AreaMomentOfInertia.FromMetersToTheFourth(1), MetersToTheFourthTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(AreaMomentOfInertia.Zero, MetersToTheFourthTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - AreaMomentOfInertia metertothefourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - Assert.False(metertothefourth.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - AreaMomentOfInertia metertothefourth = AreaMomentOfInertia.FromMetersToTheFourth(1); - Assert.False(metertothefourth.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(AreaMomentOfInertiaUnit.Undefined, AreaMomentOfInertia.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(AreaMomentOfInertiaUnit)).Cast(); - foreach(var unit in units) - { - if(unit == AreaMomentOfInertiaUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/AreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/AreaTestsBase.g.cs deleted file mode 100644 index 205d6d77df..0000000000 --- a/UnitsNet.Tests/GeneratedCode/AreaTestsBase.g.cs +++ /dev/null @@ -1,344 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Area. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AreaTestsBase - { - protected abstract double AcresInOneSquareMeter { get; } - protected abstract double HectaresInOneSquareMeter { get; } - protected abstract double SquareCentimetersInOneSquareMeter { get; } - protected abstract double SquareDecimetersInOneSquareMeter { get; } - protected abstract double SquareFeetInOneSquareMeter { get; } - protected abstract double SquareInchesInOneSquareMeter { get; } - protected abstract double SquareKilometersInOneSquareMeter { get; } - protected abstract double SquareMetersInOneSquareMeter { get; } - protected abstract double SquareMicrometersInOneSquareMeter { get; } - protected abstract double SquareMilesInOneSquareMeter { get; } - protected abstract double SquareMillimetersInOneSquareMeter { get; } - protected abstract double SquareYardsInOneSquareMeter { get; } - protected abstract double UsSurveySquareFeetInOneSquareMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double AcresTolerance { get { return 1e-5; } } - protected virtual double HectaresTolerance { get { return 1e-5; } } - protected virtual double SquareCentimetersTolerance { get { return 1e-5; } } - protected virtual double SquareDecimetersTolerance { get { return 1e-5; } } - protected virtual double SquareFeetTolerance { get { return 1e-5; } } - protected virtual double SquareInchesTolerance { get { return 1e-5; } } - protected virtual double SquareKilometersTolerance { get { return 1e-5; } } - protected virtual double SquareMetersTolerance { get { return 1e-5; } } - protected virtual double SquareMicrometersTolerance { get { return 1e-5; } } - protected virtual double SquareMilesTolerance { get { return 1e-5; } } - protected virtual double SquareMillimetersTolerance { get { return 1e-5; } } - protected virtual double SquareYardsTolerance { get { return 1e-5; } } - protected virtual double UsSurveySquareFeetTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Area((double)0.0, AreaUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Area(double.PositiveInfinity, AreaUnit.SquareMeter)); - Assert.Throws(() => new Area(double.NegativeInfinity, AreaUnit.SquareMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Area(double.NaN, AreaUnit.SquareMeter)); - } - - [Fact] - public void SquareMeterToAreaUnits() - { - Area squaremeter = Area.FromSquareMeters(1); - AssertEx.EqualTolerance(AcresInOneSquareMeter, squaremeter.Acres, AcresTolerance); - AssertEx.EqualTolerance(HectaresInOneSquareMeter, squaremeter.Hectares, HectaresTolerance); - AssertEx.EqualTolerance(SquareCentimetersInOneSquareMeter, squaremeter.SquareCentimeters, SquareCentimetersTolerance); - AssertEx.EqualTolerance(SquareDecimetersInOneSquareMeter, squaremeter.SquareDecimeters, SquareDecimetersTolerance); - AssertEx.EqualTolerance(SquareFeetInOneSquareMeter, squaremeter.SquareFeet, SquareFeetTolerance); - AssertEx.EqualTolerance(SquareInchesInOneSquareMeter, squaremeter.SquareInches, SquareInchesTolerance); - AssertEx.EqualTolerance(SquareKilometersInOneSquareMeter, squaremeter.SquareKilometers, SquareKilometersTolerance); - AssertEx.EqualTolerance(SquareMetersInOneSquareMeter, squaremeter.SquareMeters, SquareMetersTolerance); - AssertEx.EqualTolerance(SquareMicrometersInOneSquareMeter, squaremeter.SquareMicrometers, SquareMicrometersTolerance); - AssertEx.EqualTolerance(SquareMilesInOneSquareMeter, squaremeter.SquareMiles, SquareMilesTolerance); - AssertEx.EqualTolerance(SquareMillimetersInOneSquareMeter, squaremeter.SquareMillimeters, SquareMillimetersTolerance); - AssertEx.EqualTolerance(SquareYardsInOneSquareMeter, squaremeter.SquareYards, SquareYardsTolerance); - AssertEx.EqualTolerance(UsSurveySquareFeetInOneSquareMeter, squaremeter.UsSurveySquareFeet, UsSurveySquareFeetTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.Acre).Acres, AcresTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.Hectare).Hectares, HectaresTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareCentimeter).SquareCentimeters, SquareCentimetersTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareDecimeter).SquareDecimeters, SquareDecimetersTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareFoot).SquareFeet, SquareFeetTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareInch).SquareInches, SquareInchesTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareKilometer).SquareKilometers, SquareKilometersTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareMeter).SquareMeters, SquareMetersTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareMicrometer).SquareMicrometers, SquareMicrometersTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareMile).SquareMiles, SquareMilesTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareMillimeter).SquareMillimeters, SquareMillimetersTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.SquareYard).SquareYards, SquareYardsTolerance); - AssertEx.EqualTolerance(1, Area.From(1, AreaUnit.UsSurveySquareFoot).UsSurveySquareFeet, UsSurveySquareFeetTolerance); - } - - [Fact] - public void FromSquareMeters_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Area.FromSquareMeters(double.PositiveInfinity)); - Assert.Throws(() => Area.FromSquareMeters(double.NegativeInfinity)); - } - - [Fact] - public void FromSquareMeters_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Area.FromSquareMeters(double.NaN)); - } - - [Fact] - public void As() - { - var squaremeter = Area.FromSquareMeters(1); - AssertEx.EqualTolerance(AcresInOneSquareMeter, squaremeter.As(AreaUnit.Acre), AcresTolerance); - AssertEx.EqualTolerance(HectaresInOneSquareMeter, squaremeter.As(AreaUnit.Hectare), HectaresTolerance); - AssertEx.EqualTolerance(SquareCentimetersInOneSquareMeter, squaremeter.As(AreaUnit.SquareCentimeter), SquareCentimetersTolerance); - AssertEx.EqualTolerance(SquareDecimetersInOneSquareMeter, squaremeter.As(AreaUnit.SquareDecimeter), SquareDecimetersTolerance); - AssertEx.EqualTolerance(SquareFeetInOneSquareMeter, squaremeter.As(AreaUnit.SquareFoot), SquareFeetTolerance); - AssertEx.EqualTolerance(SquareInchesInOneSquareMeter, squaremeter.As(AreaUnit.SquareInch), SquareInchesTolerance); - AssertEx.EqualTolerance(SquareKilometersInOneSquareMeter, squaremeter.As(AreaUnit.SquareKilometer), SquareKilometersTolerance); - AssertEx.EqualTolerance(SquareMetersInOneSquareMeter, squaremeter.As(AreaUnit.SquareMeter), SquareMetersTolerance); - AssertEx.EqualTolerance(SquareMicrometersInOneSquareMeter, squaremeter.As(AreaUnit.SquareMicrometer), SquareMicrometersTolerance); - AssertEx.EqualTolerance(SquareMilesInOneSquareMeter, squaremeter.As(AreaUnit.SquareMile), SquareMilesTolerance); - AssertEx.EqualTolerance(SquareMillimetersInOneSquareMeter, squaremeter.As(AreaUnit.SquareMillimeter), SquareMillimetersTolerance); - AssertEx.EqualTolerance(SquareYardsInOneSquareMeter, squaremeter.As(AreaUnit.SquareYard), SquareYardsTolerance); - AssertEx.EqualTolerance(UsSurveySquareFeetInOneSquareMeter, squaremeter.As(AreaUnit.UsSurveySquareFoot), UsSurveySquareFeetTolerance); - } - - [Fact] - public void ToUnit() - { - var squaremeter = Area.FromSquareMeters(1); - - var acreQuantity = squaremeter.ToUnit(AreaUnit.Acre); - AssertEx.EqualTolerance(AcresInOneSquareMeter, (double)acreQuantity.Value, AcresTolerance); - Assert.Equal(AreaUnit.Acre, acreQuantity.Unit); - - var hectareQuantity = squaremeter.ToUnit(AreaUnit.Hectare); - AssertEx.EqualTolerance(HectaresInOneSquareMeter, (double)hectareQuantity.Value, HectaresTolerance); - Assert.Equal(AreaUnit.Hectare, hectareQuantity.Unit); - - var squarecentimeterQuantity = squaremeter.ToUnit(AreaUnit.SquareCentimeter); - AssertEx.EqualTolerance(SquareCentimetersInOneSquareMeter, (double)squarecentimeterQuantity.Value, SquareCentimetersTolerance); - Assert.Equal(AreaUnit.SquareCentimeter, squarecentimeterQuantity.Unit); - - var squaredecimeterQuantity = squaremeter.ToUnit(AreaUnit.SquareDecimeter); - AssertEx.EqualTolerance(SquareDecimetersInOneSquareMeter, (double)squaredecimeterQuantity.Value, SquareDecimetersTolerance); - Assert.Equal(AreaUnit.SquareDecimeter, squaredecimeterQuantity.Unit); - - var squarefootQuantity = squaremeter.ToUnit(AreaUnit.SquareFoot); - AssertEx.EqualTolerance(SquareFeetInOneSquareMeter, (double)squarefootQuantity.Value, SquareFeetTolerance); - Assert.Equal(AreaUnit.SquareFoot, squarefootQuantity.Unit); - - var squareinchQuantity = squaremeter.ToUnit(AreaUnit.SquareInch); - AssertEx.EqualTolerance(SquareInchesInOneSquareMeter, (double)squareinchQuantity.Value, SquareInchesTolerance); - Assert.Equal(AreaUnit.SquareInch, squareinchQuantity.Unit); - - var squarekilometerQuantity = squaremeter.ToUnit(AreaUnit.SquareKilometer); - AssertEx.EqualTolerance(SquareKilometersInOneSquareMeter, (double)squarekilometerQuantity.Value, SquareKilometersTolerance); - Assert.Equal(AreaUnit.SquareKilometer, squarekilometerQuantity.Unit); - - var squaremeterQuantity = squaremeter.ToUnit(AreaUnit.SquareMeter); - AssertEx.EqualTolerance(SquareMetersInOneSquareMeter, (double)squaremeterQuantity.Value, SquareMetersTolerance); - Assert.Equal(AreaUnit.SquareMeter, squaremeterQuantity.Unit); - - var squaremicrometerQuantity = squaremeter.ToUnit(AreaUnit.SquareMicrometer); - AssertEx.EqualTolerance(SquareMicrometersInOneSquareMeter, (double)squaremicrometerQuantity.Value, SquareMicrometersTolerance); - Assert.Equal(AreaUnit.SquareMicrometer, squaremicrometerQuantity.Unit); - - var squaremileQuantity = squaremeter.ToUnit(AreaUnit.SquareMile); - AssertEx.EqualTolerance(SquareMilesInOneSquareMeter, (double)squaremileQuantity.Value, SquareMilesTolerance); - Assert.Equal(AreaUnit.SquareMile, squaremileQuantity.Unit); - - var squaremillimeterQuantity = squaremeter.ToUnit(AreaUnit.SquareMillimeter); - AssertEx.EqualTolerance(SquareMillimetersInOneSquareMeter, (double)squaremillimeterQuantity.Value, SquareMillimetersTolerance); - Assert.Equal(AreaUnit.SquareMillimeter, squaremillimeterQuantity.Unit); - - var squareyardQuantity = squaremeter.ToUnit(AreaUnit.SquareYard); - AssertEx.EqualTolerance(SquareYardsInOneSquareMeter, (double)squareyardQuantity.Value, SquareYardsTolerance); - Assert.Equal(AreaUnit.SquareYard, squareyardQuantity.Unit); - - var ussurveysquarefootQuantity = squaremeter.ToUnit(AreaUnit.UsSurveySquareFoot); - AssertEx.EqualTolerance(UsSurveySquareFeetInOneSquareMeter, (double)ussurveysquarefootQuantity.Value, UsSurveySquareFeetTolerance); - Assert.Equal(AreaUnit.UsSurveySquareFoot, ussurveysquarefootQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Area squaremeter = Area.FromSquareMeters(1); - AssertEx.EqualTolerance(1, Area.FromAcres(squaremeter.Acres).SquareMeters, AcresTolerance); - AssertEx.EqualTolerance(1, Area.FromHectares(squaremeter.Hectares).SquareMeters, HectaresTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareCentimeters(squaremeter.SquareCentimeters).SquareMeters, SquareCentimetersTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareDecimeters(squaremeter.SquareDecimeters).SquareMeters, SquareDecimetersTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareFeet(squaremeter.SquareFeet).SquareMeters, SquareFeetTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareInches(squaremeter.SquareInches).SquareMeters, SquareInchesTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareKilometers(squaremeter.SquareKilometers).SquareMeters, SquareKilometersTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareMeters(squaremeter.SquareMeters).SquareMeters, SquareMetersTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareMicrometers(squaremeter.SquareMicrometers).SquareMeters, SquareMicrometersTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareMiles(squaremeter.SquareMiles).SquareMeters, SquareMilesTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareMillimeters(squaremeter.SquareMillimeters).SquareMeters, SquareMillimetersTolerance); - AssertEx.EqualTolerance(1, Area.FromSquareYards(squaremeter.SquareYards).SquareMeters, SquareYardsTolerance); - AssertEx.EqualTolerance(1, Area.FromUsSurveySquareFeet(squaremeter.UsSurveySquareFeet).SquareMeters, UsSurveySquareFeetTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Area v = Area.FromSquareMeters(1); - AssertEx.EqualTolerance(-1, -v.SquareMeters, SquareMetersTolerance); - AssertEx.EqualTolerance(2, (Area.FromSquareMeters(3)-v).SquareMeters, SquareMetersTolerance); - AssertEx.EqualTolerance(2, (v + v).SquareMeters, SquareMetersTolerance); - AssertEx.EqualTolerance(10, (v*10).SquareMeters, SquareMetersTolerance); - AssertEx.EqualTolerance(10, (10*v).SquareMeters, SquareMetersTolerance); - AssertEx.EqualTolerance(2, (Area.FromSquareMeters(10)/5).SquareMeters, SquareMetersTolerance); - AssertEx.EqualTolerance(2, Area.FromSquareMeters(10)/Area.FromSquareMeters(5), SquareMetersTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Area oneSquareMeter = Area.FromSquareMeters(1); - Area twoSquareMeters = Area.FromSquareMeters(2); - - Assert.True(oneSquareMeter < twoSquareMeters); - Assert.True(oneSquareMeter <= twoSquareMeters); - Assert.True(twoSquareMeters > oneSquareMeter); - Assert.True(twoSquareMeters >= oneSquareMeter); - - Assert.False(oneSquareMeter > twoSquareMeters); - Assert.False(oneSquareMeter >= twoSquareMeters); - Assert.False(twoSquareMeters < oneSquareMeter); - Assert.False(twoSquareMeters <= oneSquareMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Area squaremeter = Area.FromSquareMeters(1); - Assert.Equal(0, squaremeter.CompareTo(squaremeter)); - Assert.True(squaremeter.CompareTo(Area.Zero) > 0); - Assert.True(Area.Zero.CompareTo(squaremeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Area squaremeter = Area.FromSquareMeters(1); - Assert.Throws(() => squaremeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Area squaremeter = Area.FromSquareMeters(1); - Assert.Throws(() => squaremeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Area v = Area.FromSquareMeters(1); - Assert.True(v.Equals(Area.FromSquareMeters(1), SquareMetersTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Area.Zero, SquareMetersTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Area squaremeter = Area.FromSquareMeters(1); - Assert.False(squaremeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Area squaremeter = Area.FromSquareMeters(1); - Assert.False(squaremeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(AreaUnit.Undefined, Area.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(AreaUnit)).Cast(); - foreach(var unit in units) - { - if(unit == AreaUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/BitRateTestsBase.g.cs deleted file mode 100644 index 3050aa4ad4..0000000000 --- a/UnitsNet.Tests/GeneratedCode/BitRateTestsBase.g.cs +++ /dev/null @@ -1,450 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of BitRate. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class BitRateTestsBase - { - protected abstract double BitsPerSecondInOneBitPerSecond { get; } - protected abstract double BytesPerSecondInOneBitPerSecond { get; } - protected abstract double ExabitsPerSecondInOneBitPerSecond { get; } - protected abstract double ExabytesPerSecondInOneBitPerSecond { get; } - protected abstract double ExbibitsPerSecondInOneBitPerSecond { get; } - protected abstract double ExbibytesPerSecondInOneBitPerSecond { get; } - protected abstract double GibibitsPerSecondInOneBitPerSecond { get; } - protected abstract double GibibytesPerSecondInOneBitPerSecond { get; } - protected abstract double GigabitsPerSecondInOneBitPerSecond { get; } - protected abstract double GigabytesPerSecondInOneBitPerSecond { get; } - protected abstract double KibibitsPerSecondInOneBitPerSecond { get; } - protected abstract double KibibytesPerSecondInOneBitPerSecond { get; } - protected abstract double KilobitsPerSecondInOneBitPerSecond { get; } - protected abstract double KilobytesPerSecondInOneBitPerSecond { get; } - protected abstract double MebibitsPerSecondInOneBitPerSecond { get; } - protected abstract double MebibytesPerSecondInOneBitPerSecond { get; } - protected abstract double MegabitsPerSecondInOneBitPerSecond { get; } - protected abstract double MegabytesPerSecondInOneBitPerSecond { get; } - protected abstract double PebibitsPerSecondInOneBitPerSecond { get; } - protected abstract double PebibytesPerSecondInOneBitPerSecond { get; } - protected abstract double PetabitsPerSecondInOneBitPerSecond { get; } - protected abstract double PetabytesPerSecondInOneBitPerSecond { get; } - protected abstract double TebibitsPerSecondInOneBitPerSecond { get; } - protected abstract double TebibytesPerSecondInOneBitPerSecond { get; } - protected abstract double TerabitsPerSecondInOneBitPerSecond { get; } - protected abstract double TerabytesPerSecondInOneBitPerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double BitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double BytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double ExabitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double ExabytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double ExbibitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double ExbibytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double GibibitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double GibibytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double GigabitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double GigabytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double KibibitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double KibibytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double KilobitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double KilobytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double MebibitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double MebibytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double MegabitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double MegabytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double PebibitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double PebibytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double PetabitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double PetabytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double TebibitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double TebibytesPerSecondTolerance { get { return 1e-5; } } - protected virtual double TerabitsPerSecondTolerance { get { return 1e-5; } } - protected virtual double TerabytesPerSecondTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new BitRate((decimal)0.0, BitRateUnit.Undefined)); - } - - - [Fact] - public void BitPerSecondToBitRateUnits() - { - BitRate bitpersecond = BitRate.FromBitsPerSecond(1); - AssertEx.EqualTolerance(BitsPerSecondInOneBitPerSecond, bitpersecond.BitsPerSecond, BitsPerSecondTolerance); - AssertEx.EqualTolerance(BytesPerSecondInOneBitPerSecond, bitpersecond.BytesPerSecond, BytesPerSecondTolerance); - AssertEx.EqualTolerance(ExabitsPerSecondInOneBitPerSecond, bitpersecond.ExabitsPerSecond, ExabitsPerSecondTolerance); - AssertEx.EqualTolerance(ExabytesPerSecondInOneBitPerSecond, bitpersecond.ExabytesPerSecond, ExabytesPerSecondTolerance); - AssertEx.EqualTolerance(ExbibitsPerSecondInOneBitPerSecond, bitpersecond.ExbibitsPerSecond, ExbibitsPerSecondTolerance); - AssertEx.EqualTolerance(ExbibytesPerSecondInOneBitPerSecond, bitpersecond.ExbibytesPerSecond, ExbibytesPerSecondTolerance); - AssertEx.EqualTolerance(GibibitsPerSecondInOneBitPerSecond, bitpersecond.GibibitsPerSecond, GibibitsPerSecondTolerance); - AssertEx.EqualTolerance(GibibytesPerSecondInOneBitPerSecond, bitpersecond.GibibytesPerSecond, GibibytesPerSecondTolerance); - AssertEx.EqualTolerance(GigabitsPerSecondInOneBitPerSecond, bitpersecond.GigabitsPerSecond, GigabitsPerSecondTolerance); - AssertEx.EqualTolerance(GigabytesPerSecondInOneBitPerSecond, bitpersecond.GigabytesPerSecond, GigabytesPerSecondTolerance); - AssertEx.EqualTolerance(KibibitsPerSecondInOneBitPerSecond, bitpersecond.KibibitsPerSecond, KibibitsPerSecondTolerance); - AssertEx.EqualTolerance(KibibytesPerSecondInOneBitPerSecond, bitpersecond.KibibytesPerSecond, KibibytesPerSecondTolerance); - AssertEx.EqualTolerance(KilobitsPerSecondInOneBitPerSecond, bitpersecond.KilobitsPerSecond, KilobitsPerSecondTolerance); - AssertEx.EqualTolerance(KilobytesPerSecondInOneBitPerSecond, bitpersecond.KilobytesPerSecond, KilobytesPerSecondTolerance); - AssertEx.EqualTolerance(MebibitsPerSecondInOneBitPerSecond, bitpersecond.MebibitsPerSecond, MebibitsPerSecondTolerance); - AssertEx.EqualTolerance(MebibytesPerSecondInOneBitPerSecond, bitpersecond.MebibytesPerSecond, MebibytesPerSecondTolerance); - AssertEx.EqualTolerance(MegabitsPerSecondInOneBitPerSecond, bitpersecond.MegabitsPerSecond, MegabitsPerSecondTolerance); - AssertEx.EqualTolerance(MegabytesPerSecondInOneBitPerSecond, bitpersecond.MegabytesPerSecond, MegabytesPerSecondTolerance); - AssertEx.EqualTolerance(PebibitsPerSecondInOneBitPerSecond, bitpersecond.PebibitsPerSecond, PebibitsPerSecondTolerance); - AssertEx.EqualTolerance(PebibytesPerSecondInOneBitPerSecond, bitpersecond.PebibytesPerSecond, PebibytesPerSecondTolerance); - AssertEx.EqualTolerance(PetabitsPerSecondInOneBitPerSecond, bitpersecond.PetabitsPerSecond, PetabitsPerSecondTolerance); - AssertEx.EqualTolerance(PetabytesPerSecondInOneBitPerSecond, bitpersecond.PetabytesPerSecond, PetabytesPerSecondTolerance); - AssertEx.EqualTolerance(TebibitsPerSecondInOneBitPerSecond, bitpersecond.TebibitsPerSecond, TebibitsPerSecondTolerance); - AssertEx.EqualTolerance(TebibytesPerSecondInOneBitPerSecond, bitpersecond.TebibytesPerSecond, TebibytesPerSecondTolerance); - AssertEx.EqualTolerance(TerabitsPerSecondInOneBitPerSecond, bitpersecond.TerabitsPerSecond, TerabitsPerSecondTolerance); - AssertEx.EqualTolerance(TerabytesPerSecondInOneBitPerSecond, bitpersecond.TerabytesPerSecond, TerabytesPerSecondTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.BitPerSecond).BitsPerSecond, BitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.BytePerSecond).BytesPerSecond, BytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.ExabitPerSecond).ExabitsPerSecond, ExabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.ExabytePerSecond).ExabytesPerSecond, ExabytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.ExbibitPerSecond).ExbibitsPerSecond, ExbibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.ExbibytePerSecond).ExbibytesPerSecond, ExbibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.GibibitPerSecond).GibibitsPerSecond, GibibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.GibibytePerSecond).GibibytesPerSecond, GibibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.GigabitPerSecond).GigabitsPerSecond, GigabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.GigabytePerSecond).GigabytesPerSecond, GigabytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.KibibitPerSecond).KibibitsPerSecond, KibibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.KibibytePerSecond).KibibytesPerSecond, KibibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.KilobitPerSecond).KilobitsPerSecond, KilobitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.KilobytePerSecond).KilobytesPerSecond, KilobytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.MebibitPerSecond).MebibitsPerSecond, MebibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.MebibytePerSecond).MebibytesPerSecond, MebibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.MegabitPerSecond).MegabitsPerSecond, MegabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.MegabytePerSecond).MegabytesPerSecond, MegabytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.PebibitPerSecond).PebibitsPerSecond, PebibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.PebibytePerSecond).PebibytesPerSecond, PebibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.PetabitPerSecond).PetabitsPerSecond, PetabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.PetabytePerSecond).PetabytesPerSecond, PetabytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.TebibitPerSecond).TebibitsPerSecond, TebibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.TebibytePerSecond).TebibytesPerSecond, TebibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.TerabitPerSecond).TerabitsPerSecond, TerabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.TerabytePerSecond).TerabytesPerSecond, TerabytesPerSecondTolerance); - } - - - [Fact] - public void As() - { - var bitpersecond = BitRate.FromBitsPerSecond(1); - AssertEx.EqualTolerance(BitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.BitPerSecond), BitsPerSecondTolerance); - AssertEx.EqualTolerance(BytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.BytePerSecond), BytesPerSecondTolerance); - AssertEx.EqualTolerance(ExabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.ExabitPerSecond), ExabitsPerSecondTolerance); - AssertEx.EqualTolerance(ExabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.ExabytePerSecond), ExabytesPerSecondTolerance); - AssertEx.EqualTolerance(ExbibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.ExbibitPerSecond), ExbibitsPerSecondTolerance); - AssertEx.EqualTolerance(ExbibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.ExbibytePerSecond), ExbibytesPerSecondTolerance); - AssertEx.EqualTolerance(GibibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.GibibitPerSecond), GibibitsPerSecondTolerance); - AssertEx.EqualTolerance(GibibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.GibibytePerSecond), GibibytesPerSecondTolerance); - AssertEx.EqualTolerance(GigabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.GigabitPerSecond), GigabitsPerSecondTolerance); - AssertEx.EqualTolerance(GigabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.GigabytePerSecond), GigabytesPerSecondTolerance); - AssertEx.EqualTolerance(KibibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.KibibitPerSecond), KibibitsPerSecondTolerance); - AssertEx.EqualTolerance(KibibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.KibibytePerSecond), KibibytesPerSecondTolerance); - AssertEx.EqualTolerance(KilobitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.KilobitPerSecond), KilobitsPerSecondTolerance); - AssertEx.EqualTolerance(KilobytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.KilobytePerSecond), KilobytesPerSecondTolerance); - AssertEx.EqualTolerance(MebibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.MebibitPerSecond), MebibitsPerSecondTolerance); - AssertEx.EqualTolerance(MebibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.MebibytePerSecond), MebibytesPerSecondTolerance); - AssertEx.EqualTolerance(MegabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.MegabitPerSecond), MegabitsPerSecondTolerance); - AssertEx.EqualTolerance(MegabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.MegabytePerSecond), MegabytesPerSecondTolerance); - AssertEx.EqualTolerance(PebibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.PebibitPerSecond), PebibitsPerSecondTolerance); - AssertEx.EqualTolerance(PebibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.PebibytePerSecond), PebibytesPerSecondTolerance); - AssertEx.EqualTolerance(PetabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.PetabitPerSecond), PetabitsPerSecondTolerance); - AssertEx.EqualTolerance(PetabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.PetabytePerSecond), PetabytesPerSecondTolerance); - AssertEx.EqualTolerance(TebibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.TebibitPerSecond), TebibitsPerSecondTolerance); - AssertEx.EqualTolerance(TebibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.TebibytePerSecond), TebibytesPerSecondTolerance); - AssertEx.EqualTolerance(TerabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.TerabitPerSecond), TerabitsPerSecondTolerance); - AssertEx.EqualTolerance(TerabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.TerabytePerSecond), TerabytesPerSecondTolerance); - } - - [Fact] - public void ToUnit() - { - var bitpersecond = BitRate.FromBitsPerSecond(1); - - var bitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.BitPerSecond); - AssertEx.EqualTolerance(BitsPerSecondInOneBitPerSecond, (double)bitpersecondQuantity.Value, BitsPerSecondTolerance); - Assert.Equal(BitRateUnit.BitPerSecond, bitpersecondQuantity.Unit); - - var bytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.BytePerSecond); - AssertEx.EqualTolerance(BytesPerSecondInOneBitPerSecond, (double)bytepersecondQuantity.Value, BytesPerSecondTolerance); - Assert.Equal(BitRateUnit.BytePerSecond, bytepersecondQuantity.Unit); - - var exabitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.ExabitPerSecond); - AssertEx.EqualTolerance(ExabitsPerSecondInOneBitPerSecond, (double)exabitpersecondQuantity.Value, ExabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExabitPerSecond, exabitpersecondQuantity.Unit); - - var exabytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.ExabytePerSecond); - AssertEx.EqualTolerance(ExabytesPerSecondInOneBitPerSecond, (double)exabytepersecondQuantity.Value, ExabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.ExabytePerSecond, exabytepersecondQuantity.Unit); - - var exbibitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.ExbibitPerSecond); - AssertEx.EqualTolerance(ExbibitsPerSecondInOneBitPerSecond, (double)exbibitpersecondQuantity.Value, ExbibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbibitPerSecond, exbibitpersecondQuantity.Unit); - - var exbibytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.ExbibytePerSecond); - AssertEx.EqualTolerance(ExbibytesPerSecondInOneBitPerSecond, (double)exbibytepersecondQuantity.Value, ExbibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.ExbibytePerSecond, exbibytepersecondQuantity.Unit); - - var gibibitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.GibibitPerSecond); - AssertEx.EqualTolerance(GibibitsPerSecondInOneBitPerSecond, (double)gibibitpersecondQuantity.Value, GibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GibibitPerSecond, gibibitpersecondQuantity.Unit); - - var gibibytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.GibibytePerSecond); - AssertEx.EqualTolerance(GibibytesPerSecondInOneBitPerSecond, (double)gibibytepersecondQuantity.Value, GibibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.GibibytePerSecond, gibibytepersecondQuantity.Unit); - - var gigabitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.GigabitPerSecond); - AssertEx.EqualTolerance(GigabitsPerSecondInOneBitPerSecond, (double)gigabitpersecondQuantity.Value, GigabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.GigabitPerSecond, gigabitpersecondQuantity.Unit); - - var gigabytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.GigabytePerSecond); - AssertEx.EqualTolerance(GigabytesPerSecondInOneBitPerSecond, (double)gigabytepersecondQuantity.Value, GigabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.GigabytePerSecond, gigabytepersecondQuantity.Unit); - - var kibibitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.KibibitPerSecond); - AssertEx.EqualTolerance(KibibitsPerSecondInOneBitPerSecond, (double)kibibitpersecondQuantity.Value, KibibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KibibitPerSecond, kibibitpersecondQuantity.Unit); - - var kibibytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.KibibytePerSecond); - AssertEx.EqualTolerance(KibibytesPerSecondInOneBitPerSecond, (double)kibibytepersecondQuantity.Value, KibibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.KibibytePerSecond, kibibytepersecondQuantity.Unit); - - var kilobitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.KilobitPerSecond); - AssertEx.EqualTolerance(KilobitsPerSecondInOneBitPerSecond, (double)kilobitpersecondQuantity.Value, KilobitsPerSecondTolerance); - Assert.Equal(BitRateUnit.KilobitPerSecond, kilobitpersecondQuantity.Unit); - - var kilobytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.KilobytePerSecond); - AssertEx.EqualTolerance(KilobytesPerSecondInOneBitPerSecond, (double)kilobytepersecondQuantity.Value, KilobytesPerSecondTolerance); - Assert.Equal(BitRateUnit.KilobytePerSecond, kilobytepersecondQuantity.Unit); - - var mebibitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.MebibitPerSecond); - AssertEx.EqualTolerance(MebibitsPerSecondInOneBitPerSecond, (double)mebibitpersecondQuantity.Value, MebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MebibitPerSecond, mebibitpersecondQuantity.Unit); - - var mebibytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.MebibytePerSecond); - AssertEx.EqualTolerance(MebibytesPerSecondInOneBitPerSecond, (double)mebibytepersecondQuantity.Value, MebibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.MebibytePerSecond, mebibytepersecondQuantity.Unit); - - var megabitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.MegabitPerSecond); - AssertEx.EqualTolerance(MegabitsPerSecondInOneBitPerSecond, (double)megabitpersecondQuantity.Value, MegabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.MegabitPerSecond, megabitpersecondQuantity.Unit); - - var megabytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.MegabytePerSecond); - AssertEx.EqualTolerance(MegabytesPerSecondInOneBitPerSecond, (double)megabytepersecondQuantity.Value, MegabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.MegabytePerSecond, megabytepersecondQuantity.Unit); - - var pebibitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.PebibitPerSecond); - AssertEx.EqualTolerance(PebibitsPerSecondInOneBitPerSecond, (double)pebibitpersecondQuantity.Value, PebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PebibitPerSecond, pebibitpersecondQuantity.Unit); - - var pebibytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.PebibytePerSecond); - AssertEx.EqualTolerance(PebibytesPerSecondInOneBitPerSecond, (double)pebibytepersecondQuantity.Value, PebibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.PebibytePerSecond, pebibytepersecondQuantity.Unit); - - var petabitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.PetabitPerSecond); - AssertEx.EqualTolerance(PetabitsPerSecondInOneBitPerSecond, (double)petabitpersecondQuantity.Value, PetabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.PetabitPerSecond, petabitpersecondQuantity.Unit); - - var petabytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.PetabytePerSecond); - AssertEx.EqualTolerance(PetabytesPerSecondInOneBitPerSecond, (double)petabytepersecondQuantity.Value, PetabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.PetabytePerSecond, petabytepersecondQuantity.Unit); - - var tebibitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.TebibitPerSecond); - AssertEx.EqualTolerance(TebibitsPerSecondInOneBitPerSecond, (double)tebibitpersecondQuantity.Value, TebibitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TebibitPerSecond, tebibitpersecondQuantity.Unit); - - var tebibytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.TebibytePerSecond); - AssertEx.EqualTolerance(TebibytesPerSecondInOneBitPerSecond, (double)tebibytepersecondQuantity.Value, TebibytesPerSecondTolerance); - Assert.Equal(BitRateUnit.TebibytePerSecond, tebibytepersecondQuantity.Unit); - - var terabitpersecondQuantity = bitpersecond.ToUnit(BitRateUnit.TerabitPerSecond); - AssertEx.EqualTolerance(TerabitsPerSecondInOneBitPerSecond, (double)terabitpersecondQuantity.Value, TerabitsPerSecondTolerance); - Assert.Equal(BitRateUnit.TerabitPerSecond, terabitpersecondQuantity.Unit); - - var terabytepersecondQuantity = bitpersecond.ToUnit(BitRateUnit.TerabytePerSecond); - AssertEx.EqualTolerance(TerabytesPerSecondInOneBitPerSecond, (double)terabytepersecondQuantity.Value, TerabytesPerSecondTolerance); - Assert.Equal(BitRateUnit.TerabytePerSecond, terabytepersecondQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - BitRate bitpersecond = BitRate.FromBitsPerSecond(1); - AssertEx.EqualTolerance(1, BitRate.FromBitsPerSecond(bitpersecond.BitsPerSecond).BitsPerSecond, BitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromBytesPerSecond(bitpersecond.BytesPerSecond).BitsPerSecond, BytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromExabitsPerSecond(bitpersecond.ExabitsPerSecond).BitsPerSecond, ExabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromExabytesPerSecond(bitpersecond.ExabytesPerSecond).BitsPerSecond, ExabytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromExbibitsPerSecond(bitpersecond.ExbibitsPerSecond).BitsPerSecond, ExbibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromExbibytesPerSecond(bitpersecond.ExbibytesPerSecond).BitsPerSecond, ExbibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromGibibitsPerSecond(bitpersecond.GibibitsPerSecond).BitsPerSecond, GibibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromGibibytesPerSecond(bitpersecond.GibibytesPerSecond).BitsPerSecond, GibibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromGigabitsPerSecond(bitpersecond.GigabitsPerSecond).BitsPerSecond, GigabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromGigabytesPerSecond(bitpersecond.GigabytesPerSecond).BitsPerSecond, GigabytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromKibibitsPerSecond(bitpersecond.KibibitsPerSecond).BitsPerSecond, KibibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromKibibytesPerSecond(bitpersecond.KibibytesPerSecond).BitsPerSecond, KibibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromKilobitsPerSecond(bitpersecond.KilobitsPerSecond).BitsPerSecond, KilobitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromKilobytesPerSecond(bitpersecond.KilobytesPerSecond).BitsPerSecond, KilobytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromMebibitsPerSecond(bitpersecond.MebibitsPerSecond).BitsPerSecond, MebibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromMebibytesPerSecond(bitpersecond.MebibytesPerSecond).BitsPerSecond, MebibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromMegabitsPerSecond(bitpersecond.MegabitsPerSecond).BitsPerSecond, MegabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromMegabytesPerSecond(bitpersecond.MegabytesPerSecond).BitsPerSecond, MegabytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromPebibitsPerSecond(bitpersecond.PebibitsPerSecond).BitsPerSecond, PebibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromPebibytesPerSecond(bitpersecond.PebibytesPerSecond).BitsPerSecond, PebibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromPetabitsPerSecond(bitpersecond.PetabitsPerSecond).BitsPerSecond, PetabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromPetabytesPerSecond(bitpersecond.PetabytesPerSecond).BitsPerSecond, PetabytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromTebibitsPerSecond(bitpersecond.TebibitsPerSecond).BitsPerSecond, TebibitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromTebibytesPerSecond(bitpersecond.TebibytesPerSecond).BitsPerSecond, TebibytesPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromTerabitsPerSecond(bitpersecond.TerabitsPerSecond).BitsPerSecond, TerabitsPerSecondTolerance); - AssertEx.EqualTolerance(1, BitRate.FromTerabytesPerSecond(bitpersecond.TerabytesPerSecond).BitsPerSecond, TerabytesPerSecondTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - BitRate v = BitRate.FromBitsPerSecond(1); - AssertEx.EqualTolerance(-1, -v.BitsPerSecond, BitsPerSecondTolerance); - AssertEx.EqualTolerance(2, (BitRate.FromBitsPerSecond(3)-v).BitsPerSecond, BitsPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).BitsPerSecond, BitsPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).BitsPerSecond, BitsPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).BitsPerSecond, BitsPerSecondTolerance); - AssertEx.EqualTolerance(2, (BitRate.FromBitsPerSecond(10)/5).BitsPerSecond, BitsPerSecondTolerance); - AssertEx.EqualTolerance(2, BitRate.FromBitsPerSecond(10)/BitRate.FromBitsPerSecond(5), BitsPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - BitRate oneBitPerSecond = BitRate.FromBitsPerSecond(1); - BitRate twoBitsPerSecond = BitRate.FromBitsPerSecond(2); - - Assert.True(oneBitPerSecond < twoBitsPerSecond); - Assert.True(oneBitPerSecond <= twoBitsPerSecond); - Assert.True(twoBitsPerSecond > oneBitPerSecond); - Assert.True(twoBitsPerSecond >= oneBitPerSecond); - - Assert.False(oneBitPerSecond > twoBitsPerSecond); - Assert.False(oneBitPerSecond >= twoBitsPerSecond); - Assert.False(twoBitsPerSecond < oneBitPerSecond); - Assert.False(twoBitsPerSecond <= oneBitPerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - BitRate bitpersecond = BitRate.FromBitsPerSecond(1); - Assert.Equal(0, bitpersecond.CompareTo(bitpersecond)); - Assert.True(bitpersecond.CompareTo(BitRate.Zero) > 0); - Assert.True(BitRate.Zero.CompareTo(bitpersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - BitRate bitpersecond = BitRate.FromBitsPerSecond(1); - Assert.Throws(() => bitpersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - BitRate bitpersecond = BitRate.FromBitsPerSecond(1); - Assert.Throws(() => bitpersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - BitRate v = BitRate.FromBitsPerSecond(1); - Assert.True(v.Equals(BitRate.FromBitsPerSecond(1), BitsPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(BitRate.Zero, BitsPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - BitRate bitpersecond = BitRate.FromBitsPerSecond(1); - Assert.False(bitpersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - BitRate bitpersecond = BitRate.FromBitsPerSecond(1); - Assert.False(bitpersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(BitRateUnit.Undefined, BitRate.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(BitRateUnit)).Cast(); - foreach(var unit in units) - { - if(unit == BitRateUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/BrakeSpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/BrakeSpecificFuelConsumptionTestsBase.g.cs deleted file mode 100644 index c424b3e7fb..0000000000 --- a/UnitsNet.Tests/GeneratedCode/BrakeSpecificFuelConsumptionTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of BrakeSpecificFuelConsumption. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class BrakeSpecificFuelConsumptionTestsBase - { - protected abstract double GramsPerKiloWattHourInOneKilogramPerJoule { get; } - protected abstract double KilogramsPerJouleInOneKilogramPerJoule { get; } - protected abstract double PoundsPerMechanicalHorsepowerHourInOneKilogramPerJoule { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double GramsPerKiloWattHourTolerance { get { return 1e-5; } } - protected virtual double KilogramsPerJouleTolerance { get { return 1e-5; } } - protected virtual double PoundsPerMechanicalHorsepowerHourTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new BrakeSpecificFuelConsumption((double)0.0, BrakeSpecificFuelConsumptionUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new BrakeSpecificFuelConsumption(double.PositiveInfinity, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)); - Assert.Throws(() => new BrakeSpecificFuelConsumption(double.NegativeInfinity, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new BrakeSpecificFuelConsumption(double.NaN, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)); - } - - [Fact] - public void KilogramPerJouleToBrakeSpecificFuelConsumptionUnits() - { - BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - AssertEx.EqualTolerance(GramsPerKiloWattHourInOneKilogramPerJoule, kilogramperjoule.GramsPerKiloWattHour, GramsPerKiloWattHourTolerance); - AssertEx.EqualTolerance(KilogramsPerJouleInOneKilogramPerJoule, kilogramperjoule.KilogramsPerJoule, KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(PoundsPerMechanicalHorsepowerHourInOneKilogramPerJoule, kilogramperjoule.PoundsPerMechanicalHorsepowerHour, PoundsPerMechanicalHorsepowerHourTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, BrakeSpecificFuelConsumption.From(1, BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour).GramsPerKiloWattHour, GramsPerKiloWattHourTolerance); - AssertEx.EqualTolerance(1, BrakeSpecificFuelConsumption.From(1, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule).KilogramsPerJoule, KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(1, BrakeSpecificFuelConsumption.From(1, BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour).PoundsPerMechanicalHorsepowerHour, PoundsPerMechanicalHorsepowerHourTolerance); - } - - [Fact] - public void FromKilogramsPerJoule_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => BrakeSpecificFuelConsumption.FromKilogramsPerJoule(double.PositiveInfinity)); - Assert.Throws(() => BrakeSpecificFuelConsumption.FromKilogramsPerJoule(double.NegativeInfinity)); - } - - [Fact] - public void FromKilogramsPerJoule_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => BrakeSpecificFuelConsumption.FromKilogramsPerJoule(double.NaN)); - } - - [Fact] - public void As() - { - var kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - AssertEx.EqualTolerance(GramsPerKiloWattHourInOneKilogramPerJoule, kilogramperjoule.As(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour), GramsPerKiloWattHourTolerance); - AssertEx.EqualTolerance(KilogramsPerJouleInOneKilogramPerJoule, kilogramperjoule.As(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule), KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(PoundsPerMechanicalHorsepowerHourInOneKilogramPerJoule, kilogramperjoule.As(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour), PoundsPerMechanicalHorsepowerHourTolerance); - } - - [Fact] - public void ToUnit() - { - var kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - - var gramperkilowatthourQuantity = kilogramperjoule.ToUnit(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour); - AssertEx.EqualTolerance(GramsPerKiloWattHourInOneKilogramPerJoule, (double)gramperkilowatthourQuantity.Value, GramsPerKiloWattHourTolerance); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, gramperkilowatthourQuantity.Unit); - - var kilogramperjouleQuantity = kilogramperjoule.ToUnit(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule); - AssertEx.EqualTolerance(KilogramsPerJouleInOneKilogramPerJoule, (double)kilogramperjouleQuantity.Value, KilogramsPerJouleTolerance); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, kilogramperjouleQuantity.Unit); - - var poundpermechanicalhorsepowerhourQuantity = kilogramperjoule.ToUnit(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour); - AssertEx.EqualTolerance(PoundsPerMechanicalHorsepowerHourInOneKilogramPerJoule, (double)poundpermechanicalhorsepowerhourQuantity.Value, PoundsPerMechanicalHorsepowerHourTolerance); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, poundpermechanicalhorsepowerhourQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - AssertEx.EqualTolerance(1, BrakeSpecificFuelConsumption.FromGramsPerKiloWattHour(kilogramperjoule.GramsPerKiloWattHour).KilogramsPerJoule, GramsPerKiloWattHourTolerance); - AssertEx.EqualTolerance(1, BrakeSpecificFuelConsumption.FromKilogramsPerJoule(kilogramperjoule.KilogramsPerJoule).KilogramsPerJoule, KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(1, BrakeSpecificFuelConsumption.FromPoundsPerMechanicalHorsepowerHour(kilogramperjoule.PoundsPerMechanicalHorsepowerHour).KilogramsPerJoule, PoundsPerMechanicalHorsepowerHourTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - BrakeSpecificFuelConsumption v = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - AssertEx.EqualTolerance(-1, -v.KilogramsPerJoule, KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(2, (BrakeSpecificFuelConsumption.FromKilogramsPerJoule(3)-v).KilogramsPerJoule, KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(2, (v + v).KilogramsPerJoule, KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(10, (v*10).KilogramsPerJoule, KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(10, (10*v).KilogramsPerJoule, KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(2, (BrakeSpecificFuelConsumption.FromKilogramsPerJoule(10)/5).KilogramsPerJoule, KilogramsPerJouleTolerance); - AssertEx.EqualTolerance(2, BrakeSpecificFuelConsumption.FromKilogramsPerJoule(10)/BrakeSpecificFuelConsumption.FromKilogramsPerJoule(5), KilogramsPerJouleTolerance); - } - - [Fact] - public void ComparisonOperators() - { - BrakeSpecificFuelConsumption oneKilogramPerJoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - BrakeSpecificFuelConsumption twoKilogramsPerJoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(2); - - Assert.True(oneKilogramPerJoule < twoKilogramsPerJoule); - Assert.True(oneKilogramPerJoule <= twoKilogramsPerJoule); - Assert.True(twoKilogramsPerJoule > oneKilogramPerJoule); - Assert.True(twoKilogramsPerJoule >= oneKilogramPerJoule); - - Assert.False(oneKilogramPerJoule > twoKilogramsPerJoule); - Assert.False(oneKilogramPerJoule >= twoKilogramsPerJoule); - Assert.False(twoKilogramsPerJoule < oneKilogramPerJoule); - Assert.False(twoKilogramsPerJoule <= oneKilogramPerJoule); - } - - [Fact] - public void CompareToIsImplemented() - { - BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - Assert.Equal(0, kilogramperjoule.CompareTo(kilogramperjoule)); - Assert.True(kilogramperjoule.CompareTo(BrakeSpecificFuelConsumption.Zero) > 0); - Assert.True(BrakeSpecificFuelConsumption.Zero.CompareTo(kilogramperjoule) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - Assert.Throws(() => kilogramperjoule.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - Assert.Throws(() => kilogramperjoule.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - BrakeSpecificFuelConsumption v = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - Assert.True(v.Equals(BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1), KilogramsPerJouleTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(BrakeSpecificFuelConsumption.Zero, KilogramsPerJouleTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - Assert.False(kilogramperjoule.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - BrakeSpecificFuelConsumption kilogramperjoule = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1); - Assert.False(kilogramperjoule.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(BrakeSpecificFuelConsumptionUnit.Undefined, BrakeSpecificFuelConsumption.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(BrakeSpecificFuelConsumptionUnit)).Cast(); - foreach(var unit in units) - { - if(unit == BrakeSpecificFuelConsumptionUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/CapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/CapacitanceTestsBase.g.cs deleted file mode 100644 index 08850f7618..0000000000 --- a/UnitsNet.Tests/GeneratedCode/CapacitanceTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Capacitance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class CapacitanceTestsBase - { - protected abstract double FaradsInOneFarad { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double FaradsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Capacitance((double)0.0, CapacitanceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Capacitance(double.PositiveInfinity, CapacitanceUnit.Farad)); - Assert.Throws(() => new Capacitance(double.NegativeInfinity, CapacitanceUnit.Farad)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Capacitance(double.NaN, CapacitanceUnit.Farad)); - } - - [Fact] - public void FaradToCapacitanceUnits() - { - Capacitance farad = Capacitance.FromFarads(1); - AssertEx.EqualTolerance(FaradsInOneFarad, farad.Farads, FaradsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Capacitance.From(1, CapacitanceUnit.Farad).Farads, FaradsTolerance); - } - - [Fact] - public void FromFarads_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Capacitance.FromFarads(double.PositiveInfinity)); - Assert.Throws(() => Capacitance.FromFarads(double.NegativeInfinity)); - } - - [Fact] - public void FromFarads_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Capacitance.FromFarads(double.NaN)); - } - - [Fact] - public void As() - { - var farad = Capacitance.FromFarads(1); - AssertEx.EqualTolerance(FaradsInOneFarad, farad.As(CapacitanceUnit.Farad), FaradsTolerance); - } - - [Fact] - public void ToUnit() - { - var farad = Capacitance.FromFarads(1); - - var faradQuantity = farad.ToUnit(CapacitanceUnit.Farad); - AssertEx.EqualTolerance(FaradsInOneFarad, (double)faradQuantity.Value, FaradsTolerance); - Assert.Equal(CapacitanceUnit.Farad, faradQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Capacitance farad = Capacitance.FromFarads(1); - AssertEx.EqualTolerance(1, Capacitance.FromFarads(farad.Farads).Farads, FaradsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Capacitance v = Capacitance.FromFarads(1); - AssertEx.EqualTolerance(-1, -v.Farads, FaradsTolerance); - AssertEx.EqualTolerance(2, (Capacitance.FromFarads(3)-v).Farads, FaradsTolerance); - AssertEx.EqualTolerance(2, (v + v).Farads, FaradsTolerance); - AssertEx.EqualTolerance(10, (v*10).Farads, FaradsTolerance); - AssertEx.EqualTolerance(10, (10*v).Farads, FaradsTolerance); - AssertEx.EqualTolerance(2, (Capacitance.FromFarads(10)/5).Farads, FaradsTolerance); - AssertEx.EqualTolerance(2, Capacitance.FromFarads(10)/Capacitance.FromFarads(5), FaradsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Capacitance oneFarad = Capacitance.FromFarads(1); - Capacitance twoFarads = Capacitance.FromFarads(2); - - Assert.True(oneFarad < twoFarads); - Assert.True(oneFarad <= twoFarads); - Assert.True(twoFarads > oneFarad); - Assert.True(twoFarads >= oneFarad); - - Assert.False(oneFarad > twoFarads); - Assert.False(oneFarad >= twoFarads); - Assert.False(twoFarads < oneFarad); - Assert.False(twoFarads <= oneFarad); - } - - [Fact] - public void CompareToIsImplemented() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.Equal(0, farad.CompareTo(farad)); - Assert.True(farad.CompareTo(Capacitance.Zero) > 0); - Assert.True(Capacitance.Zero.CompareTo(farad) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.Throws(() => farad.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.Throws(() => farad.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Capacitance v = Capacitance.FromFarads(1); - Assert.True(v.Equals(Capacitance.FromFarads(1), FaradsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Capacitance.Zero, FaradsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.False(farad.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.False(farad.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(CapacitanceUnit.Undefined, Capacitance.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(CapacitanceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == CapacitanceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/DensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/DensityTestsBase.g.cs deleted file mode 100644 index 7c9cfc75cb..0000000000 --- a/UnitsNet.Tests/GeneratedCode/DensityTestsBase.g.cs +++ /dev/null @@ -1,594 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Density. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class DensityTestsBase - { - protected abstract double CentigramsPerDeciLiterInOneKilogramPerCubicMeter { get; } - protected abstract double CentigramsPerLiterInOneKilogramPerCubicMeter { get; } - protected abstract double CentigramsPerMilliliterInOneKilogramPerCubicMeter { get; } - protected abstract double DecigramsPerDeciLiterInOneKilogramPerCubicMeter { get; } - protected abstract double DecigramsPerLiterInOneKilogramPerCubicMeter { get; } - protected abstract double DecigramsPerMilliliterInOneKilogramPerCubicMeter { get; } - protected abstract double GramsPerCubicCentimeterInOneKilogramPerCubicMeter { get; } - protected abstract double GramsPerCubicMeterInOneKilogramPerCubicMeter { get; } - protected abstract double GramsPerCubicMillimeterInOneKilogramPerCubicMeter { get; } - protected abstract double GramsPerDeciLiterInOneKilogramPerCubicMeter { get; } - protected abstract double GramsPerLiterInOneKilogramPerCubicMeter { get; } - protected abstract double GramsPerMilliliterInOneKilogramPerCubicMeter { get; } - protected abstract double KilogramsPerCubicCentimeterInOneKilogramPerCubicMeter { get; } - protected abstract double KilogramsPerCubicMeterInOneKilogramPerCubicMeter { get; } - protected abstract double KilogramsPerCubicMillimeterInOneKilogramPerCubicMeter { get; } - protected abstract double KilopoundsPerCubicFootInOneKilogramPerCubicMeter { get; } - protected abstract double KilopoundsPerCubicInchInOneKilogramPerCubicMeter { get; } - protected abstract double MicrogramsPerDeciLiterInOneKilogramPerCubicMeter { get; } - protected abstract double MicrogramsPerLiterInOneKilogramPerCubicMeter { get; } - protected abstract double MicrogramsPerMilliliterInOneKilogramPerCubicMeter { get; } - protected abstract double MilligramsPerCubicMeterInOneKilogramPerCubicMeter { get; } - protected abstract double MilligramsPerDeciLiterInOneKilogramPerCubicMeter { get; } - protected abstract double MilligramsPerLiterInOneKilogramPerCubicMeter { get; } - protected abstract double MilligramsPerMilliliterInOneKilogramPerCubicMeter { get; } - protected abstract double NanogramsPerDeciLiterInOneKilogramPerCubicMeter { get; } - protected abstract double NanogramsPerLiterInOneKilogramPerCubicMeter { get; } - protected abstract double NanogramsPerMilliliterInOneKilogramPerCubicMeter { get; } - protected abstract double PicogramsPerDeciLiterInOneKilogramPerCubicMeter { get; } - protected abstract double PicogramsPerLiterInOneKilogramPerCubicMeter { get; } - protected abstract double PicogramsPerMilliliterInOneKilogramPerCubicMeter { get; } - protected abstract double PoundsPerCubicFootInOneKilogramPerCubicMeter { get; } - protected abstract double PoundsPerCubicInchInOneKilogramPerCubicMeter { get; } - protected abstract double PoundsPerImperialGallonInOneKilogramPerCubicMeter { get; } - protected abstract double PoundsPerUSGallonInOneKilogramPerCubicMeter { get; } - protected abstract double SlugsPerCubicFootInOneKilogramPerCubicMeter { get; } - protected abstract double TonnesPerCubicCentimeterInOneKilogramPerCubicMeter { get; } - protected abstract double TonnesPerCubicMeterInOneKilogramPerCubicMeter { get; } - protected abstract double TonnesPerCubicMillimeterInOneKilogramPerCubicMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentigramsPerDeciLiterTolerance { get { return 1e-5; } } - protected virtual double CentigramsPerLiterTolerance { get { return 1e-5; } } - protected virtual double CentigramsPerMilliliterTolerance { get { return 1e-5; } } - protected virtual double DecigramsPerDeciLiterTolerance { get { return 1e-5; } } - protected virtual double DecigramsPerLiterTolerance { get { return 1e-5; } } - protected virtual double DecigramsPerMilliliterTolerance { get { return 1e-5; } } - protected virtual double GramsPerCubicCentimeterTolerance { get { return 1e-5; } } - protected virtual double GramsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double GramsPerCubicMillimeterTolerance { get { return 1e-5; } } - protected virtual double GramsPerDeciLiterTolerance { get { return 1e-5; } } - protected virtual double GramsPerLiterTolerance { get { return 1e-5; } } - protected virtual double GramsPerMilliliterTolerance { get { return 1e-5; } } - protected virtual double KilogramsPerCubicCentimeterTolerance { get { return 1e-5; } } - protected virtual double KilogramsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double KilogramsPerCubicMillimeterTolerance { get { return 1e-5; } } - protected virtual double KilopoundsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double KilopoundsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double MicrogramsPerDeciLiterTolerance { get { return 1e-5; } } - protected virtual double MicrogramsPerLiterTolerance { get { return 1e-5; } } - protected virtual double MicrogramsPerMilliliterTolerance { get { return 1e-5; } } - protected virtual double MilligramsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double MilligramsPerDeciLiterTolerance { get { return 1e-5; } } - protected virtual double MilligramsPerLiterTolerance { get { return 1e-5; } } - protected virtual double MilligramsPerMilliliterTolerance { get { return 1e-5; } } - protected virtual double NanogramsPerDeciLiterTolerance { get { return 1e-5; } } - protected virtual double NanogramsPerLiterTolerance { get { return 1e-5; } } - protected virtual double NanogramsPerMilliliterTolerance { get { return 1e-5; } } - protected virtual double PicogramsPerDeciLiterTolerance { get { return 1e-5; } } - protected virtual double PicogramsPerLiterTolerance { get { return 1e-5; } } - protected virtual double PicogramsPerMilliliterTolerance { get { return 1e-5; } } - protected virtual double PoundsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double PoundsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double PoundsPerImperialGallonTolerance { get { return 1e-5; } } - protected virtual double PoundsPerUSGallonTolerance { get { return 1e-5; } } - protected virtual double SlugsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double TonnesPerCubicCentimeterTolerance { get { return 1e-5; } } - protected virtual double TonnesPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double TonnesPerCubicMillimeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Density((double)0.0, DensityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Density(double.PositiveInfinity, DensityUnit.KilogramPerCubicMeter)); - Assert.Throws(() => new Density(double.NegativeInfinity, DensityUnit.KilogramPerCubicMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Density(double.NaN, DensityUnit.KilogramPerCubicMeter)); - } - - [Fact] - public void KilogramPerCubicMeterToDensityUnits() - { - Density kilogrampercubicmeter = Density.FromKilogramsPerCubicMeter(1); - AssertEx.EqualTolerance(CentigramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.CentigramsPerDeciLiter, CentigramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(CentigramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.CentigramsPerLiter, CentigramsPerLiterTolerance); - AssertEx.EqualTolerance(CentigramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.CentigramsPerMilliliter, CentigramsPerMilliliterTolerance); - AssertEx.EqualTolerance(DecigramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.DecigramsPerDeciLiter, DecigramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(DecigramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.DecigramsPerLiter, DecigramsPerLiterTolerance); - AssertEx.EqualTolerance(DecigramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.DecigramsPerMilliliter, DecigramsPerMilliliterTolerance); - AssertEx.EqualTolerance(GramsPerCubicCentimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.GramsPerCubicCentimeter, GramsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(GramsPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.GramsPerCubicMeter, GramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(GramsPerCubicMillimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.GramsPerCubicMillimeter, GramsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(GramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.GramsPerDeciLiter, GramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(GramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.GramsPerLiter, GramsPerLiterTolerance); - AssertEx.EqualTolerance(GramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.GramsPerMilliliter, GramsPerMilliliterTolerance); - AssertEx.EqualTolerance(KilogramsPerCubicCentimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.KilogramsPerCubicCentimeter, KilogramsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(KilogramsPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(KilogramsPerCubicMillimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.KilogramsPerCubicMillimeter, KilogramsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(KilopoundsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.KilopoundsPerCubicFoot, KilopoundsPerCubicFootTolerance); - AssertEx.EqualTolerance(KilopoundsPerCubicInchInOneKilogramPerCubicMeter, kilogrampercubicmeter.KilopoundsPerCubicInch, KilopoundsPerCubicInchTolerance); - AssertEx.EqualTolerance(MicrogramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.MicrogramsPerDeciLiter, MicrogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(MicrogramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.MicrogramsPerLiter, MicrogramsPerLiterTolerance); - AssertEx.EqualTolerance(MicrogramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.MicrogramsPerMilliliter, MicrogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(MilligramsPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(MilligramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.MilligramsPerDeciLiter, MilligramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(MilligramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.MilligramsPerLiter, MilligramsPerLiterTolerance); - AssertEx.EqualTolerance(MilligramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.MilligramsPerMilliliter, MilligramsPerMilliliterTolerance); - AssertEx.EqualTolerance(NanogramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.NanogramsPerDeciLiter, NanogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(NanogramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.NanogramsPerLiter, NanogramsPerLiterTolerance); - AssertEx.EqualTolerance(NanogramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.NanogramsPerMilliliter, NanogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(PicogramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.PicogramsPerDeciLiter, PicogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(PicogramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.PicogramsPerLiter, PicogramsPerLiterTolerance); - AssertEx.EqualTolerance(PicogramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.PicogramsPerMilliliter, PicogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(PoundsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.PoundsPerCubicFoot, PoundsPerCubicFootTolerance); - AssertEx.EqualTolerance(PoundsPerCubicInchInOneKilogramPerCubicMeter, kilogrampercubicmeter.PoundsPerCubicInch, PoundsPerCubicInchTolerance); - AssertEx.EqualTolerance(PoundsPerImperialGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.PoundsPerImperialGallon, PoundsPerImperialGallonTolerance); - AssertEx.EqualTolerance(PoundsPerUSGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.PoundsPerUSGallon, PoundsPerUSGallonTolerance); - AssertEx.EqualTolerance(SlugsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.SlugsPerCubicFoot, SlugsPerCubicFootTolerance); - AssertEx.EqualTolerance(TonnesPerCubicCentimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.TonnesPerCubicCentimeter, TonnesPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(TonnesPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.TonnesPerCubicMeter, TonnesPerCubicMeterTolerance); - AssertEx.EqualTolerance(TonnesPerCubicMillimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.TonnesPerCubicMillimeter, TonnesPerCubicMillimeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.CentigramPerDeciliter).CentigramsPerDeciLiter, CentigramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.CentigramPerLiter).CentigramsPerLiter, CentigramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.CentigramPerMilliliter).CentigramsPerMilliliter, CentigramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.DecigramPerDeciliter).DecigramsPerDeciLiter, DecigramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.DecigramPerLiter).DecigramsPerLiter, DecigramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.DecigramPerMilliliter).DecigramsPerMilliliter, DecigramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.GramPerCubicCentimeter).GramsPerCubicCentimeter, GramsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.GramPerCubicMeter).GramsPerCubicMeter, GramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.GramPerCubicMillimeter).GramsPerCubicMillimeter, GramsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.GramPerDeciliter).GramsPerDeciLiter, GramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.GramPerLiter).GramsPerLiter, GramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.GramPerMilliliter).GramsPerMilliliter, GramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.KilogramPerCubicCentimeter).KilogramsPerCubicCentimeter, KilogramsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.KilogramPerCubicMeter).KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.KilogramPerCubicMillimeter).KilogramsPerCubicMillimeter, KilogramsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.KilopoundPerCubicFoot).KilopoundsPerCubicFoot, KilopoundsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.KilopoundPerCubicInch).KilopoundsPerCubicInch, KilopoundsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.MicrogramPerDeciliter).MicrogramsPerDeciLiter, MicrogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.MicrogramPerLiter).MicrogramsPerLiter, MicrogramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.MicrogramPerMilliliter).MicrogramsPerMilliliter, MicrogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.MilligramPerCubicMeter).MilligramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.MilligramPerDeciliter).MilligramsPerDeciLiter, MilligramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.MilligramPerLiter).MilligramsPerLiter, MilligramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.MilligramPerMilliliter).MilligramsPerMilliliter, MilligramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.NanogramPerDeciliter).NanogramsPerDeciLiter, NanogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.NanogramPerLiter).NanogramsPerLiter, NanogramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.NanogramPerMilliliter).NanogramsPerMilliliter, NanogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PicogramPerDeciliter).PicogramsPerDeciLiter, PicogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PicogramPerLiter).PicogramsPerLiter, PicogramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PicogramPerMilliliter).PicogramsPerMilliliter, PicogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PoundPerCubicFoot).PoundsPerCubicFoot, PoundsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PoundPerCubicInch).PoundsPerCubicInch, PoundsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PoundPerImperialGallon).PoundsPerImperialGallon, PoundsPerImperialGallonTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.PoundPerUSGallon).PoundsPerUSGallon, PoundsPerUSGallonTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.SlugPerCubicFoot).SlugsPerCubicFoot, SlugsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.TonnePerCubicCentimeter).TonnesPerCubicCentimeter, TonnesPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.TonnePerCubicMeter).TonnesPerCubicMeter, TonnesPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Density.From(1, DensityUnit.TonnePerCubicMillimeter).TonnesPerCubicMillimeter, TonnesPerCubicMillimeterTolerance); - } - - [Fact] - public void FromKilogramsPerCubicMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Density.FromKilogramsPerCubicMeter(double.PositiveInfinity)); - Assert.Throws(() => Density.FromKilogramsPerCubicMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromKilogramsPerCubicMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Density.FromKilogramsPerCubicMeter(double.NaN)); - } - - [Fact] - public void As() - { - var kilogrampercubicmeter = Density.FromKilogramsPerCubicMeter(1); - AssertEx.EqualTolerance(CentigramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.CentigramPerDeciliter), CentigramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(CentigramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.CentigramPerLiter), CentigramsPerLiterTolerance); - AssertEx.EqualTolerance(CentigramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.CentigramPerMilliliter), CentigramsPerMilliliterTolerance); - AssertEx.EqualTolerance(DecigramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.DecigramPerDeciliter), DecigramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(DecigramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.DecigramPerLiter), DecigramsPerLiterTolerance); - AssertEx.EqualTolerance(DecigramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.DecigramPerMilliliter), DecigramsPerMilliliterTolerance); - AssertEx.EqualTolerance(GramsPerCubicCentimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.GramPerCubicCentimeter), GramsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(GramsPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.GramPerCubicMeter), GramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(GramsPerCubicMillimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.GramPerCubicMillimeter), GramsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(GramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.GramPerDeciliter), GramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(GramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.GramPerLiter), GramsPerLiterTolerance); - AssertEx.EqualTolerance(GramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.GramPerMilliliter), GramsPerMilliliterTolerance); - AssertEx.EqualTolerance(KilogramsPerCubicCentimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.KilogramPerCubicCentimeter), KilogramsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(KilogramsPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.KilogramPerCubicMeter), KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(KilogramsPerCubicMillimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.KilogramPerCubicMillimeter), KilogramsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(KilopoundsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.KilopoundPerCubicFoot), KilopoundsPerCubicFootTolerance); - AssertEx.EqualTolerance(KilopoundsPerCubicInchInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.KilopoundPerCubicInch), KilopoundsPerCubicInchTolerance); - AssertEx.EqualTolerance(MicrogramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.MicrogramPerDeciliter), MicrogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(MicrogramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.MicrogramPerLiter), MicrogramsPerLiterTolerance); - AssertEx.EqualTolerance(MicrogramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.MicrogramPerMilliliter), MicrogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(MilligramsPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.MilligramPerCubicMeter), MilligramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(MilligramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.MilligramPerDeciliter), MilligramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(MilligramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.MilligramPerLiter), MilligramsPerLiterTolerance); - AssertEx.EqualTolerance(MilligramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.MilligramPerMilliliter), MilligramsPerMilliliterTolerance); - AssertEx.EqualTolerance(NanogramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.NanogramPerDeciliter), NanogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(NanogramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.NanogramPerLiter), NanogramsPerLiterTolerance); - AssertEx.EqualTolerance(NanogramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.NanogramPerMilliliter), NanogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(PicogramsPerDeciLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PicogramPerDeciliter), PicogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(PicogramsPerLiterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PicogramPerLiter), PicogramsPerLiterTolerance); - AssertEx.EqualTolerance(PicogramsPerMilliliterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PicogramPerMilliliter), PicogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(PoundsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PoundPerCubicFoot), PoundsPerCubicFootTolerance); - AssertEx.EqualTolerance(PoundsPerCubicInchInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PoundPerCubicInch), PoundsPerCubicInchTolerance); - AssertEx.EqualTolerance(PoundsPerImperialGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PoundPerImperialGallon), PoundsPerImperialGallonTolerance); - AssertEx.EqualTolerance(PoundsPerUSGallonInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.PoundPerUSGallon), PoundsPerUSGallonTolerance); - AssertEx.EqualTolerance(SlugsPerCubicFootInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.SlugPerCubicFoot), SlugsPerCubicFootTolerance); - AssertEx.EqualTolerance(TonnesPerCubicCentimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.TonnePerCubicCentimeter), TonnesPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(TonnesPerCubicMeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.TonnePerCubicMeter), TonnesPerCubicMeterTolerance); - AssertEx.EqualTolerance(TonnesPerCubicMillimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.TonnePerCubicMillimeter), TonnesPerCubicMillimeterTolerance); - } - - [Fact] - public void ToUnit() - { - var kilogrampercubicmeter = Density.FromKilogramsPerCubicMeter(1); - - var centigramperdeciliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.CentigramPerDeciliter); - AssertEx.EqualTolerance(CentigramsPerDeciLiterInOneKilogramPerCubicMeter, (double)centigramperdeciliterQuantity.Value, CentigramsPerDeciLiterTolerance); - Assert.Equal(DensityUnit.CentigramPerDeciliter, centigramperdeciliterQuantity.Unit); - - var centigramperliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.CentigramPerLiter); - AssertEx.EqualTolerance(CentigramsPerLiterInOneKilogramPerCubicMeter, (double)centigramperliterQuantity.Value, CentigramsPerLiterTolerance); - Assert.Equal(DensityUnit.CentigramPerLiter, centigramperliterQuantity.Unit); - - var centigrampermilliliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.CentigramPerMilliliter); - AssertEx.EqualTolerance(CentigramsPerMilliliterInOneKilogramPerCubicMeter, (double)centigrampermilliliterQuantity.Value, CentigramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.CentigramPerMilliliter, centigrampermilliliterQuantity.Unit); - - var decigramperdeciliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.DecigramPerDeciliter); - AssertEx.EqualTolerance(DecigramsPerDeciLiterInOneKilogramPerCubicMeter, (double)decigramperdeciliterQuantity.Value, DecigramsPerDeciLiterTolerance); - Assert.Equal(DensityUnit.DecigramPerDeciliter, decigramperdeciliterQuantity.Unit); - - var decigramperliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.DecigramPerLiter); - AssertEx.EqualTolerance(DecigramsPerLiterInOneKilogramPerCubicMeter, (double)decigramperliterQuantity.Value, DecigramsPerLiterTolerance); - Assert.Equal(DensityUnit.DecigramPerLiter, decigramperliterQuantity.Unit); - - var decigrampermilliliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.DecigramPerMilliliter); - AssertEx.EqualTolerance(DecigramsPerMilliliterInOneKilogramPerCubicMeter, (double)decigrampermilliliterQuantity.Value, DecigramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.DecigramPerMilliliter, decigrampermilliliterQuantity.Unit); - - var grampercubiccentimeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.GramPerCubicCentimeter); - AssertEx.EqualTolerance(GramsPerCubicCentimeterInOneKilogramPerCubicMeter, (double)grampercubiccentimeterQuantity.Value, GramsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicCentimeter, grampercubiccentimeterQuantity.Unit); - - var grampercubicmeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.GramPerCubicMeter); - AssertEx.EqualTolerance(GramsPerCubicMeterInOneKilogramPerCubicMeter, (double)grampercubicmeterQuantity.Value, GramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicMeter, grampercubicmeterQuantity.Unit); - - var grampercubicmillimeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.GramPerCubicMillimeter); - AssertEx.EqualTolerance(GramsPerCubicMillimeterInOneKilogramPerCubicMeter, (double)grampercubicmillimeterQuantity.Value, GramsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.GramPerCubicMillimeter, grampercubicmillimeterQuantity.Unit); - - var gramperdeciliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.GramPerDeciliter); - AssertEx.EqualTolerance(GramsPerDeciLiterInOneKilogramPerCubicMeter, (double)gramperdeciliterQuantity.Value, GramsPerDeciLiterTolerance); - Assert.Equal(DensityUnit.GramPerDeciliter, gramperdeciliterQuantity.Unit); - - var gramperliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.GramPerLiter); - AssertEx.EqualTolerance(GramsPerLiterInOneKilogramPerCubicMeter, (double)gramperliterQuantity.Value, GramsPerLiterTolerance); - Assert.Equal(DensityUnit.GramPerLiter, gramperliterQuantity.Unit); - - var grampermilliliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.GramPerMilliliter); - AssertEx.EqualTolerance(GramsPerMilliliterInOneKilogramPerCubicMeter, (double)grampermilliliterQuantity.Value, GramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.GramPerMilliliter, grampermilliliterQuantity.Unit); - - var kilogrampercubiccentimeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.KilogramPerCubicCentimeter); - AssertEx.EqualTolerance(KilogramsPerCubicCentimeterInOneKilogramPerCubicMeter, (double)kilogrampercubiccentimeterQuantity.Value, KilogramsPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicCentimeter, kilogrampercubiccentimeterQuantity.Unit); - - var kilogrampercubicmeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.KilogramPerCubicMeter); - AssertEx.EqualTolerance(KilogramsPerCubicMeterInOneKilogramPerCubicMeter, (double)kilogrampercubicmeterQuantity.Value, KilogramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicMeter, kilogrampercubicmeterQuantity.Unit); - - var kilogrampercubicmillimeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.KilogramPerCubicMillimeter); - AssertEx.EqualTolerance(KilogramsPerCubicMillimeterInOneKilogramPerCubicMeter, (double)kilogrampercubicmillimeterQuantity.Value, KilogramsPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.KilogramPerCubicMillimeter, kilogrampercubicmillimeterQuantity.Unit); - - var kilopoundpercubicfootQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.KilopoundPerCubicFoot); - AssertEx.EqualTolerance(KilopoundsPerCubicFootInOneKilogramPerCubicMeter, (double)kilopoundpercubicfootQuantity.Value, KilopoundsPerCubicFootTolerance); - Assert.Equal(DensityUnit.KilopoundPerCubicFoot, kilopoundpercubicfootQuantity.Unit); - - var kilopoundpercubicinchQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.KilopoundPerCubicInch); - AssertEx.EqualTolerance(KilopoundsPerCubicInchInOneKilogramPerCubicMeter, (double)kilopoundpercubicinchQuantity.Value, KilopoundsPerCubicInchTolerance); - Assert.Equal(DensityUnit.KilopoundPerCubicInch, kilopoundpercubicinchQuantity.Unit); - - var microgramperdeciliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.MicrogramPerDeciliter); - AssertEx.EqualTolerance(MicrogramsPerDeciLiterInOneKilogramPerCubicMeter, (double)microgramperdeciliterQuantity.Value, MicrogramsPerDeciLiterTolerance); - Assert.Equal(DensityUnit.MicrogramPerDeciliter, microgramperdeciliterQuantity.Unit); - - var microgramperliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.MicrogramPerLiter); - AssertEx.EqualTolerance(MicrogramsPerLiterInOneKilogramPerCubicMeter, (double)microgramperliterQuantity.Value, MicrogramsPerLiterTolerance); - Assert.Equal(DensityUnit.MicrogramPerLiter, microgramperliterQuantity.Unit); - - var microgrampermilliliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.MicrogramPerMilliliter); - AssertEx.EqualTolerance(MicrogramsPerMilliliterInOneKilogramPerCubicMeter, (double)microgrampermilliliterQuantity.Value, MicrogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.MicrogramPerMilliliter, microgrampermilliliterQuantity.Unit); - - var milligrampercubicmeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.MilligramPerCubicMeter); - AssertEx.EqualTolerance(MilligramsPerCubicMeterInOneKilogramPerCubicMeter, (double)milligrampercubicmeterQuantity.Value, MilligramsPerCubicMeterTolerance); - Assert.Equal(DensityUnit.MilligramPerCubicMeter, milligrampercubicmeterQuantity.Unit); - - var milligramperdeciliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.MilligramPerDeciliter); - AssertEx.EqualTolerance(MilligramsPerDeciLiterInOneKilogramPerCubicMeter, (double)milligramperdeciliterQuantity.Value, MilligramsPerDeciLiterTolerance); - Assert.Equal(DensityUnit.MilligramPerDeciliter, milligramperdeciliterQuantity.Unit); - - var milligramperliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.MilligramPerLiter); - AssertEx.EqualTolerance(MilligramsPerLiterInOneKilogramPerCubicMeter, (double)milligramperliterQuantity.Value, MilligramsPerLiterTolerance); - Assert.Equal(DensityUnit.MilligramPerLiter, milligramperliterQuantity.Unit); - - var milligrampermilliliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.MilligramPerMilliliter); - AssertEx.EqualTolerance(MilligramsPerMilliliterInOneKilogramPerCubicMeter, (double)milligrampermilliliterQuantity.Value, MilligramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.MilligramPerMilliliter, milligrampermilliliterQuantity.Unit); - - var nanogramperdeciliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.NanogramPerDeciliter); - AssertEx.EqualTolerance(NanogramsPerDeciLiterInOneKilogramPerCubicMeter, (double)nanogramperdeciliterQuantity.Value, NanogramsPerDeciLiterTolerance); - Assert.Equal(DensityUnit.NanogramPerDeciliter, nanogramperdeciliterQuantity.Unit); - - var nanogramperliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.NanogramPerLiter); - AssertEx.EqualTolerance(NanogramsPerLiterInOneKilogramPerCubicMeter, (double)nanogramperliterQuantity.Value, NanogramsPerLiterTolerance); - Assert.Equal(DensityUnit.NanogramPerLiter, nanogramperliterQuantity.Unit); - - var nanogrampermilliliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.NanogramPerMilliliter); - AssertEx.EqualTolerance(NanogramsPerMilliliterInOneKilogramPerCubicMeter, (double)nanogrampermilliliterQuantity.Value, NanogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.NanogramPerMilliliter, nanogrampermilliliterQuantity.Unit); - - var picogramperdeciliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.PicogramPerDeciliter); - AssertEx.EqualTolerance(PicogramsPerDeciLiterInOneKilogramPerCubicMeter, (double)picogramperdeciliterQuantity.Value, PicogramsPerDeciLiterTolerance); - Assert.Equal(DensityUnit.PicogramPerDeciliter, picogramperdeciliterQuantity.Unit); - - var picogramperliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.PicogramPerLiter); - AssertEx.EqualTolerance(PicogramsPerLiterInOneKilogramPerCubicMeter, (double)picogramperliterQuantity.Value, PicogramsPerLiterTolerance); - Assert.Equal(DensityUnit.PicogramPerLiter, picogramperliterQuantity.Unit); - - var picogrampermilliliterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.PicogramPerMilliliter); - AssertEx.EqualTolerance(PicogramsPerMilliliterInOneKilogramPerCubicMeter, (double)picogrampermilliliterQuantity.Value, PicogramsPerMilliliterTolerance); - Assert.Equal(DensityUnit.PicogramPerMilliliter, picogrampermilliliterQuantity.Unit); - - var poundpercubicfootQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.PoundPerCubicFoot); - AssertEx.EqualTolerance(PoundsPerCubicFootInOneKilogramPerCubicMeter, (double)poundpercubicfootQuantity.Value, PoundsPerCubicFootTolerance); - Assert.Equal(DensityUnit.PoundPerCubicFoot, poundpercubicfootQuantity.Unit); - - var poundpercubicinchQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.PoundPerCubicInch); - AssertEx.EqualTolerance(PoundsPerCubicInchInOneKilogramPerCubicMeter, (double)poundpercubicinchQuantity.Value, PoundsPerCubicInchTolerance); - Assert.Equal(DensityUnit.PoundPerCubicInch, poundpercubicinchQuantity.Unit); - - var poundperimperialgallonQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.PoundPerImperialGallon); - AssertEx.EqualTolerance(PoundsPerImperialGallonInOneKilogramPerCubicMeter, (double)poundperimperialgallonQuantity.Value, PoundsPerImperialGallonTolerance); - Assert.Equal(DensityUnit.PoundPerImperialGallon, poundperimperialgallonQuantity.Unit); - - var poundperusgallonQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.PoundPerUSGallon); - AssertEx.EqualTolerance(PoundsPerUSGallonInOneKilogramPerCubicMeter, (double)poundperusgallonQuantity.Value, PoundsPerUSGallonTolerance); - Assert.Equal(DensityUnit.PoundPerUSGallon, poundperusgallonQuantity.Unit); - - var slugpercubicfootQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.SlugPerCubicFoot); - AssertEx.EqualTolerance(SlugsPerCubicFootInOneKilogramPerCubicMeter, (double)slugpercubicfootQuantity.Value, SlugsPerCubicFootTolerance); - Assert.Equal(DensityUnit.SlugPerCubicFoot, slugpercubicfootQuantity.Unit); - - var tonnepercubiccentimeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.TonnePerCubicCentimeter); - AssertEx.EqualTolerance(TonnesPerCubicCentimeterInOneKilogramPerCubicMeter, (double)tonnepercubiccentimeterQuantity.Value, TonnesPerCubicCentimeterTolerance); - Assert.Equal(DensityUnit.TonnePerCubicCentimeter, tonnepercubiccentimeterQuantity.Unit); - - var tonnepercubicmeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.TonnePerCubicMeter); - AssertEx.EqualTolerance(TonnesPerCubicMeterInOneKilogramPerCubicMeter, (double)tonnepercubicmeterQuantity.Value, TonnesPerCubicMeterTolerance); - Assert.Equal(DensityUnit.TonnePerCubicMeter, tonnepercubicmeterQuantity.Unit); - - var tonnepercubicmillimeterQuantity = kilogrampercubicmeter.ToUnit(DensityUnit.TonnePerCubicMillimeter); - AssertEx.EqualTolerance(TonnesPerCubicMillimeterInOneKilogramPerCubicMeter, (double)tonnepercubicmillimeterQuantity.Value, TonnesPerCubicMillimeterTolerance); - Assert.Equal(DensityUnit.TonnePerCubicMillimeter, tonnepercubicmillimeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Density kilogrampercubicmeter = Density.FromKilogramsPerCubicMeter(1); - AssertEx.EqualTolerance(1, Density.FromCentigramsPerDeciLiter(kilogrampercubicmeter.CentigramsPerDeciLiter).KilogramsPerCubicMeter, CentigramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromCentigramsPerLiter(kilogrampercubicmeter.CentigramsPerLiter).KilogramsPerCubicMeter, CentigramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromCentigramsPerMilliliter(kilogrampercubicmeter.CentigramsPerMilliliter).KilogramsPerCubicMeter, CentigramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.FromDecigramsPerDeciLiter(kilogrampercubicmeter.DecigramsPerDeciLiter).KilogramsPerCubicMeter, DecigramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromDecigramsPerLiter(kilogrampercubicmeter.DecigramsPerLiter).KilogramsPerCubicMeter, DecigramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromDecigramsPerMilliliter(kilogrampercubicmeter.DecigramsPerMilliliter).KilogramsPerCubicMeter, DecigramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.FromGramsPerCubicCentimeter(kilogrampercubicmeter.GramsPerCubicCentimeter).KilogramsPerCubicMeter, GramsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, Density.FromGramsPerCubicMeter(kilogrampercubicmeter.GramsPerCubicMeter).KilogramsPerCubicMeter, GramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Density.FromGramsPerCubicMillimeter(kilogrampercubicmeter.GramsPerCubicMillimeter).KilogramsPerCubicMeter, GramsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, Density.FromGramsPerDeciLiter(kilogrampercubicmeter.GramsPerDeciLiter).KilogramsPerCubicMeter, GramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromGramsPerLiter(kilogrampercubicmeter.GramsPerLiter).KilogramsPerCubicMeter, GramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromGramsPerMilliliter(kilogrampercubicmeter.GramsPerMilliliter).KilogramsPerCubicMeter, GramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.FromKilogramsPerCubicCentimeter(kilogrampercubicmeter.KilogramsPerCubicCentimeter).KilogramsPerCubicMeter, KilogramsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, Density.FromKilogramsPerCubicMeter(kilogrampercubicmeter.KilogramsPerCubicMeter).KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Density.FromKilogramsPerCubicMillimeter(kilogrampercubicmeter.KilogramsPerCubicMillimeter).KilogramsPerCubicMeter, KilogramsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, Density.FromKilopoundsPerCubicFoot(kilogrampercubicmeter.KilopoundsPerCubicFoot).KilogramsPerCubicMeter, KilopoundsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, Density.FromKilopoundsPerCubicInch(kilogrampercubicmeter.KilopoundsPerCubicInch).KilogramsPerCubicMeter, KilopoundsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, Density.FromMicrogramsPerDeciLiter(kilogrampercubicmeter.MicrogramsPerDeciLiter).KilogramsPerCubicMeter, MicrogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromMicrogramsPerLiter(kilogrampercubicmeter.MicrogramsPerLiter).KilogramsPerCubicMeter, MicrogramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromMicrogramsPerMilliliter(kilogrampercubicmeter.MicrogramsPerMilliliter).KilogramsPerCubicMeter, MicrogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.FromMilligramsPerCubicMeter(kilogrampercubicmeter.MilligramsPerCubicMeter).KilogramsPerCubicMeter, MilligramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Density.FromMilligramsPerDeciLiter(kilogrampercubicmeter.MilligramsPerDeciLiter).KilogramsPerCubicMeter, MilligramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromMilligramsPerLiter(kilogrampercubicmeter.MilligramsPerLiter).KilogramsPerCubicMeter, MilligramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromMilligramsPerMilliliter(kilogrampercubicmeter.MilligramsPerMilliliter).KilogramsPerCubicMeter, MilligramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.FromNanogramsPerDeciLiter(kilogrampercubicmeter.NanogramsPerDeciLiter).KilogramsPerCubicMeter, NanogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromNanogramsPerLiter(kilogrampercubicmeter.NanogramsPerLiter).KilogramsPerCubicMeter, NanogramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromNanogramsPerMilliliter(kilogrampercubicmeter.NanogramsPerMilliliter).KilogramsPerCubicMeter, NanogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.FromPicogramsPerDeciLiter(kilogrampercubicmeter.PicogramsPerDeciLiter).KilogramsPerCubicMeter, PicogramsPerDeciLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromPicogramsPerLiter(kilogrampercubicmeter.PicogramsPerLiter).KilogramsPerCubicMeter, PicogramsPerLiterTolerance); - AssertEx.EqualTolerance(1, Density.FromPicogramsPerMilliliter(kilogrampercubicmeter.PicogramsPerMilliliter).KilogramsPerCubicMeter, PicogramsPerMilliliterTolerance); - AssertEx.EqualTolerance(1, Density.FromPoundsPerCubicFoot(kilogrampercubicmeter.PoundsPerCubicFoot).KilogramsPerCubicMeter, PoundsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, Density.FromPoundsPerCubicInch(kilogrampercubicmeter.PoundsPerCubicInch).KilogramsPerCubicMeter, PoundsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, Density.FromPoundsPerImperialGallon(kilogrampercubicmeter.PoundsPerImperialGallon).KilogramsPerCubicMeter, PoundsPerImperialGallonTolerance); - AssertEx.EqualTolerance(1, Density.FromPoundsPerUSGallon(kilogrampercubicmeter.PoundsPerUSGallon).KilogramsPerCubicMeter, PoundsPerUSGallonTolerance); - AssertEx.EqualTolerance(1, Density.FromSlugsPerCubicFoot(kilogrampercubicmeter.SlugsPerCubicFoot).KilogramsPerCubicMeter, SlugsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, Density.FromTonnesPerCubicCentimeter(kilogrampercubicmeter.TonnesPerCubicCentimeter).KilogramsPerCubicMeter, TonnesPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, Density.FromTonnesPerCubicMeter(kilogrampercubicmeter.TonnesPerCubicMeter).KilogramsPerCubicMeter, TonnesPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Density.FromTonnesPerCubicMillimeter(kilogrampercubicmeter.TonnesPerCubicMillimeter).KilogramsPerCubicMeter, TonnesPerCubicMillimeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Density v = Density.FromKilogramsPerCubicMeter(1); - AssertEx.EqualTolerance(-1, -v.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (Density.FromKilogramsPerCubicMeter(3)-v).KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (Density.FromKilogramsPerCubicMeter(10)/5).KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, Density.FromKilogramsPerCubicMeter(10)/Density.FromKilogramsPerCubicMeter(5), KilogramsPerCubicMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Density oneKilogramPerCubicMeter = Density.FromKilogramsPerCubicMeter(1); - Density twoKilogramsPerCubicMeter = Density.FromKilogramsPerCubicMeter(2); - - Assert.True(oneKilogramPerCubicMeter < twoKilogramsPerCubicMeter); - Assert.True(oneKilogramPerCubicMeter <= twoKilogramsPerCubicMeter); - Assert.True(twoKilogramsPerCubicMeter > oneKilogramPerCubicMeter); - Assert.True(twoKilogramsPerCubicMeter >= oneKilogramPerCubicMeter); - - Assert.False(oneKilogramPerCubicMeter > twoKilogramsPerCubicMeter); - Assert.False(oneKilogramPerCubicMeter >= twoKilogramsPerCubicMeter); - Assert.False(twoKilogramsPerCubicMeter < oneKilogramPerCubicMeter); - Assert.False(twoKilogramsPerCubicMeter <= oneKilogramPerCubicMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Density kilogrampercubicmeter = Density.FromKilogramsPerCubicMeter(1); - Assert.Equal(0, kilogrampercubicmeter.CompareTo(kilogrampercubicmeter)); - Assert.True(kilogrampercubicmeter.CompareTo(Density.Zero) > 0); - Assert.True(Density.Zero.CompareTo(kilogrampercubicmeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Density kilogrampercubicmeter = Density.FromKilogramsPerCubicMeter(1); - Assert.Throws(() => kilogrampercubicmeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Density kilogrampercubicmeter = Density.FromKilogramsPerCubicMeter(1); - Assert.Throws(() => kilogrampercubicmeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Density v = Density.FromKilogramsPerCubicMeter(1); - Assert.True(v.Equals(Density.FromKilogramsPerCubicMeter(1), KilogramsPerCubicMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Density.Zero, KilogramsPerCubicMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Density kilogrampercubicmeter = Density.FromKilogramsPerCubicMeter(1); - Assert.False(kilogrampercubicmeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Density kilogrampercubicmeter = Density.FromKilogramsPerCubicMeter(1); - Assert.False(kilogrampercubicmeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(DensityUnit.Undefined, Density.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(DensityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == DensityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/DurationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/DurationTestsBase.g.cs deleted file mode 100644 index 72f080eb89..0000000000 --- a/UnitsNet.Tests/GeneratedCode/DurationTestsBase.g.cs +++ /dev/null @@ -1,314 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Duration. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class DurationTestsBase - { - protected abstract double DaysInOneSecond { get; } - protected abstract double HoursInOneSecond { get; } - protected abstract double MicrosecondsInOneSecond { get; } - protected abstract double MillisecondsInOneSecond { get; } - protected abstract double MinutesInOneSecond { get; } - protected abstract double Months30InOneSecond { get; } - protected abstract double NanosecondsInOneSecond { get; } - protected abstract double SecondsInOneSecond { get; } - protected abstract double WeeksInOneSecond { get; } - protected abstract double Years365InOneSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DaysTolerance { get { return 1e-5; } } - protected virtual double HoursTolerance { get { return 1e-5; } } - protected virtual double MicrosecondsTolerance { get { return 1e-5; } } - protected virtual double MillisecondsTolerance { get { return 1e-5; } } - protected virtual double MinutesTolerance { get { return 1e-5; } } - protected virtual double Months30Tolerance { get { return 1e-5; } } - protected virtual double NanosecondsTolerance { get { return 1e-5; } } - protected virtual double SecondsTolerance { get { return 1e-5; } } - protected virtual double WeeksTolerance { get { return 1e-5; } } - protected virtual double Years365Tolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Duration((double)0.0, DurationUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Duration(double.PositiveInfinity, DurationUnit.Second)); - Assert.Throws(() => new Duration(double.NegativeInfinity, DurationUnit.Second)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Duration(double.NaN, DurationUnit.Second)); - } - - [Fact] - public void SecondToDurationUnits() - { - Duration second = Duration.FromSeconds(1); - AssertEx.EqualTolerance(DaysInOneSecond, second.Days, DaysTolerance); - AssertEx.EqualTolerance(HoursInOneSecond, second.Hours, HoursTolerance); - AssertEx.EqualTolerance(MicrosecondsInOneSecond, second.Microseconds, MicrosecondsTolerance); - AssertEx.EqualTolerance(MillisecondsInOneSecond, second.Milliseconds, MillisecondsTolerance); - AssertEx.EqualTolerance(MinutesInOneSecond, second.Minutes, MinutesTolerance); - AssertEx.EqualTolerance(Months30InOneSecond, second.Months30, Months30Tolerance); - AssertEx.EqualTolerance(NanosecondsInOneSecond, second.Nanoseconds, NanosecondsTolerance); - AssertEx.EqualTolerance(SecondsInOneSecond, second.Seconds, SecondsTolerance); - AssertEx.EqualTolerance(WeeksInOneSecond, second.Weeks, WeeksTolerance); - AssertEx.EqualTolerance(Years365InOneSecond, second.Years365, Years365Tolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Day).Days, DaysTolerance); - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Hour).Hours, HoursTolerance); - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Microsecond).Microseconds, MicrosecondsTolerance); - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Millisecond).Milliseconds, MillisecondsTolerance); - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Minute).Minutes, MinutesTolerance); - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Month30).Months30, Months30Tolerance); - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Nanosecond).Nanoseconds, NanosecondsTolerance); - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Second).Seconds, SecondsTolerance); - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Week).Weeks, WeeksTolerance); - AssertEx.EqualTolerance(1, Duration.From(1, DurationUnit.Year365).Years365, Years365Tolerance); - } - - [Fact] - public void FromSeconds_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Duration.FromSeconds(double.PositiveInfinity)); - Assert.Throws(() => Duration.FromSeconds(double.NegativeInfinity)); - } - - [Fact] - public void FromSeconds_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Duration.FromSeconds(double.NaN)); - } - - [Fact] - public void As() - { - var second = Duration.FromSeconds(1); - AssertEx.EqualTolerance(DaysInOneSecond, second.As(DurationUnit.Day), DaysTolerance); - AssertEx.EqualTolerance(HoursInOneSecond, second.As(DurationUnit.Hour), HoursTolerance); - AssertEx.EqualTolerance(MicrosecondsInOneSecond, second.As(DurationUnit.Microsecond), MicrosecondsTolerance); - AssertEx.EqualTolerance(MillisecondsInOneSecond, second.As(DurationUnit.Millisecond), MillisecondsTolerance); - AssertEx.EqualTolerance(MinutesInOneSecond, second.As(DurationUnit.Minute), MinutesTolerance); - AssertEx.EqualTolerance(Months30InOneSecond, second.As(DurationUnit.Month30), Months30Tolerance); - AssertEx.EqualTolerance(NanosecondsInOneSecond, second.As(DurationUnit.Nanosecond), NanosecondsTolerance); - AssertEx.EqualTolerance(SecondsInOneSecond, second.As(DurationUnit.Second), SecondsTolerance); - AssertEx.EqualTolerance(WeeksInOneSecond, second.As(DurationUnit.Week), WeeksTolerance); - AssertEx.EqualTolerance(Years365InOneSecond, second.As(DurationUnit.Year365), Years365Tolerance); - } - - [Fact] - public void ToUnit() - { - var second = Duration.FromSeconds(1); - - var dayQuantity = second.ToUnit(DurationUnit.Day); - AssertEx.EqualTolerance(DaysInOneSecond, (double)dayQuantity.Value, DaysTolerance); - Assert.Equal(DurationUnit.Day, dayQuantity.Unit); - - var hourQuantity = second.ToUnit(DurationUnit.Hour); - AssertEx.EqualTolerance(HoursInOneSecond, (double)hourQuantity.Value, HoursTolerance); - Assert.Equal(DurationUnit.Hour, hourQuantity.Unit); - - var microsecondQuantity = second.ToUnit(DurationUnit.Microsecond); - AssertEx.EqualTolerance(MicrosecondsInOneSecond, (double)microsecondQuantity.Value, MicrosecondsTolerance); - Assert.Equal(DurationUnit.Microsecond, microsecondQuantity.Unit); - - var millisecondQuantity = second.ToUnit(DurationUnit.Millisecond); - AssertEx.EqualTolerance(MillisecondsInOneSecond, (double)millisecondQuantity.Value, MillisecondsTolerance); - Assert.Equal(DurationUnit.Millisecond, millisecondQuantity.Unit); - - var minuteQuantity = second.ToUnit(DurationUnit.Minute); - AssertEx.EqualTolerance(MinutesInOneSecond, (double)minuteQuantity.Value, MinutesTolerance); - Assert.Equal(DurationUnit.Minute, minuteQuantity.Unit); - - var month30Quantity = second.ToUnit(DurationUnit.Month30); - AssertEx.EqualTolerance(Months30InOneSecond, (double)month30Quantity.Value, Months30Tolerance); - Assert.Equal(DurationUnit.Month30, month30Quantity.Unit); - - var nanosecondQuantity = second.ToUnit(DurationUnit.Nanosecond); - AssertEx.EqualTolerance(NanosecondsInOneSecond, (double)nanosecondQuantity.Value, NanosecondsTolerance); - Assert.Equal(DurationUnit.Nanosecond, nanosecondQuantity.Unit); - - var secondQuantity = second.ToUnit(DurationUnit.Second); - AssertEx.EqualTolerance(SecondsInOneSecond, (double)secondQuantity.Value, SecondsTolerance); - Assert.Equal(DurationUnit.Second, secondQuantity.Unit); - - var weekQuantity = second.ToUnit(DurationUnit.Week); - AssertEx.EqualTolerance(WeeksInOneSecond, (double)weekQuantity.Value, WeeksTolerance); - Assert.Equal(DurationUnit.Week, weekQuantity.Unit); - - var year365Quantity = second.ToUnit(DurationUnit.Year365); - AssertEx.EqualTolerance(Years365InOneSecond, (double)year365Quantity.Value, Years365Tolerance); - Assert.Equal(DurationUnit.Year365, year365Quantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Duration second = Duration.FromSeconds(1); - AssertEx.EqualTolerance(1, Duration.FromDays(second.Days).Seconds, DaysTolerance); - AssertEx.EqualTolerance(1, Duration.FromHours(second.Hours).Seconds, HoursTolerance); - AssertEx.EqualTolerance(1, Duration.FromMicroseconds(second.Microseconds).Seconds, MicrosecondsTolerance); - AssertEx.EqualTolerance(1, Duration.FromMilliseconds(second.Milliseconds).Seconds, MillisecondsTolerance); - AssertEx.EqualTolerance(1, Duration.FromMinutes(second.Minutes).Seconds, MinutesTolerance); - AssertEx.EqualTolerance(1, Duration.FromMonths30(second.Months30).Seconds, Months30Tolerance); - AssertEx.EqualTolerance(1, Duration.FromNanoseconds(second.Nanoseconds).Seconds, NanosecondsTolerance); - AssertEx.EqualTolerance(1, Duration.FromSeconds(second.Seconds).Seconds, SecondsTolerance); - AssertEx.EqualTolerance(1, Duration.FromWeeks(second.Weeks).Seconds, WeeksTolerance); - AssertEx.EqualTolerance(1, Duration.FromYears365(second.Years365).Seconds, Years365Tolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Duration v = Duration.FromSeconds(1); - AssertEx.EqualTolerance(-1, -v.Seconds, SecondsTolerance); - AssertEx.EqualTolerance(2, (Duration.FromSeconds(3)-v).Seconds, SecondsTolerance); - AssertEx.EqualTolerance(2, (v + v).Seconds, SecondsTolerance); - AssertEx.EqualTolerance(10, (v*10).Seconds, SecondsTolerance); - AssertEx.EqualTolerance(10, (10*v).Seconds, SecondsTolerance); - AssertEx.EqualTolerance(2, (Duration.FromSeconds(10)/5).Seconds, SecondsTolerance); - AssertEx.EqualTolerance(2, Duration.FromSeconds(10)/Duration.FromSeconds(5), SecondsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Duration oneSecond = Duration.FromSeconds(1); - Duration twoSeconds = Duration.FromSeconds(2); - - Assert.True(oneSecond < twoSeconds); - Assert.True(oneSecond <= twoSeconds); - Assert.True(twoSeconds > oneSecond); - Assert.True(twoSeconds >= oneSecond); - - Assert.False(oneSecond > twoSeconds); - Assert.False(oneSecond >= twoSeconds); - Assert.False(twoSeconds < oneSecond); - Assert.False(twoSeconds <= oneSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - Duration second = Duration.FromSeconds(1); - Assert.Equal(0, second.CompareTo(second)); - Assert.True(second.CompareTo(Duration.Zero) > 0); - Assert.True(Duration.Zero.CompareTo(second) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Duration second = Duration.FromSeconds(1); - Assert.Throws(() => second.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Duration second = Duration.FromSeconds(1); - Assert.Throws(() => second.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Duration v = Duration.FromSeconds(1); - Assert.True(v.Equals(Duration.FromSeconds(1), SecondsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Duration.Zero, SecondsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Duration second = Duration.FromSeconds(1); - Assert.False(second.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Duration second = Duration.FromSeconds(1); - Assert.False(second.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(DurationUnit.Undefined, Duration.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(DurationUnit)).Cast(); - foreach(var unit in units) - { - if(unit == DurationUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/DynamicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/DynamicViscosityTestsBase.g.cs deleted file mode 100644 index 7bfb997f2b..0000000000 --- a/UnitsNet.Tests/GeneratedCode/DynamicViscosityTestsBase.g.cs +++ /dev/null @@ -1,274 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of DynamicViscosity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class DynamicViscosityTestsBase - { - protected abstract double CentipoiseInOneNewtonSecondPerMeterSquared { get; } - protected abstract double MicropascalSecondsInOneNewtonSecondPerMeterSquared { get; } - protected abstract double MillipascalSecondsInOneNewtonSecondPerMeterSquared { get; } - protected abstract double NewtonSecondsPerMeterSquaredInOneNewtonSecondPerMeterSquared { get; } - protected abstract double PascalSecondsInOneNewtonSecondPerMeterSquared { get; } - protected abstract double PoiseInOneNewtonSecondPerMeterSquared { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentipoiseTolerance { get { return 1e-5; } } - protected virtual double MicropascalSecondsTolerance { get { return 1e-5; } } - protected virtual double MillipascalSecondsTolerance { get { return 1e-5; } } - protected virtual double NewtonSecondsPerMeterSquaredTolerance { get { return 1e-5; } } - protected virtual double PascalSecondsTolerance { get { return 1e-5; } } - protected virtual double PoiseTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new DynamicViscosity((double)0.0, DynamicViscosityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new DynamicViscosity(double.PositiveInfinity, DynamicViscosityUnit.NewtonSecondPerMeterSquared)); - Assert.Throws(() => new DynamicViscosity(double.NegativeInfinity, DynamicViscosityUnit.NewtonSecondPerMeterSquared)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new DynamicViscosity(double.NaN, DynamicViscosityUnit.NewtonSecondPerMeterSquared)); - } - - [Fact] - public void NewtonSecondPerMeterSquaredToDynamicViscosityUnits() - { - DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - AssertEx.EqualTolerance(CentipoiseInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.Centipoise, CentipoiseTolerance); - AssertEx.EqualTolerance(MicropascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.MicropascalSeconds, MicropascalSecondsTolerance); - AssertEx.EqualTolerance(MillipascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.MillipascalSeconds, MillipascalSecondsTolerance); - AssertEx.EqualTolerance(NewtonSecondsPerMeterSquaredInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(PascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.PascalSeconds, PascalSecondsTolerance); - AssertEx.EqualTolerance(PoiseInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.Poise, PoiseTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, DynamicViscosity.From(1, DynamicViscosityUnit.Centipoise).Centipoise, CentipoiseTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.From(1, DynamicViscosityUnit.MicropascalSecond).MicropascalSeconds, MicropascalSecondsTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.From(1, DynamicViscosityUnit.MillipascalSecond).MillipascalSeconds, MillipascalSecondsTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.From(1, DynamicViscosityUnit.NewtonSecondPerMeterSquared).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.From(1, DynamicViscosityUnit.PascalSecond).PascalSeconds, PascalSecondsTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.From(1, DynamicViscosityUnit.Poise).Poise, PoiseTolerance); - } - - [Fact] - public void FromNewtonSecondsPerMeterSquared_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => DynamicViscosity.FromNewtonSecondsPerMeterSquared(double.PositiveInfinity)); - Assert.Throws(() => DynamicViscosity.FromNewtonSecondsPerMeterSquared(double.NegativeInfinity)); - } - - [Fact] - public void FromNewtonSecondsPerMeterSquared_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => DynamicViscosity.FromNewtonSecondsPerMeterSquared(double.NaN)); - } - - [Fact] - public void As() - { - var newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - AssertEx.EqualTolerance(CentipoiseInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.Centipoise), CentipoiseTolerance); - AssertEx.EqualTolerance(MicropascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.MicropascalSecond), MicropascalSecondsTolerance); - AssertEx.EqualTolerance(MillipascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.MillipascalSecond), MillipascalSecondsTolerance); - AssertEx.EqualTolerance(NewtonSecondsPerMeterSquaredInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.NewtonSecondPerMeterSquared), NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(PascalSecondsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.PascalSecond), PascalSecondsTolerance); - AssertEx.EqualTolerance(PoiseInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.Poise), PoiseTolerance); - } - - [Fact] - public void ToUnit() - { - var newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - - var centipoiseQuantity = newtonsecondpermetersquared.ToUnit(DynamicViscosityUnit.Centipoise); - AssertEx.EqualTolerance(CentipoiseInOneNewtonSecondPerMeterSquared, (double)centipoiseQuantity.Value, CentipoiseTolerance); - Assert.Equal(DynamicViscosityUnit.Centipoise, centipoiseQuantity.Unit); - - var micropascalsecondQuantity = newtonsecondpermetersquared.ToUnit(DynamicViscosityUnit.MicropascalSecond); - AssertEx.EqualTolerance(MicropascalSecondsInOneNewtonSecondPerMeterSquared, (double)micropascalsecondQuantity.Value, MicropascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MicropascalSecond, micropascalsecondQuantity.Unit); - - var millipascalsecondQuantity = newtonsecondpermetersquared.ToUnit(DynamicViscosityUnit.MillipascalSecond); - AssertEx.EqualTolerance(MillipascalSecondsInOneNewtonSecondPerMeterSquared, (double)millipascalsecondQuantity.Value, MillipascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.MillipascalSecond, millipascalsecondQuantity.Unit); - - var newtonsecondpermetersquaredQuantity = newtonsecondpermetersquared.ToUnit(DynamicViscosityUnit.NewtonSecondPerMeterSquared); - AssertEx.EqualTolerance(NewtonSecondsPerMeterSquaredInOneNewtonSecondPerMeterSquared, (double)newtonsecondpermetersquaredQuantity.Value, NewtonSecondsPerMeterSquaredTolerance); - Assert.Equal(DynamicViscosityUnit.NewtonSecondPerMeterSquared, newtonsecondpermetersquaredQuantity.Unit); - - var pascalsecondQuantity = newtonsecondpermetersquared.ToUnit(DynamicViscosityUnit.PascalSecond); - AssertEx.EqualTolerance(PascalSecondsInOneNewtonSecondPerMeterSquared, (double)pascalsecondQuantity.Value, PascalSecondsTolerance); - Assert.Equal(DynamicViscosityUnit.PascalSecond, pascalsecondQuantity.Unit); - - var poiseQuantity = newtonsecondpermetersquared.ToUnit(DynamicViscosityUnit.Poise); - AssertEx.EqualTolerance(PoiseInOneNewtonSecondPerMeterSquared, (double)poiseQuantity.Value, PoiseTolerance); - Assert.Equal(DynamicViscosityUnit.Poise, poiseQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - AssertEx.EqualTolerance(1, DynamicViscosity.FromCentipoise(newtonsecondpermetersquared.Centipoise).NewtonSecondsPerMeterSquared, CentipoiseTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.FromMicropascalSeconds(newtonsecondpermetersquared.MicropascalSeconds).NewtonSecondsPerMeterSquared, MicropascalSecondsTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.FromMillipascalSeconds(newtonsecondpermetersquared.MillipascalSeconds).NewtonSecondsPerMeterSquared, MillipascalSecondsTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.FromNewtonSecondsPerMeterSquared(newtonsecondpermetersquared.NewtonSecondsPerMeterSquared).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.FromPascalSeconds(newtonsecondpermetersquared.PascalSeconds).NewtonSecondsPerMeterSquared, PascalSecondsTolerance); - AssertEx.EqualTolerance(1, DynamicViscosity.FromPoise(newtonsecondpermetersquared.Poise).NewtonSecondsPerMeterSquared, PoiseTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - DynamicViscosity v = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - AssertEx.EqualTolerance(-1, -v.NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(2, (DynamicViscosity.FromNewtonSecondsPerMeterSquared(3)-v).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(2, (v + v).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(10, (v*10).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(10, (10*v).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(2, (DynamicViscosity.FromNewtonSecondsPerMeterSquared(10)/5).NewtonSecondsPerMeterSquared, NewtonSecondsPerMeterSquaredTolerance); - AssertEx.EqualTolerance(2, DynamicViscosity.FromNewtonSecondsPerMeterSquared(10)/DynamicViscosity.FromNewtonSecondsPerMeterSquared(5), NewtonSecondsPerMeterSquaredTolerance); - } - - [Fact] - public void ComparisonOperators() - { - DynamicViscosity oneNewtonSecondPerMeterSquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - DynamicViscosity twoNewtonSecondsPerMeterSquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(2); - - Assert.True(oneNewtonSecondPerMeterSquared < twoNewtonSecondsPerMeterSquared); - Assert.True(oneNewtonSecondPerMeterSquared <= twoNewtonSecondsPerMeterSquared); - Assert.True(twoNewtonSecondsPerMeterSquared > oneNewtonSecondPerMeterSquared); - Assert.True(twoNewtonSecondsPerMeterSquared >= oneNewtonSecondPerMeterSquared); - - Assert.False(oneNewtonSecondPerMeterSquared > twoNewtonSecondsPerMeterSquared); - Assert.False(oneNewtonSecondPerMeterSquared >= twoNewtonSecondsPerMeterSquared); - Assert.False(twoNewtonSecondsPerMeterSquared < oneNewtonSecondPerMeterSquared); - Assert.False(twoNewtonSecondsPerMeterSquared <= oneNewtonSecondPerMeterSquared); - } - - [Fact] - public void CompareToIsImplemented() - { - DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - Assert.Equal(0, newtonsecondpermetersquared.CompareTo(newtonsecondpermetersquared)); - Assert.True(newtonsecondpermetersquared.CompareTo(DynamicViscosity.Zero) > 0); - Assert.True(DynamicViscosity.Zero.CompareTo(newtonsecondpermetersquared) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - Assert.Throws(() => newtonsecondpermetersquared.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - Assert.Throws(() => newtonsecondpermetersquared.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - DynamicViscosity v = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - Assert.True(v.Equals(DynamicViscosity.FromNewtonSecondsPerMeterSquared(1), NewtonSecondsPerMeterSquaredTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(DynamicViscosity.Zero, NewtonSecondsPerMeterSquaredTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - Assert.False(newtonsecondpermetersquared.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - DynamicViscosity newtonsecondpermetersquared = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1); - Assert.False(newtonsecondpermetersquared.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(DynamicViscosityUnit.Undefined, DynamicViscosity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(DynamicViscosityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == DynamicViscosityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricAdmittanceTestsBase.g.cs deleted file mode 100644 index 38917b9776..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricAdmittanceTestsBase.g.cs +++ /dev/null @@ -1,254 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricAdmittance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricAdmittanceTestsBase - { - protected abstract double MicrosiemensInOneSiemens { get; } - protected abstract double MillisiemensInOneSiemens { get; } - protected abstract double NanosiemensInOneSiemens { get; } - protected abstract double SiemensInOneSiemens { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double MicrosiemensTolerance { get { return 1e-5; } } - protected virtual double MillisiemensTolerance { get { return 1e-5; } } - protected virtual double NanosiemensTolerance { get { return 1e-5; } } - protected virtual double SiemensTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricAdmittance((double)0.0, ElectricAdmittanceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricAdmittance(double.PositiveInfinity, ElectricAdmittanceUnit.Siemens)); - Assert.Throws(() => new ElectricAdmittance(double.NegativeInfinity, ElectricAdmittanceUnit.Siemens)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricAdmittance(double.NaN, ElectricAdmittanceUnit.Siemens)); - } - - [Fact] - public void SiemensToElectricAdmittanceUnits() - { - ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1); - AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.Microsiemens, MicrosiemensTolerance); - AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.Millisiemens, MillisiemensTolerance); - AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.Nanosiemens, NanosiemensTolerance); - AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.Siemens, SiemensTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricAdmittance.From(1, ElectricAdmittanceUnit.Microsiemens).Microsiemens, MicrosiemensTolerance); - AssertEx.EqualTolerance(1, ElectricAdmittance.From(1, ElectricAdmittanceUnit.Millisiemens).Millisiemens, MillisiemensTolerance); - AssertEx.EqualTolerance(1, ElectricAdmittance.From(1, ElectricAdmittanceUnit.Nanosiemens).Nanosiemens, NanosiemensTolerance); - AssertEx.EqualTolerance(1, ElectricAdmittance.From(1, ElectricAdmittanceUnit.Siemens).Siemens, SiemensTolerance); - } - - [Fact] - public void FromSiemens_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricAdmittance.FromSiemens(double.PositiveInfinity)); - Assert.Throws(() => ElectricAdmittance.FromSiemens(double.NegativeInfinity)); - } - - [Fact] - public void FromSiemens_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricAdmittance.FromSiemens(double.NaN)); - } - - [Fact] - public void As() - { - var siemens = ElectricAdmittance.FromSiemens(1); - AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Microsiemens), MicrosiemensTolerance); - AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Millisiemens), MillisiemensTolerance); - AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Nanosiemens), NanosiemensTolerance); - AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Siemens), SiemensTolerance); - } - - [Fact] - public void ToUnit() - { - var siemens = ElectricAdmittance.FromSiemens(1); - - var microsiemensQuantity = siemens.ToUnit(ElectricAdmittanceUnit.Microsiemens); - AssertEx.EqualTolerance(MicrosiemensInOneSiemens, (double)microsiemensQuantity.Value, MicrosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Microsiemens, microsiemensQuantity.Unit); - - var millisiemensQuantity = siemens.ToUnit(ElectricAdmittanceUnit.Millisiemens); - AssertEx.EqualTolerance(MillisiemensInOneSiemens, (double)millisiemensQuantity.Value, MillisiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Millisiemens, millisiemensQuantity.Unit); - - var nanosiemensQuantity = siemens.ToUnit(ElectricAdmittanceUnit.Nanosiemens); - AssertEx.EqualTolerance(NanosiemensInOneSiemens, (double)nanosiemensQuantity.Value, NanosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Nanosiemens, nanosiemensQuantity.Unit); - - var siemensQuantity = siemens.ToUnit(ElectricAdmittanceUnit.Siemens); - AssertEx.EqualTolerance(SiemensInOneSiemens, (double)siemensQuantity.Value, SiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Siemens, siemensQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1); - AssertEx.EqualTolerance(1, ElectricAdmittance.FromMicrosiemens(siemens.Microsiemens).Siemens, MicrosiemensTolerance); - AssertEx.EqualTolerance(1, ElectricAdmittance.FromMillisiemens(siemens.Millisiemens).Siemens, MillisiemensTolerance); - AssertEx.EqualTolerance(1, ElectricAdmittance.FromNanosiemens(siemens.Nanosiemens).Siemens, NanosiemensTolerance); - AssertEx.EqualTolerance(1, ElectricAdmittance.FromSiemens(siemens.Siemens).Siemens, SiemensTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricAdmittance v = ElectricAdmittance.FromSiemens(1); - AssertEx.EqualTolerance(-1, -v.Siemens, SiemensTolerance); - AssertEx.EqualTolerance(2, (ElectricAdmittance.FromSiemens(3)-v).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(2, (v + v).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(10, (v*10).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(10, (10*v).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(2, (ElectricAdmittance.FromSiemens(10)/5).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(2, ElectricAdmittance.FromSiemens(10)/ElectricAdmittance.FromSiemens(5), SiemensTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricAdmittance oneSiemens = ElectricAdmittance.FromSiemens(1); - ElectricAdmittance twoSiemens = ElectricAdmittance.FromSiemens(2); - - Assert.True(oneSiemens < twoSiemens); - Assert.True(oneSiemens <= twoSiemens); - Assert.True(twoSiemens > oneSiemens); - Assert.True(twoSiemens >= oneSiemens); - - Assert.False(oneSiemens > twoSiemens); - Assert.False(oneSiemens >= twoSiemens); - Assert.False(twoSiemens < oneSiemens); - Assert.False(twoSiemens <= oneSiemens); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1); - Assert.Equal(0, siemens.CompareTo(siemens)); - Assert.True(siemens.CompareTo(ElectricAdmittance.Zero) > 0); - Assert.True(ElectricAdmittance.Zero.CompareTo(siemens) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1); - Assert.Throws(() => siemens.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1); - Assert.Throws(() => siemens.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricAdmittance v = ElectricAdmittance.FromSiemens(1); - Assert.True(v.Equals(ElectricAdmittance.FromSiemens(1), SiemensTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricAdmittance.Zero, SiemensTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1); - Assert.False(siemens.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1); - Assert.False(siemens.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricAdmittanceUnit.Undefined, ElectricAdmittance.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricAdmittanceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricAdmittanceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricChargeDensityTestsBase.g.cs deleted file mode 100644 index 9e9f244019..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricChargeDensityTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricChargeDensity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricChargeDensityTestsBase - { - protected abstract double CoulombsPerCubicMeterInOneCoulombPerCubicMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CoulombsPerCubicMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricChargeDensity((double)0.0, ElectricChargeDensityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricChargeDensity(double.PositiveInfinity, ElectricChargeDensityUnit.CoulombPerCubicMeter)); - Assert.Throws(() => new ElectricChargeDensity(double.NegativeInfinity, ElectricChargeDensityUnit.CoulombPerCubicMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricChargeDensity(double.NaN, ElectricChargeDensityUnit.CoulombPerCubicMeter)); - } - - [Fact] - public void CoulombPerCubicMeterToElectricChargeDensityUnits() - { - ElectricChargeDensity coulombpercubicmeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - AssertEx.EqualTolerance(CoulombsPerCubicMeterInOneCoulombPerCubicMeter, coulombpercubicmeter.CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricChargeDensity.From(1, ElectricChargeDensityUnit.CoulombPerCubicMeter).CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - } - - [Fact] - public void FromCoulombsPerCubicMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricChargeDensity.FromCoulombsPerCubicMeter(double.PositiveInfinity)); - Assert.Throws(() => ElectricChargeDensity.FromCoulombsPerCubicMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromCoulombsPerCubicMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricChargeDensity.FromCoulombsPerCubicMeter(double.NaN)); - } - - [Fact] - public void As() - { - var coulombpercubicmeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - AssertEx.EqualTolerance(CoulombsPerCubicMeterInOneCoulombPerCubicMeter, coulombpercubicmeter.As(ElectricChargeDensityUnit.CoulombPerCubicMeter), CoulombsPerCubicMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var coulombpercubicmeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - - var coulombpercubicmeterQuantity = coulombpercubicmeter.ToUnit(ElectricChargeDensityUnit.CoulombPerCubicMeter); - AssertEx.EqualTolerance(CoulombsPerCubicMeterInOneCoulombPerCubicMeter, (double)coulombpercubicmeterQuantity.Value, CoulombsPerCubicMeterTolerance); - Assert.Equal(ElectricChargeDensityUnit.CoulombPerCubicMeter, coulombpercubicmeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricChargeDensity coulombpercubicmeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - AssertEx.EqualTolerance(1, ElectricChargeDensity.FromCoulombsPerCubicMeter(coulombpercubicmeter.CoulombsPerCubicMeter).CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricChargeDensity v = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - AssertEx.EqualTolerance(-1, -v.CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (ElectricChargeDensity.FromCoulombsPerCubicMeter(3)-v).CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (ElectricChargeDensity.FromCoulombsPerCubicMeter(10)/5).CoulombsPerCubicMeter, CoulombsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, ElectricChargeDensity.FromCoulombsPerCubicMeter(10)/ElectricChargeDensity.FromCoulombsPerCubicMeter(5), CoulombsPerCubicMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricChargeDensity oneCoulombPerCubicMeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - ElectricChargeDensity twoCoulombsPerCubicMeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(2); - - Assert.True(oneCoulombPerCubicMeter < twoCoulombsPerCubicMeter); - Assert.True(oneCoulombPerCubicMeter <= twoCoulombsPerCubicMeter); - Assert.True(twoCoulombsPerCubicMeter > oneCoulombPerCubicMeter); - Assert.True(twoCoulombsPerCubicMeter >= oneCoulombPerCubicMeter); - - Assert.False(oneCoulombPerCubicMeter > twoCoulombsPerCubicMeter); - Assert.False(oneCoulombPerCubicMeter >= twoCoulombsPerCubicMeter); - Assert.False(twoCoulombsPerCubicMeter < oneCoulombPerCubicMeter); - Assert.False(twoCoulombsPerCubicMeter <= oneCoulombPerCubicMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricChargeDensity coulombpercubicmeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - Assert.Equal(0, coulombpercubicmeter.CompareTo(coulombpercubicmeter)); - Assert.True(coulombpercubicmeter.CompareTo(ElectricChargeDensity.Zero) > 0); - Assert.True(ElectricChargeDensity.Zero.CompareTo(coulombpercubicmeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricChargeDensity coulombpercubicmeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - Assert.Throws(() => coulombpercubicmeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricChargeDensity coulombpercubicmeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - Assert.Throws(() => coulombpercubicmeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricChargeDensity v = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - Assert.True(v.Equals(ElectricChargeDensity.FromCoulombsPerCubicMeter(1), CoulombsPerCubicMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricChargeDensity.Zero, CoulombsPerCubicMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricChargeDensity coulombpercubicmeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - Assert.False(coulombpercubicmeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricChargeDensity coulombpercubicmeter = ElectricChargeDensity.FromCoulombsPerCubicMeter(1); - Assert.False(coulombpercubicmeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricChargeDensityUnit.Undefined, ElectricChargeDensity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricChargeDensityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricChargeDensityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricChargeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricChargeTestsBase.g.cs deleted file mode 100644 index eda26be3cb..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricChargeTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricCharge. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricChargeTestsBase - { - protected abstract double CoulombsInOneCoulomb { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CoulombsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCharge((double)0.0, ElectricChargeUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCharge(double.PositiveInfinity, ElectricChargeUnit.Coulomb)); - Assert.Throws(() => new ElectricCharge(double.NegativeInfinity, ElectricChargeUnit.Coulomb)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCharge(double.NaN, ElectricChargeUnit.Coulomb)); - } - - [Fact] - public void CoulombToElectricChargeUnits() - { - ElectricCharge coulomb = ElectricCharge.FromCoulombs(1); - AssertEx.EqualTolerance(CoulombsInOneCoulomb, coulomb.Coulombs, CoulombsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricCharge.From(1, ElectricChargeUnit.Coulomb).Coulombs, CoulombsTolerance); - } - - [Fact] - public void FromCoulombs_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricCharge.FromCoulombs(double.PositiveInfinity)); - Assert.Throws(() => ElectricCharge.FromCoulombs(double.NegativeInfinity)); - } - - [Fact] - public void FromCoulombs_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricCharge.FromCoulombs(double.NaN)); - } - - [Fact] - public void As() - { - var coulomb = ElectricCharge.FromCoulombs(1); - AssertEx.EqualTolerance(CoulombsInOneCoulomb, coulomb.As(ElectricChargeUnit.Coulomb), CoulombsTolerance); - } - - [Fact] - public void ToUnit() - { - var coulomb = ElectricCharge.FromCoulombs(1); - - var coulombQuantity = coulomb.ToUnit(ElectricChargeUnit.Coulomb); - AssertEx.EqualTolerance(CoulombsInOneCoulomb, (double)coulombQuantity.Value, CoulombsTolerance); - Assert.Equal(ElectricChargeUnit.Coulomb, coulombQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricCharge coulomb = ElectricCharge.FromCoulombs(1); - AssertEx.EqualTolerance(1, ElectricCharge.FromCoulombs(coulomb.Coulombs).Coulombs, CoulombsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricCharge v = ElectricCharge.FromCoulombs(1); - AssertEx.EqualTolerance(-1, -v.Coulombs, CoulombsTolerance); - AssertEx.EqualTolerance(2, (ElectricCharge.FromCoulombs(3)-v).Coulombs, CoulombsTolerance); - AssertEx.EqualTolerance(2, (v + v).Coulombs, CoulombsTolerance); - AssertEx.EqualTolerance(10, (v*10).Coulombs, CoulombsTolerance); - AssertEx.EqualTolerance(10, (10*v).Coulombs, CoulombsTolerance); - AssertEx.EqualTolerance(2, (ElectricCharge.FromCoulombs(10)/5).Coulombs, CoulombsTolerance); - AssertEx.EqualTolerance(2, ElectricCharge.FromCoulombs(10)/ElectricCharge.FromCoulombs(5), CoulombsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricCharge oneCoulomb = ElectricCharge.FromCoulombs(1); - ElectricCharge twoCoulombs = ElectricCharge.FromCoulombs(2); - - Assert.True(oneCoulomb < twoCoulombs); - Assert.True(oneCoulomb <= twoCoulombs); - Assert.True(twoCoulombs > oneCoulomb); - Assert.True(twoCoulombs >= oneCoulomb); - - Assert.False(oneCoulomb > twoCoulombs); - Assert.False(oneCoulomb >= twoCoulombs); - Assert.False(twoCoulombs < oneCoulomb); - Assert.False(twoCoulombs <= oneCoulomb); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricCharge coulomb = ElectricCharge.FromCoulombs(1); - Assert.Equal(0, coulomb.CompareTo(coulomb)); - Assert.True(coulomb.CompareTo(ElectricCharge.Zero) > 0); - Assert.True(ElectricCharge.Zero.CompareTo(coulomb) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricCharge coulomb = ElectricCharge.FromCoulombs(1); - Assert.Throws(() => coulomb.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricCharge coulomb = ElectricCharge.FromCoulombs(1); - Assert.Throws(() => coulomb.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricCharge v = ElectricCharge.FromCoulombs(1); - Assert.True(v.Equals(ElectricCharge.FromCoulombs(1), CoulombsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricCharge.Zero, CoulombsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricCharge coulomb = ElectricCharge.FromCoulombs(1); - Assert.False(coulomb.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricCharge coulomb = ElectricCharge.FromCoulombs(1); - Assert.False(coulomb.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricChargeUnit.Undefined, ElectricCharge.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricChargeUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricChargeUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricConductanceTestsBase.g.cs deleted file mode 100644 index 9ed876aeed..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricConductanceTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricConductance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricConductanceTestsBase - { - protected abstract double MicrosiemensInOneSiemens { get; } - protected abstract double MillisiemensInOneSiemens { get; } - protected abstract double SiemensInOneSiemens { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double MicrosiemensTolerance { get { return 1e-5; } } - protected virtual double MillisiemensTolerance { get { return 1e-5; } } - protected virtual double SiemensTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricConductance((double)0.0, ElectricConductanceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricConductance(double.PositiveInfinity, ElectricConductanceUnit.Siemens)); - Assert.Throws(() => new ElectricConductance(double.NegativeInfinity, ElectricConductanceUnit.Siemens)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricConductance(double.NaN, ElectricConductanceUnit.Siemens)); - } - - [Fact] - public void SiemensToElectricConductanceUnits() - { - ElectricConductance siemens = ElectricConductance.FromSiemens(1); - AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.Microsiemens, MicrosiemensTolerance); - AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.Millisiemens, MillisiemensTolerance); - AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.Siemens, SiemensTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricConductance.From(1, ElectricConductanceUnit.Microsiemens).Microsiemens, MicrosiemensTolerance); - AssertEx.EqualTolerance(1, ElectricConductance.From(1, ElectricConductanceUnit.Millisiemens).Millisiemens, MillisiemensTolerance); - AssertEx.EqualTolerance(1, ElectricConductance.From(1, ElectricConductanceUnit.Siemens).Siemens, SiemensTolerance); - } - - [Fact] - public void FromSiemens_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricConductance.FromSiemens(double.PositiveInfinity)); - Assert.Throws(() => ElectricConductance.FromSiemens(double.NegativeInfinity)); - } - - [Fact] - public void FromSiemens_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricConductance.FromSiemens(double.NaN)); - } - - [Fact] - public void As() - { - var siemens = ElectricConductance.FromSiemens(1); - AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Microsiemens), MicrosiemensTolerance); - AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Millisiemens), MillisiemensTolerance); - AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Siemens), SiemensTolerance); - } - - [Fact] - public void ToUnit() - { - var siemens = ElectricConductance.FromSiemens(1); - - var microsiemensQuantity = siemens.ToUnit(ElectricConductanceUnit.Microsiemens); - AssertEx.EqualTolerance(MicrosiemensInOneSiemens, (double)microsiemensQuantity.Value, MicrosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Microsiemens, microsiemensQuantity.Unit); - - var millisiemensQuantity = siemens.ToUnit(ElectricConductanceUnit.Millisiemens); - AssertEx.EqualTolerance(MillisiemensInOneSiemens, (double)millisiemensQuantity.Value, MillisiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Millisiemens, millisiemensQuantity.Unit); - - var siemensQuantity = siemens.ToUnit(ElectricConductanceUnit.Siemens); - AssertEx.EqualTolerance(SiemensInOneSiemens, (double)siemensQuantity.Value, SiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Siemens, siemensQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricConductance siemens = ElectricConductance.FromSiemens(1); - AssertEx.EqualTolerance(1, ElectricConductance.FromMicrosiemens(siemens.Microsiemens).Siemens, MicrosiemensTolerance); - AssertEx.EqualTolerance(1, ElectricConductance.FromMillisiemens(siemens.Millisiemens).Siemens, MillisiemensTolerance); - AssertEx.EqualTolerance(1, ElectricConductance.FromSiemens(siemens.Siemens).Siemens, SiemensTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricConductance v = ElectricConductance.FromSiemens(1); - AssertEx.EqualTolerance(-1, -v.Siemens, SiemensTolerance); - AssertEx.EqualTolerance(2, (ElectricConductance.FromSiemens(3)-v).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(2, (v + v).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(10, (v*10).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(10, (10*v).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(2, (ElectricConductance.FromSiemens(10)/5).Siemens, SiemensTolerance); - AssertEx.EqualTolerance(2, ElectricConductance.FromSiemens(10)/ElectricConductance.FromSiemens(5), SiemensTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricConductance oneSiemens = ElectricConductance.FromSiemens(1); - ElectricConductance twoSiemens = ElectricConductance.FromSiemens(2); - - Assert.True(oneSiemens < twoSiemens); - Assert.True(oneSiemens <= twoSiemens); - Assert.True(twoSiemens > oneSiemens); - Assert.True(twoSiemens >= oneSiemens); - - Assert.False(oneSiemens > twoSiemens); - Assert.False(oneSiemens >= twoSiemens); - Assert.False(twoSiemens < oneSiemens); - Assert.False(twoSiemens <= oneSiemens); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricConductance siemens = ElectricConductance.FromSiemens(1); - Assert.Equal(0, siemens.CompareTo(siemens)); - Assert.True(siemens.CompareTo(ElectricConductance.Zero) > 0); - Assert.True(ElectricConductance.Zero.CompareTo(siemens) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricConductance siemens = ElectricConductance.FromSiemens(1); - Assert.Throws(() => siemens.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricConductance siemens = ElectricConductance.FromSiemens(1); - Assert.Throws(() => siemens.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricConductance v = ElectricConductance.FromSiemens(1); - Assert.True(v.Equals(ElectricConductance.FromSiemens(1), SiemensTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricConductance.Zero, SiemensTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricConductance siemens = ElectricConductance.FromSiemens(1); - Assert.False(siemens.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricConductance siemens = ElectricConductance.FromSiemens(1); - Assert.False(siemens.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricConductanceUnit.Undefined, ElectricConductance.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricConductanceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricConductanceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricConductivityTestsBase.g.cs deleted file mode 100644 index ea049f0f48..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricConductivityTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricConductivity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricConductivityTestsBase - { - protected abstract double SiemensPerMeterInOneSiemensPerMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double SiemensPerMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricConductivity((double)0.0, ElectricConductivityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricConductivity(double.PositiveInfinity, ElectricConductivityUnit.SiemensPerMeter)); - Assert.Throws(() => new ElectricConductivity(double.NegativeInfinity, ElectricConductivityUnit.SiemensPerMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricConductivity(double.NaN, ElectricConductivityUnit.SiemensPerMeter)); - } - - [Fact] - public void SiemensPerMeterToElectricConductivityUnits() - { - ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); - AssertEx.EqualTolerance(SiemensPerMeterInOneSiemensPerMeter, siemenspermeter.SiemensPerMeter, SiemensPerMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricConductivity.From(1, ElectricConductivityUnit.SiemensPerMeter).SiemensPerMeter, SiemensPerMeterTolerance); - } - - [Fact] - public void FromSiemensPerMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricConductivity.FromSiemensPerMeter(double.PositiveInfinity)); - Assert.Throws(() => ElectricConductivity.FromSiemensPerMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromSiemensPerMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricConductivity.FromSiemensPerMeter(double.NaN)); - } - - [Fact] - public void As() - { - var siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); - AssertEx.EqualTolerance(SiemensPerMeterInOneSiemensPerMeter, siemenspermeter.As(ElectricConductivityUnit.SiemensPerMeter), SiemensPerMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); - - var siemenspermeterQuantity = siemenspermeter.ToUnit(ElectricConductivityUnit.SiemensPerMeter); - AssertEx.EqualTolerance(SiemensPerMeterInOneSiemensPerMeter, (double)siemenspermeterQuantity.Value, SiemensPerMeterTolerance); - Assert.Equal(ElectricConductivityUnit.SiemensPerMeter, siemenspermeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); - AssertEx.EqualTolerance(1, ElectricConductivity.FromSiemensPerMeter(siemenspermeter.SiemensPerMeter).SiemensPerMeter, SiemensPerMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricConductivity v = ElectricConductivity.FromSiemensPerMeter(1); - AssertEx.EqualTolerance(-1, -v.SiemensPerMeter, SiemensPerMeterTolerance); - AssertEx.EqualTolerance(2, (ElectricConductivity.FromSiemensPerMeter(3)-v).SiemensPerMeter, SiemensPerMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).SiemensPerMeter, SiemensPerMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).SiemensPerMeter, SiemensPerMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).SiemensPerMeter, SiemensPerMeterTolerance); - AssertEx.EqualTolerance(2, (ElectricConductivity.FromSiemensPerMeter(10)/5).SiemensPerMeter, SiemensPerMeterTolerance); - AssertEx.EqualTolerance(2, ElectricConductivity.FromSiemensPerMeter(10)/ElectricConductivity.FromSiemensPerMeter(5), SiemensPerMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricConductivity oneSiemensPerMeter = ElectricConductivity.FromSiemensPerMeter(1); - ElectricConductivity twoSiemensPerMeter = ElectricConductivity.FromSiemensPerMeter(2); - - Assert.True(oneSiemensPerMeter < twoSiemensPerMeter); - Assert.True(oneSiemensPerMeter <= twoSiemensPerMeter); - Assert.True(twoSiemensPerMeter > oneSiemensPerMeter); - Assert.True(twoSiemensPerMeter >= oneSiemensPerMeter); - - Assert.False(oneSiemensPerMeter > twoSiemensPerMeter); - Assert.False(oneSiemensPerMeter >= twoSiemensPerMeter); - Assert.False(twoSiemensPerMeter < oneSiemensPerMeter); - Assert.False(twoSiemensPerMeter <= oneSiemensPerMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); - Assert.Equal(0, siemenspermeter.CompareTo(siemenspermeter)); - Assert.True(siemenspermeter.CompareTo(ElectricConductivity.Zero) > 0); - Assert.True(ElectricConductivity.Zero.CompareTo(siemenspermeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); - Assert.Throws(() => siemenspermeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); - Assert.Throws(() => siemenspermeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricConductivity v = ElectricConductivity.FromSiemensPerMeter(1); - Assert.True(v.Equals(ElectricConductivity.FromSiemensPerMeter(1), SiemensPerMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricConductivity.Zero, SiemensPerMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); - Assert.False(siemenspermeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); - Assert.False(siemenspermeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricConductivityUnit.Undefined, ElectricConductivity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricConductivityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricConductivityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricCurrentDensityTestsBase.g.cs deleted file mode 100644 index dd5e6399ba..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricCurrentDensityTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricCurrentDensity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricCurrentDensityTestsBase - { - protected abstract double AmperesPerSquareMeterInOneAmperePerSquareMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double AmperesPerSquareMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCurrentDensity((double)0.0, ElectricCurrentDensityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCurrentDensity(double.PositiveInfinity, ElectricCurrentDensityUnit.AmperePerSquareMeter)); - Assert.Throws(() => new ElectricCurrentDensity(double.NegativeInfinity, ElectricCurrentDensityUnit.AmperePerSquareMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCurrentDensity(double.NaN, ElectricCurrentDensityUnit.AmperePerSquareMeter)); - } - - [Fact] - public void AmperePerSquareMeterToElectricCurrentDensityUnits() - { - ElectricCurrentDensity amperepersquaremeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - AssertEx.EqualTolerance(AmperesPerSquareMeterInOneAmperePerSquareMeter, amperepersquaremeter.AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricCurrentDensity.From(1, ElectricCurrentDensityUnit.AmperePerSquareMeter).AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - } - - [Fact] - public void FromAmperesPerSquareMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricCurrentDensity.FromAmperesPerSquareMeter(double.PositiveInfinity)); - Assert.Throws(() => ElectricCurrentDensity.FromAmperesPerSquareMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromAmperesPerSquareMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricCurrentDensity.FromAmperesPerSquareMeter(double.NaN)); - } - - [Fact] - public void As() - { - var amperepersquaremeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - AssertEx.EqualTolerance(AmperesPerSquareMeterInOneAmperePerSquareMeter, amperepersquaremeter.As(ElectricCurrentDensityUnit.AmperePerSquareMeter), AmperesPerSquareMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var amperepersquaremeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - - var amperepersquaremeterQuantity = amperepersquaremeter.ToUnit(ElectricCurrentDensityUnit.AmperePerSquareMeter); - AssertEx.EqualTolerance(AmperesPerSquareMeterInOneAmperePerSquareMeter, (double)amperepersquaremeterQuantity.Value, AmperesPerSquareMeterTolerance); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareMeter, amperepersquaremeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricCurrentDensity amperepersquaremeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - AssertEx.EqualTolerance(1, ElectricCurrentDensity.FromAmperesPerSquareMeter(amperepersquaremeter.AmperesPerSquareMeter).AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricCurrentDensity v = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - AssertEx.EqualTolerance(-1, -v.AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (ElectricCurrentDensity.FromAmperesPerSquareMeter(3)-v).AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (ElectricCurrentDensity.FromAmperesPerSquareMeter(10)/5).AmperesPerSquareMeter, AmperesPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, ElectricCurrentDensity.FromAmperesPerSquareMeter(10)/ElectricCurrentDensity.FromAmperesPerSquareMeter(5), AmperesPerSquareMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricCurrentDensity oneAmperePerSquareMeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - ElectricCurrentDensity twoAmperesPerSquareMeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(2); - - Assert.True(oneAmperePerSquareMeter < twoAmperesPerSquareMeter); - Assert.True(oneAmperePerSquareMeter <= twoAmperesPerSquareMeter); - Assert.True(twoAmperesPerSquareMeter > oneAmperePerSquareMeter); - Assert.True(twoAmperesPerSquareMeter >= oneAmperePerSquareMeter); - - Assert.False(oneAmperePerSquareMeter > twoAmperesPerSquareMeter); - Assert.False(oneAmperePerSquareMeter >= twoAmperesPerSquareMeter); - Assert.False(twoAmperesPerSquareMeter < oneAmperePerSquareMeter); - Assert.False(twoAmperesPerSquareMeter <= oneAmperePerSquareMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricCurrentDensity amperepersquaremeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - Assert.Equal(0, amperepersquaremeter.CompareTo(amperepersquaremeter)); - Assert.True(amperepersquaremeter.CompareTo(ElectricCurrentDensity.Zero) > 0); - Assert.True(ElectricCurrentDensity.Zero.CompareTo(amperepersquaremeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricCurrentDensity amperepersquaremeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - Assert.Throws(() => amperepersquaremeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricCurrentDensity amperepersquaremeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - Assert.Throws(() => amperepersquaremeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricCurrentDensity v = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - Assert.True(v.Equals(ElectricCurrentDensity.FromAmperesPerSquareMeter(1), AmperesPerSquareMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricCurrentDensity.Zero, AmperesPerSquareMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricCurrentDensity amperepersquaremeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - Assert.False(amperepersquaremeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricCurrentDensity amperepersquaremeter = ElectricCurrentDensity.FromAmperesPerSquareMeter(1); - Assert.False(amperepersquaremeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricCurrentDensityUnit.Undefined, ElectricCurrentDensity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricCurrentDensityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricCurrentDensityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricCurrentGradientTestsBase.g.cs deleted file mode 100644 index fe5682a5fe..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricCurrentGradientTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricCurrentGradient. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricCurrentGradientTestsBase - { - protected abstract double AmperesPerSecondInOneAmperePerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double AmperesPerSecondTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCurrentGradient((double)0.0, ElectricCurrentGradientUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCurrentGradient(double.PositiveInfinity, ElectricCurrentGradientUnit.AmperePerSecond)); - Assert.Throws(() => new ElectricCurrentGradient(double.NegativeInfinity, ElectricCurrentGradientUnit.AmperePerSecond)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCurrentGradient(double.NaN, ElectricCurrentGradientUnit.AmperePerSecond)); - } - - [Fact] - public void AmperePerSecondToElectricCurrentGradientUnits() - { - ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - AssertEx.EqualTolerance(AmperesPerSecondInOneAmperePerSecond, amperepersecond.AmperesPerSecond, AmperesPerSecondTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricCurrentGradient.From(1, ElectricCurrentGradientUnit.AmperePerSecond).AmperesPerSecond, AmperesPerSecondTolerance); - } - - [Fact] - public void FromAmperesPerSecond_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricCurrentGradient.FromAmperesPerSecond(double.PositiveInfinity)); - Assert.Throws(() => ElectricCurrentGradient.FromAmperesPerSecond(double.NegativeInfinity)); - } - - [Fact] - public void FromAmperesPerSecond_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricCurrentGradient.FromAmperesPerSecond(double.NaN)); - } - - [Fact] - public void As() - { - var amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - AssertEx.EqualTolerance(AmperesPerSecondInOneAmperePerSecond, amperepersecond.As(ElectricCurrentGradientUnit.AmperePerSecond), AmperesPerSecondTolerance); - } - - [Fact] - public void ToUnit() - { - var amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - - var amperepersecondQuantity = amperepersecond.ToUnit(ElectricCurrentGradientUnit.AmperePerSecond); - AssertEx.EqualTolerance(AmperesPerSecondInOneAmperePerSecond, (double)amperepersecondQuantity.Value, AmperesPerSecondTolerance); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerSecond, amperepersecondQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - AssertEx.EqualTolerance(1, ElectricCurrentGradient.FromAmperesPerSecond(amperepersecond.AmperesPerSecond).AmperesPerSecond, AmperesPerSecondTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricCurrentGradient v = ElectricCurrentGradient.FromAmperesPerSecond(1); - AssertEx.EqualTolerance(-1, -v.AmperesPerSecond, AmperesPerSecondTolerance); - AssertEx.EqualTolerance(2, (ElectricCurrentGradient.FromAmperesPerSecond(3)-v).AmperesPerSecond, AmperesPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).AmperesPerSecond, AmperesPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).AmperesPerSecond, AmperesPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).AmperesPerSecond, AmperesPerSecondTolerance); - AssertEx.EqualTolerance(2, (ElectricCurrentGradient.FromAmperesPerSecond(10)/5).AmperesPerSecond, AmperesPerSecondTolerance); - AssertEx.EqualTolerance(2, ElectricCurrentGradient.FromAmperesPerSecond(10)/ElectricCurrentGradient.FromAmperesPerSecond(5), AmperesPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricCurrentGradient oneAmperePerSecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - ElectricCurrentGradient twoAmperesPerSecond = ElectricCurrentGradient.FromAmperesPerSecond(2); - - Assert.True(oneAmperePerSecond < twoAmperesPerSecond); - Assert.True(oneAmperePerSecond <= twoAmperesPerSecond); - Assert.True(twoAmperesPerSecond > oneAmperePerSecond); - Assert.True(twoAmperesPerSecond >= oneAmperePerSecond); - - Assert.False(oneAmperePerSecond > twoAmperesPerSecond); - Assert.False(oneAmperePerSecond >= twoAmperesPerSecond); - Assert.False(twoAmperesPerSecond < oneAmperePerSecond); - Assert.False(twoAmperesPerSecond <= oneAmperePerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - Assert.Equal(0, amperepersecond.CompareTo(amperepersecond)); - Assert.True(amperepersecond.CompareTo(ElectricCurrentGradient.Zero) > 0); - Assert.True(ElectricCurrentGradient.Zero.CompareTo(amperepersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - Assert.Throws(() => amperepersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - Assert.Throws(() => amperepersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricCurrentGradient v = ElectricCurrentGradient.FromAmperesPerSecond(1); - Assert.True(v.Equals(ElectricCurrentGradient.FromAmperesPerSecond(1), AmperesPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricCurrentGradient.Zero, AmperesPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - Assert.False(amperepersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); - Assert.False(amperepersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricCurrentGradientUnit.Undefined, ElectricCurrentGradient.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricCurrentGradientUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricCurrentGradientUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricCurrentTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricCurrentTestsBase.g.cs deleted file mode 100644 index 3fd63c38a0..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricCurrentTestsBase.g.cs +++ /dev/null @@ -1,294 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricCurrent. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricCurrentTestsBase - { - protected abstract double AmperesInOneAmpere { get; } - protected abstract double CentiamperesInOneAmpere { get; } - protected abstract double KiloamperesInOneAmpere { get; } - protected abstract double MegaamperesInOneAmpere { get; } - protected abstract double MicroamperesInOneAmpere { get; } - protected abstract double MilliamperesInOneAmpere { get; } - protected abstract double NanoamperesInOneAmpere { get; } - protected abstract double PicoamperesInOneAmpere { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double AmperesTolerance { get { return 1e-5; } } - protected virtual double CentiamperesTolerance { get { return 1e-5; } } - protected virtual double KiloamperesTolerance { get { return 1e-5; } } - protected virtual double MegaamperesTolerance { get { return 1e-5; } } - protected virtual double MicroamperesTolerance { get { return 1e-5; } } - protected virtual double MilliamperesTolerance { get { return 1e-5; } } - protected virtual double NanoamperesTolerance { get { return 1e-5; } } - protected virtual double PicoamperesTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCurrent((double)0.0, ElectricCurrentUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCurrent(double.PositiveInfinity, ElectricCurrentUnit.Ampere)); - Assert.Throws(() => new ElectricCurrent(double.NegativeInfinity, ElectricCurrentUnit.Ampere)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricCurrent(double.NaN, ElectricCurrentUnit.Ampere)); - } - - [Fact] - public void AmpereToElectricCurrentUnits() - { - ElectricCurrent ampere = ElectricCurrent.FromAmperes(1); - AssertEx.EqualTolerance(AmperesInOneAmpere, ampere.Amperes, AmperesTolerance); - AssertEx.EqualTolerance(CentiamperesInOneAmpere, ampere.Centiamperes, CentiamperesTolerance); - AssertEx.EqualTolerance(KiloamperesInOneAmpere, ampere.Kiloamperes, KiloamperesTolerance); - AssertEx.EqualTolerance(MegaamperesInOneAmpere, ampere.Megaamperes, MegaamperesTolerance); - AssertEx.EqualTolerance(MicroamperesInOneAmpere, ampere.Microamperes, MicroamperesTolerance); - AssertEx.EqualTolerance(MilliamperesInOneAmpere, ampere.Milliamperes, MilliamperesTolerance); - AssertEx.EqualTolerance(NanoamperesInOneAmpere, ampere.Nanoamperes, NanoamperesTolerance); - AssertEx.EqualTolerance(PicoamperesInOneAmpere, ampere.Picoamperes, PicoamperesTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Ampere).Amperes, AmperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Centiampere).Centiamperes, CentiamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Kiloampere).Kiloamperes, KiloamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Megaampere).Megaamperes, MegaamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Microampere).Microamperes, MicroamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Milliampere).Milliamperes, MilliamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Nanoampere).Nanoamperes, NanoamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.From(1, ElectricCurrentUnit.Picoampere).Picoamperes, PicoamperesTolerance); - } - - [Fact] - public void FromAmperes_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricCurrent.FromAmperes(double.PositiveInfinity)); - Assert.Throws(() => ElectricCurrent.FromAmperes(double.NegativeInfinity)); - } - - [Fact] - public void FromAmperes_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricCurrent.FromAmperes(double.NaN)); - } - - [Fact] - public void As() - { - var ampere = ElectricCurrent.FromAmperes(1); - AssertEx.EqualTolerance(AmperesInOneAmpere, ampere.As(ElectricCurrentUnit.Ampere), AmperesTolerance); - AssertEx.EqualTolerance(CentiamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Centiampere), CentiamperesTolerance); - AssertEx.EqualTolerance(KiloamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Kiloampere), KiloamperesTolerance); - AssertEx.EqualTolerance(MegaamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Megaampere), MegaamperesTolerance); - AssertEx.EqualTolerance(MicroamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Microampere), MicroamperesTolerance); - AssertEx.EqualTolerance(MilliamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Milliampere), MilliamperesTolerance); - AssertEx.EqualTolerance(NanoamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Nanoampere), NanoamperesTolerance); - AssertEx.EqualTolerance(PicoamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Picoampere), PicoamperesTolerance); - } - - [Fact] - public void ToUnit() - { - var ampere = ElectricCurrent.FromAmperes(1); - - var ampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Ampere); - AssertEx.EqualTolerance(AmperesInOneAmpere, (double)ampereQuantity.Value, AmperesTolerance); - Assert.Equal(ElectricCurrentUnit.Ampere, ampereQuantity.Unit); - - var centiampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Centiampere); - AssertEx.EqualTolerance(CentiamperesInOneAmpere, (double)centiampereQuantity.Value, CentiamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Centiampere, centiampereQuantity.Unit); - - var kiloampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Kiloampere); - AssertEx.EqualTolerance(KiloamperesInOneAmpere, (double)kiloampereQuantity.Value, KiloamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Kiloampere, kiloampereQuantity.Unit); - - var megaampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Megaampere); - AssertEx.EqualTolerance(MegaamperesInOneAmpere, (double)megaampereQuantity.Value, MegaamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Megaampere, megaampereQuantity.Unit); - - var microampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Microampere); - AssertEx.EqualTolerance(MicroamperesInOneAmpere, (double)microampereQuantity.Value, MicroamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Microampere, microampereQuantity.Unit); - - var milliampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Milliampere); - AssertEx.EqualTolerance(MilliamperesInOneAmpere, (double)milliampereQuantity.Value, MilliamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Milliampere, milliampereQuantity.Unit); - - var nanoampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Nanoampere); - AssertEx.EqualTolerance(NanoamperesInOneAmpere, (double)nanoampereQuantity.Value, NanoamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Nanoampere, nanoampereQuantity.Unit); - - var picoampereQuantity = ampere.ToUnit(ElectricCurrentUnit.Picoampere); - AssertEx.EqualTolerance(PicoamperesInOneAmpere, (double)picoampereQuantity.Value, PicoamperesTolerance); - Assert.Equal(ElectricCurrentUnit.Picoampere, picoampereQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricCurrent ampere = ElectricCurrent.FromAmperes(1); - AssertEx.EqualTolerance(1, ElectricCurrent.FromAmperes(ampere.Amperes).Amperes, AmperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.FromCentiamperes(ampere.Centiamperes).Amperes, CentiamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.FromKiloamperes(ampere.Kiloamperes).Amperes, KiloamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.FromMegaamperes(ampere.Megaamperes).Amperes, MegaamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.FromMicroamperes(ampere.Microamperes).Amperes, MicroamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.FromMilliamperes(ampere.Milliamperes).Amperes, MilliamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.FromNanoamperes(ampere.Nanoamperes).Amperes, NanoamperesTolerance); - AssertEx.EqualTolerance(1, ElectricCurrent.FromPicoamperes(ampere.Picoamperes).Amperes, PicoamperesTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricCurrent v = ElectricCurrent.FromAmperes(1); - AssertEx.EqualTolerance(-1, -v.Amperes, AmperesTolerance); - AssertEx.EqualTolerance(2, (ElectricCurrent.FromAmperes(3)-v).Amperes, AmperesTolerance); - AssertEx.EqualTolerance(2, (v + v).Amperes, AmperesTolerance); - AssertEx.EqualTolerance(10, (v*10).Amperes, AmperesTolerance); - AssertEx.EqualTolerance(10, (10*v).Amperes, AmperesTolerance); - AssertEx.EqualTolerance(2, (ElectricCurrent.FromAmperes(10)/5).Amperes, AmperesTolerance); - AssertEx.EqualTolerance(2, ElectricCurrent.FromAmperes(10)/ElectricCurrent.FromAmperes(5), AmperesTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricCurrent oneAmpere = ElectricCurrent.FromAmperes(1); - ElectricCurrent twoAmperes = ElectricCurrent.FromAmperes(2); - - Assert.True(oneAmpere < twoAmperes); - Assert.True(oneAmpere <= twoAmperes); - Assert.True(twoAmperes > oneAmpere); - Assert.True(twoAmperes >= oneAmpere); - - Assert.False(oneAmpere > twoAmperes); - Assert.False(oneAmpere >= twoAmperes); - Assert.False(twoAmperes < oneAmpere); - Assert.False(twoAmperes <= oneAmpere); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricCurrent ampere = ElectricCurrent.FromAmperes(1); - Assert.Equal(0, ampere.CompareTo(ampere)); - Assert.True(ampere.CompareTo(ElectricCurrent.Zero) > 0); - Assert.True(ElectricCurrent.Zero.CompareTo(ampere) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricCurrent ampere = ElectricCurrent.FromAmperes(1); - Assert.Throws(() => ampere.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricCurrent ampere = ElectricCurrent.FromAmperes(1); - Assert.Throws(() => ampere.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricCurrent v = ElectricCurrent.FromAmperes(1); - Assert.True(v.Equals(ElectricCurrent.FromAmperes(1), AmperesTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricCurrent.Zero, AmperesTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricCurrent ampere = ElectricCurrent.FromAmperes(1); - Assert.False(ampere.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricCurrent ampere = ElectricCurrent.FromAmperes(1); - Assert.False(ampere.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricCurrentUnit.Undefined, ElectricCurrent.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricCurrentUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricCurrentUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricFieldTestsBase.g.cs deleted file mode 100644 index 3d74928898..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricFieldTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricField. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricFieldTestsBase - { - protected abstract double VoltsPerMeterInOneVoltPerMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double VoltsPerMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricField((double)0.0, ElectricFieldUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricField(double.PositiveInfinity, ElectricFieldUnit.VoltPerMeter)); - Assert.Throws(() => new ElectricField(double.NegativeInfinity, ElectricFieldUnit.VoltPerMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricField(double.NaN, ElectricFieldUnit.VoltPerMeter)); - } - - [Fact] - public void VoltPerMeterToElectricFieldUnits() - { - ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); - AssertEx.EqualTolerance(VoltsPerMeterInOneVoltPerMeter, voltpermeter.VoltsPerMeter, VoltsPerMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricField.From(1, ElectricFieldUnit.VoltPerMeter).VoltsPerMeter, VoltsPerMeterTolerance); - } - - [Fact] - public void FromVoltsPerMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricField.FromVoltsPerMeter(double.PositiveInfinity)); - Assert.Throws(() => ElectricField.FromVoltsPerMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromVoltsPerMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricField.FromVoltsPerMeter(double.NaN)); - } - - [Fact] - public void As() - { - var voltpermeter = ElectricField.FromVoltsPerMeter(1); - AssertEx.EqualTolerance(VoltsPerMeterInOneVoltPerMeter, voltpermeter.As(ElectricFieldUnit.VoltPerMeter), VoltsPerMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var voltpermeter = ElectricField.FromVoltsPerMeter(1); - - var voltpermeterQuantity = voltpermeter.ToUnit(ElectricFieldUnit.VoltPerMeter); - AssertEx.EqualTolerance(VoltsPerMeterInOneVoltPerMeter, (double)voltpermeterQuantity.Value, VoltsPerMeterTolerance); - Assert.Equal(ElectricFieldUnit.VoltPerMeter, voltpermeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); - AssertEx.EqualTolerance(1, ElectricField.FromVoltsPerMeter(voltpermeter.VoltsPerMeter).VoltsPerMeter, VoltsPerMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricField v = ElectricField.FromVoltsPerMeter(1); - AssertEx.EqualTolerance(-1, -v.VoltsPerMeter, VoltsPerMeterTolerance); - AssertEx.EqualTolerance(2, (ElectricField.FromVoltsPerMeter(3)-v).VoltsPerMeter, VoltsPerMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltsPerMeter, VoltsPerMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltsPerMeter, VoltsPerMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltsPerMeter, VoltsPerMeterTolerance); - AssertEx.EqualTolerance(2, (ElectricField.FromVoltsPerMeter(10)/5).VoltsPerMeter, VoltsPerMeterTolerance); - AssertEx.EqualTolerance(2, ElectricField.FromVoltsPerMeter(10)/ElectricField.FromVoltsPerMeter(5), VoltsPerMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricField oneVoltPerMeter = ElectricField.FromVoltsPerMeter(1); - ElectricField twoVoltsPerMeter = ElectricField.FromVoltsPerMeter(2); - - Assert.True(oneVoltPerMeter < twoVoltsPerMeter); - Assert.True(oneVoltPerMeter <= twoVoltsPerMeter); - Assert.True(twoVoltsPerMeter > oneVoltPerMeter); - Assert.True(twoVoltsPerMeter >= oneVoltPerMeter); - - Assert.False(oneVoltPerMeter > twoVoltsPerMeter); - Assert.False(oneVoltPerMeter >= twoVoltsPerMeter); - Assert.False(twoVoltsPerMeter < oneVoltPerMeter); - Assert.False(twoVoltsPerMeter <= oneVoltPerMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); - Assert.Equal(0, voltpermeter.CompareTo(voltpermeter)); - Assert.True(voltpermeter.CompareTo(ElectricField.Zero) > 0); - Assert.True(ElectricField.Zero.CompareTo(voltpermeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); - Assert.Throws(() => voltpermeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); - Assert.Throws(() => voltpermeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricField v = ElectricField.FromVoltsPerMeter(1); - Assert.True(v.Equals(ElectricField.FromVoltsPerMeter(1), VoltsPerMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricField.Zero, VoltsPerMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); - Assert.False(voltpermeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); - Assert.False(voltpermeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricFieldUnit.Undefined, ElectricField.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricFieldUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricFieldUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricInductanceTestsBase.g.cs deleted file mode 100644 index 0200aec8be..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricInductanceTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricInductance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricInductanceTestsBase - { - protected abstract double HenriesInOneHenry { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double HenriesTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricInductance((double)0.0, ElectricInductanceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricInductance(double.PositiveInfinity, ElectricInductanceUnit.Henry)); - Assert.Throws(() => new ElectricInductance(double.NegativeInfinity, ElectricInductanceUnit.Henry)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricInductance(double.NaN, ElectricInductanceUnit.Henry)); - } - - [Fact] - public void HenryToElectricInductanceUnits() - { - ElectricInductance henry = ElectricInductance.FromHenries(1); - AssertEx.EqualTolerance(HenriesInOneHenry, henry.Henries, HenriesTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricInductance.From(1, ElectricInductanceUnit.Henry).Henries, HenriesTolerance); - } - - [Fact] - public void FromHenries_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricInductance.FromHenries(double.PositiveInfinity)); - Assert.Throws(() => ElectricInductance.FromHenries(double.NegativeInfinity)); - } - - [Fact] - public void FromHenries_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricInductance.FromHenries(double.NaN)); - } - - [Fact] - public void As() - { - var henry = ElectricInductance.FromHenries(1); - AssertEx.EqualTolerance(HenriesInOneHenry, henry.As(ElectricInductanceUnit.Henry), HenriesTolerance); - } - - [Fact] - public void ToUnit() - { - var henry = ElectricInductance.FromHenries(1); - - var henryQuantity = henry.ToUnit(ElectricInductanceUnit.Henry); - AssertEx.EqualTolerance(HenriesInOneHenry, (double)henryQuantity.Value, HenriesTolerance); - Assert.Equal(ElectricInductanceUnit.Henry, henryQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricInductance henry = ElectricInductance.FromHenries(1); - AssertEx.EqualTolerance(1, ElectricInductance.FromHenries(henry.Henries).Henries, HenriesTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricInductance v = ElectricInductance.FromHenries(1); - AssertEx.EqualTolerance(-1, -v.Henries, HenriesTolerance); - AssertEx.EqualTolerance(2, (ElectricInductance.FromHenries(3)-v).Henries, HenriesTolerance); - AssertEx.EqualTolerance(2, (v + v).Henries, HenriesTolerance); - AssertEx.EqualTolerance(10, (v*10).Henries, HenriesTolerance); - AssertEx.EqualTolerance(10, (10*v).Henries, HenriesTolerance); - AssertEx.EqualTolerance(2, (ElectricInductance.FromHenries(10)/5).Henries, HenriesTolerance); - AssertEx.EqualTolerance(2, ElectricInductance.FromHenries(10)/ElectricInductance.FromHenries(5), HenriesTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricInductance oneHenry = ElectricInductance.FromHenries(1); - ElectricInductance twoHenries = ElectricInductance.FromHenries(2); - - Assert.True(oneHenry < twoHenries); - Assert.True(oneHenry <= twoHenries); - Assert.True(twoHenries > oneHenry); - Assert.True(twoHenries >= oneHenry); - - Assert.False(oneHenry > twoHenries); - Assert.False(oneHenry >= twoHenries); - Assert.False(twoHenries < oneHenry); - Assert.False(twoHenries <= oneHenry); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricInductance henry = ElectricInductance.FromHenries(1); - Assert.Equal(0, henry.CompareTo(henry)); - Assert.True(henry.CompareTo(ElectricInductance.Zero) > 0); - Assert.True(ElectricInductance.Zero.CompareTo(henry) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricInductance henry = ElectricInductance.FromHenries(1); - Assert.Throws(() => henry.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricInductance henry = ElectricInductance.FromHenries(1); - Assert.Throws(() => henry.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricInductance v = ElectricInductance.FromHenries(1); - Assert.True(v.Equals(ElectricInductance.FromHenries(1), HenriesTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricInductance.Zero, HenriesTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricInductance henry = ElectricInductance.FromHenries(1); - Assert.False(henry.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricInductance henry = ElectricInductance.FromHenries(1); - Assert.False(henry.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricInductanceUnit.Undefined, ElectricInductance.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricInductanceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricInductanceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricPotentialAcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricPotentialAcTestsBase.g.cs deleted file mode 100644 index 7b4d02bbcb..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricPotentialAcTestsBase.g.cs +++ /dev/null @@ -1,264 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricPotentialAc. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricPotentialAcTestsBase - { - protected abstract double KilovoltsAcInOneVoltAc { get; } - protected abstract double MegavoltsAcInOneVoltAc { get; } - protected abstract double MicrovoltsAcInOneVoltAc { get; } - protected abstract double MillivoltsAcInOneVoltAc { get; } - protected abstract double VoltsAcInOneVoltAc { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilovoltsAcTolerance { get { return 1e-5; } } - protected virtual double MegavoltsAcTolerance { get { return 1e-5; } } - protected virtual double MicrovoltsAcTolerance { get { return 1e-5; } } - protected virtual double MillivoltsAcTolerance { get { return 1e-5; } } - protected virtual double VoltsAcTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialAc((double)0.0, ElectricPotentialAcUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialAc(double.PositiveInfinity, ElectricPotentialAcUnit.VoltAc)); - Assert.Throws(() => new ElectricPotentialAc(double.NegativeInfinity, ElectricPotentialAcUnit.VoltAc)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialAc(double.NaN, ElectricPotentialAcUnit.VoltAc)); - } - - [Fact] - public void VoltAcToElectricPotentialAcUnits() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - AssertEx.EqualTolerance(KilovoltsAcInOneVoltAc, voltac.KilovoltsAc, KilovoltsAcTolerance); - AssertEx.EqualTolerance(MegavoltsAcInOneVoltAc, voltac.MegavoltsAc, MegavoltsAcTolerance); - AssertEx.EqualTolerance(MicrovoltsAcInOneVoltAc, voltac.MicrovoltsAc, MicrovoltsAcTolerance); - AssertEx.EqualTolerance(MillivoltsAcInOneVoltAc, voltac.MillivoltsAc, MillivoltsAcTolerance); - AssertEx.EqualTolerance(VoltsAcInOneVoltAc, voltac.VoltsAc, VoltsAcTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricPotentialAc.From(1, ElectricPotentialAcUnit.KilovoltAc).KilovoltsAc, KilovoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.From(1, ElectricPotentialAcUnit.MegavoltAc).MegavoltsAc, MegavoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.From(1, ElectricPotentialAcUnit.MicrovoltAc).MicrovoltsAc, MicrovoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.From(1, ElectricPotentialAcUnit.MillivoltAc).MillivoltsAc, MillivoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.From(1, ElectricPotentialAcUnit.VoltAc).VoltsAc, VoltsAcTolerance); - } - - [Fact] - public void FromVoltsAc_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotentialAc.FromVoltsAc(double.PositiveInfinity)); - Assert.Throws(() => ElectricPotentialAc.FromVoltsAc(double.NegativeInfinity)); - } - - [Fact] - public void FromVoltsAc_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotentialAc.FromVoltsAc(double.NaN)); - } - - [Fact] - public void As() - { - var voltac = ElectricPotentialAc.FromVoltsAc(1); - AssertEx.EqualTolerance(KilovoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.KilovoltAc), KilovoltsAcTolerance); - AssertEx.EqualTolerance(MegavoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.MegavoltAc), MegavoltsAcTolerance); - AssertEx.EqualTolerance(MicrovoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.MicrovoltAc), MicrovoltsAcTolerance); - AssertEx.EqualTolerance(MillivoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.MillivoltAc), MillivoltsAcTolerance); - AssertEx.EqualTolerance(VoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.VoltAc), VoltsAcTolerance); - } - - [Fact] - public void ToUnit() - { - var voltac = ElectricPotentialAc.FromVoltsAc(1); - - var kilovoltacQuantity = voltac.ToUnit(ElectricPotentialAcUnit.KilovoltAc); - AssertEx.EqualTolerance(KilovoltsAcInOneVoltAc, (double)kilovoltacQuantity.Value, KilovoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.KilovoltAc, kilovoltacQuantity.Unit); - - var megavoltacQuantity = voltac.ToUnit(ElectricPotentialAcUnit.MegavoltAc); - AssertEx.EqualTolerance(MegavoltsAcInOneVoltAc, (double)megavoltacQuantity.Value, MegavoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MegavoltAc, megavoltacQuantity.Unit); - - var microvoltacQuantity = voltac.ToUnit(ElectricPotentialAcUnit.MicrovoltAc); - AssertEx.EqualTolerance(MicrovoltsAcInOneVoltAc, (double)microvoltacQuantity.Value, MicrovoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MicrovoltAc, microvoltacQuantity.Unit); - - var millivoltacQuantity = voltac.ToUnit(ElectricPotentialAcUnit.MillivoltAc); - AssertEx.EqualTolerance(MillivoltsAcInOneVoltAc, (double)millivoltacQuantity.Value, MillivoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MillivoltAc, millivoltacQuantity.Unit); - - var voltacQuantity = voltac.ToUnit(ElectricPotentialAcUnit.VoltAc); - AssertEx.EqualTolerance(VoltsAcInOneVoltAc, (double)voltacQuantity.Value, VoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.VoltAc, voltacQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromKilovoltsAc(voltac.KilovoltsAc).VoltsAc, KilovoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromMegavoltsAc(voltac.MegavoltsAc).VoltsAc, MegavoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromMicrovoltsAc(voltac.MicrovoltsAc).VoltsAc, MicrovoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromMillivoltsAc(voltac.MillivoltsAc).VoltsAc, MillivoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromVoltsAc(voltac.VoltsAc).VoltsAc, VoltsAcTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricPotentialAc v = ElectricPotentialAc.FromVoltsAc(1); - AssertEx.EqualTolerance(-1, -v.VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(2, (ElectricPotentialAc.FromVoltsAc(3)-v).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(2, (ElectricPotentialAc.FromVoltsAc(10)/5).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(2, ElectricPotentialAc.FromVoltsAc(10)/ElectricPotentialAc.FromVoltsAc(5), VoltsAcTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricPotentialAc oneVoltAc = ElectricPotentialAc.FromVoltsAc(1); - ElectricPotentialAc twoVoltsAc = ElectricPotentialAc.FromVoltsAc(2); - - Assert.True(oneVoltAc < twoVoltsAc); - Assert.True(oneVoltAc <= twoVoltsAc); - Assert.True(twoVoltsAc > oneVoltAc); - Assert.True(twoVoltsAc >= oneVoltAc); - - Assert.False(oneVoltAc > twoVoltsAc); - Assert.False(oneVoltAc >= twoVoltsAc); - Assert.False(twoVoltsAc < oneVoltAc); - Assert.False(twoVoltsAc <= oneVoltAc); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.Equal(0, voltac.CompareTo(voltac)); - Assert.True(voltac.CompareTo(ElectricPotentialAc.Zero) > 0); - Assert.True(ElectricPotentialAc.Zero.CompareTo(voltac) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.Throws(() => voltac.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.Throws(() => voltac.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricPotentialAc v = ElectricPotentialAc.FromVoltsAc(1); - Assert.True(v.Equals(ElectricPotentialAc.FromVoltsAc(1), VoltsAcTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricPotentialAc.Zero, VoltsAcTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.False(voltac.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.False(voltac.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricPotentialAcUnit.Undefined, ElectricPotentialAc.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricPotentialAcUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricPotentialAcUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricPotentialDcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricPotentialDcTestsBase.g.cs deleted file mode 100644 index 35bfbf279b..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricPotentialDcTestsBase.g.cs +++ /dev/null @@ -1,264 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricPotentialDc. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricPotentialDcTestsBase - { - protected abstract double KilovoltsDcInOneVoltDc { get; } - protected abstract double MegavoltsDcInOneVoltDc { get; } - protected abstract double MicrovoltsDcInOneVoltDc { get; } - protected abstract double MillivoltsDcInOneVoltDc { get; } - protected abstract double VoltsDcInOneVoltDc { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilovoltsDcTolerance { get { return 1e-5; } } - protected virtual double MegavoltsDcTolerance { get { return 1e-5; } } - protected virtual double MicrovoltsDcTolerance { get { return 1e-5; } } - protected virtual double MillivoltsDcTolerance { get { return 1e-5; } } - protected virtual double VoltsDcTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialDc((double)0.0, ElectricPotentialDcUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialDc(double.PositiveInfinity, ElectricPotentialDcUnit.VoltDc)); - Assert.Throws(() => new ElectricPotentialDc(double.NegativeInfinity, ElectricPotentialDcUnit.VoltDc)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialDc(double.NaN, ElectricPotentialDcUnit.VoltDc)); - } - - [Fact] - public void VoltDcToElectricPotentialDcUnits() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - AssertEx.EqualTolerance(KilovoltsDcInOneVoltDc, voltdc.KilovoltsDc, KilovoltsDcTolerance); - AssertEx.EqualTolerance(MegavoltsDcInOneVoltDc, voltdc.MegavoltsDc, MegavoltsDcTolerance); - AssertEx.EqualTolerance(MicrovoltsDcInOneVoltDc, voltdc.MicrovoltsDc, MicrovoltsDcTolerance); - AssertEx.EqualTolerance(MillivoltsDcInOneVoltDc, voltdc.MillivoltsDc, MillivoltsDcTolerance); - AssertEx.EqualTolerance(VoltsDcInOneVoltDc, voltdc.VoltsDc, VoltsDcTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricPotentialDc.From(1, ElectricPotentialDcUnit.KilovoltDc).KilovoltsDc, KilovoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.From(1, ElectricPotentialDcUnit.MegavoltDc).MegavoltsDc, MegavoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.From(1, ElectricPotentialDcUnit.MicrovoltDc).MicrovoltsDc, MicrovoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.From(1, ElectricPotentialDcUnit.MillivoltDc).MillivoltsDc, MillivoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.From(1, ElectricPotentialDcUnit.VoltDc).VoltsDc, VoltsDcTolerance); - } - - [Fact] - public void FromVoltsDc_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotentialDc.FromVoltsDc(double.PositiveInfinity)); - Assert.Throws(() => ElectricPotentialDc.FromVoltsDc(double.NegativeInfinity)); - } - - [Fact] - public void FromVoltsDc_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotentialDc.FromVoltsDc(double.NaN)); - } - - [Fact] - public void As() - { - var voltdc = ElectricPotentialDc.FromVoltsDc(1); - AssertEx.EqualTolerance(KilovoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.KilovoltDc), KilovoltsDcTolerance); - AssertEx.EqualTolerance(MegavoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.MegavoltDc), MegavoltsDcTolerance); - AssertEx.EqualTolerance(MicrovoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.MicrovoltDc), MicrovoltsDcTolerance); - AssertEx.EqualTolerance(MillivoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.MillivoltDc), MillivoltsDcTolerance); - AssertEx.EqualTolerance(VoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.VoltDc), VoltsDcTolerance); - } - - [Fact] - public void ToUnit() - { - var voltdc = ElectricPotentialDc.FromVoltsDc(1); - - var kilovoltdcQuantity = voltdc.ToUnit(ElectricPotentialDcUnit.KilovoltDc); - AssertEx.EqualTolerance(KilovoltsDcInOneVoltDc, (double)kilovoltdcQuantity.Value, KilovoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.KilovoltDc, kilovoltdcQuantity.Unit); - - var megavoltdcQuantity = voltdc.ToUnit(ElectricPotentialDcUnit.MegavoltDc); - AssertEx.EqualTolerance(MegavoltsDcInOneVoltDc, (double)megavoltdcQuantity.Value, MegavoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MegavoltDc, megavoltdcQuantity.Unit); - - var microvoltdcQuantity = voltdc.ToUnit(ElectricPotentialDcUnit.MicrovoltDc); - AssertEx.EqualTolerance(MicrovoltsDcInOneVoltDc, (double)microvoltdcQuantity.Value, MicrovoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MicrovoltDc, microvoltdcQuantity.Unit); - - var millivoltdcQuantity = voltdc.ToUnit(ElectricPotentialDcUnit.MillivoltDc); - AssertEx.EqualTolerance(MillivoltsDcInOneVoltDc, (double)millivoltdcQuantity.Value, MillivoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MillivoltDc, millivoltdcQuantity.Unit); - - var voltdcQuantity = voltdc.ToUnit(ElectricPotentialDcUnit.VoltDc); - AssertEx.EqualTolerance(VoltsDcInOneVoltDc, (double)voltdcQuantity.Value, VoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.VoltDc, voltdcQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromKilovoltsDc(voltdc.KilovoltsDc).VoltsDc, KilovoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromMegavoltsDc(voltdc.MegavoltsDc).VoltsDc, MegavoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromMicrovoltsDc(voltdc.MicrovoltsDc).VoltsDc, MicrovoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromMillivoltsDc(voltdc.MillivoltsDc).VoltsDc, MillivoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromVoltsDc(voltdc.VoltsDc).VoltsDc, VoltsDcTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricPotentialDc v = ElectricPotentialDc.FromVoltsDc(1); - AssertEx.EqualTolerance(-1, -v.VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(2, (ElectricPotentialDc.FromVoltsDc(3)-v).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(2, (ElectricPotentialDc.FromVoltsDc(10)/5).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(2, ElectricPotentialDc.FromVoltsDc(10)/ElectricPotentialDc.FromVoltsDc(5), VoltsDcTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricPotentialDc oneVoltDc = ElectricPotentialDc.FromVoltsDc(1); - ElectricPotentialDc twoVoltsDc = ElectricPotentialDc.FromVoltsDc(2); - - Assert.True(oneVoltDc < twoVoltsDc); - Assert.True(oneVoltDc <= twoVoltsDc); - Assert.True(twoVoltsDc > oneVoltDc); - Assert.True(twoVoltsDc >= oneVoltDc); - - Assert.False(oneVoltDc > twoVoltsDc); - Assert.False(oneVoltDc >= twoVoltsDc); - Assert.False(twoVoltsDc < oneVoltDc); - Assert.False(twoVoltsDc <= oneVoltDc); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.Equal(0, voltdc.CompareTo(voltdc)); - Assert.True(voltdc.CompareTo(ElectricPotentialDc.Zero) > 0); - Assert.True(ElectricPotentialDc.Zero.CompareTo(voltdc) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.Throws(() => voltdc.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.Throws(() => voltdc.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricPotentialDc v = ElectricPotentialDc.FromVoltsDc(1); - Assert.True(v.Equals(ElectricPotentialDc.FromVoltsDc(1), VoltsDcTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricPotentialDc.Zero, VoltsDcTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.False(voltdc.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.False(voltdc.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricPotentialDcUnit.Undefined, ElectricPotentialDc.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricPotentialDcUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricPotentialDcUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricPotentialTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricPotentialTestsBase.g.cs deleted file mode 100644 index c1572878e3..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricPotentialTestsBase.g.cs +++ /dev/null @@ -1,264 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricPotential. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricPotentialTestsBase - { - protected abstract double KilovoltsInOneVolt { get; } - protected abstract double MegavoltsInOneVolt { get; } - protected abstract double MicrovoltsInOneVolt { get; } - protected abstract double MillivoltsInOneVolt { get; } - protected abstract double VoltsInOneVolt { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilovoltsTolerance { get { return 1e-5; } } - protected virtual double MegavoltsTolerance { get { return 1e-5; } } - protected virtual double MicrovoltsTolerance { get { return 1e-5; } } - protected virtual double MillivoltsTolerance { get { return 1e-5; } } - protected virtual double VoltsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotential((double)0.0, ElectricPotentialUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotential(double.PositiveInfinity, ElectricPotentialUnit.Volt)); - Assert.Throws(() => new ElectricPotential(double.NegativeInfinity, ElectricPotentialUnit.Volt)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotential(double.NaN, ElectricPotentialUnit.Volt)); - } - - [Fact] - public void VoltToElectricPotentialUnits() - { - ElectricPotential volt = ElectricPotential.FromVolts(1); - AssertEx.EqualTolerance(KilovoltsInOneVolt, volt.Kilovolts, KilovoltsTolerance); - AssertEx.EqualTolerance(MegavoltsInOneVolt, volt.Megavolts, MegavoltsTolerance); - AssertEx.EqualTolerance(MicrovoltsInOneVolt, volt.Microvolts, MicrovoltsTolerance); - AssertEx.EqualTolerance(MillivoltsInOneVolt, volt.Millivolts, MillivoltsTolerance); - AssertEx.EqualTolerance(VoltsInOneVolt, volt.Volts, VoltsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricPotential.From(1, ElectricPotentialUnit.Kilovolt).Kilovolts, KilovoltsTolerance); - AssertEx.EqualTolerance(1, ElectricPotential.From(1, ElectricPotentialUnit.Megavolt).Megavolts, MegavoltsTolerance); - AssertEx.EqualTolerance(1, ElectricPotential.From(1, ElectricPotentialUnit.Microvolt).Microvolts, MicrovoltsTolerance); - AssertEx.EqualTolerance(1, ElectricPotential.From(1, ElectricPotentialUnit.Millivolt).Millivolts, MillivoltsTolerance); - AssertEx.EqualTolerance(1, ElectricPotential.From(1, ElectricPotentialUnit.Volt).Volts, VoltsTolerance); - } - - [Fact] - public void FromVolts_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotential.FromVolts(double.PositiveInfinity)); - Assert.Throws(() => ElectricPotential.FromVolts(double.NegativeInfinity)); - } - - [Fact] - public void FromVolts_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotential.FromVolts(double.NaN)); - } - - [Fact] - public void As() - { - var volt = ElectricPotential.FromVolts(1); - AssertEx.EqualTolerance(KilovoltsInOneVolt, volt.As(ElectricPotentialUnit.Kilovolt), KilovoltsTolerance); - AssertEx.EqualTolerance(MegavoltsInOneVolt, volt.As(ElectricPotentialUnit.Megavolt), MegavoltsTolerance); - AssertEx.EqualTolerance(MicrovoltsInOneVolt, volt.As(ElectricPotentialUnit.Microvolt), MicrovoltsTolerance); - AssertEx.EqualTolerance(MillivoltsInOneVolt, volt.As(ElectricPotentialUnit.Millivolt), MillivoltsTolerance); - AssertEx.EqualTolerance(VoltsInOneVolt, volt.As(ElectricPotentialUnit.Volt), VoltsTolerance); - } - - [Fact] - public void ToUnit() - { - var volt = ElectricPotential.FromVolts(1); - - var kilovoltQuantity = volt.ToUnit(ElectricPotentialUnit.Kilovolt); - AssertEx.EqualTolerance(KilovoltsInOneVolt, (double)kilovoltQuantity.Value, KilovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Kilovolt, kilovoltQuantity.Unit); - - var megavoltQuantity = volt.ToUnit(ElectricPotentialUnit.Megavolt); - AssertEx.EqualTolerance(MegavoltsInOneVolt, (double)megavoltQuantity.Value, MegavoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Megavolt, megavoltQuantity.Unit); - - var microvoltQuantity = volt.ToUnit(ElectricPotentialUnit.Microvolt); - AssertEx.EqualTolerance(MicrovoltsInOneVolt, (double)microvoltQuantity.Value, MicrovoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Microvolt, microvoltQuantity.Unit); - - var millivoltQuantity = volt.ToUnit(ElectricPotentialUnit.Millivolt); - AssertEx.EqualTolerance(MillivoltsInOneVolt, (double)millivoltQuantity.Value, MillivoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Millivolt, millivoltQuantity.Unit); - - var voltQuantity = volt.ToUnit(ElectricPotentialUnit.Volt); - AssertEx.EqualTolerance(VoltsInOneVolt, (double)voltQuantity.Value, VoltsTolerance); - Assert.Equal(ElectricPotentialUnit.Volt, voltQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricPotential volt = ElectricPotential.FromVolts(1); - AssertEx.EqualTolerance(1, ElectricPotential.FromKilovolts(volt.Kilovolts).Volts, KilovoltsTolerance); - AssertEx.EqualTolerance(1, ElectricPotential.FromMegavolts(volt.Megavolts).Volts, MegavoltsTolerance); - AssertEx.EqualTolerance(1, ElectricPotential.FromMicrovolts(volt.Microvolts).Volts, MicrovoltsTolerance); - AssertEx.EqualTolerance(1, ElectricPotential.FromMillivolts(volt.Millivolts).Volts, MillivoltsTolerance); - AssertEx.EqualTolerance(1, ElectricPotential.FromVolts(volt.Volts).Volts, VoltsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricPotential v = ElectricPotential.FromVolts(1); - AssertEx.EqualTolerance(-1, -v.Volts, VoltsTolerance); - AssertEx.EqualTolerance(2, (ElectricPotential.FromVolts(3)-v).Volts, VoltsTolerance); - AssertEx.EqualTolerance(2, (v + v).Volts, VoltsTolerance); - AssertEx.EqualTolerance(10, (v*10).Volts, VoltsTolerance); - AssertEx.EqualTolerance(10, (10*v).Volts, VoltsTolerance); - AssertEx.EqualTolerance(2, (ElectricPotential.FromVolts(10)/5).Volts, VoltsTolerance); - AssertEx.EqualTolerance(2, ElectricPotential.FromVolts(10)/ElectricPotential.FromVolts(5), VoltsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricPotential oneVolt = ElectricPotential.FromVolts(1); - ElectricPotential twoVolts = ElectricPotential.FromVolts(2); - - Assert.True(oneVolt < twoVolts); - Assert.True(oneVolt <= twoVolts); - Assert.True(twoVolts > oneVolt); - Assert.True(twoVolts >= oneVolt); - - Assert.False(oneVolt > twoVolts); - Assert.False(oneVolt >= twoVolts); - Assert.False(twoVolts < oneVolt); - Assert.False(twoVolts <= oneVolt); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricPotential volt = ElectricPotential.FromVolts(1); - Assert.Equal(0, volt.CompareTo(volt)); - Assert.True(volt.CompareTo(ElectricPotential.Zero) > 0); - Assert.True(ElectricPotential.Zero.CompareTo(volt) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricPotential volt = ElectricPotential.FromVolts(1); - Assert.Throws(() => volt.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricPotential volt = ElectricPotential.FromVolts(1); - Assert.Throws(() => volt.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricPotential v = ElectricPotential.FromVolts(1); - Assert.True(v.Equals(ElectricPotential.FromVolts(1), VoltsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricPotential.Zero, VoltsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricPotential volt = ElectricPotential.FromVolts(1); - Assert.False(volt.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricPotential volt = ElectricPotential.FromVolts(1); - Assert.False(volt.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricPotentialUnit.Undefined, ElectricPotential.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricPotentialUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricPotentialUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricResistanceTestsBase.g.cs deleted file mode 100644 index 4fc90f533c..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricResistanceTestsBase.g.cs +++ /dev/null @@ -1,254 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricResistance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricResistanceTestsBase - { - protected abstract double KiloohmsInOneOhm { get; } - protected abstract double MegaohmsInOneOhm { get; } - protected abstract double MilliohmsInOneOhm { get; } - protected abstract double OhmsInOneOhm { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KiloohmsTolerance { get { return 1e-5; } } - protected virtual double MegaohmsTolerance { get { return 1e-5; } } - protected virtual double MilliohmsTolerance { get { return 1e-5; } } - protected virtual double OhmsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricResistance((double)0.0, ElectricResistanceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricResistance(double.PositiveInfinity, ElectricResistanceUnit.Ohm)); - Assert.Throws(() => new ElectricResistance(double.NegativeInfinity, ElectricResistanceUnit.Ohm)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricResistance(double.NaN, ElectricResistanceUnit.Ohm)); - } - - [Fact] - public void OhmToElectricResistanceUnits() - { - ElectricResistance ohm = ElectricResistance.FromOhms(1); - AssertEx.EqualTolerance(KiloohmsInOneOhm, ohm.Kiloohms, KiloohmsTolerance); - AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.Megaohms, MegaohmsTolerance); - AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.Milliohms, MilliohmsTolerance); - AssertEx.EqualTolerance(OhmsInOneOhm, ohm.Ohms, OhmsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricResistance.From(1, ElectricResistanceUnit.Kiloohm).Kiloohms, KiloohmsTolerance); - AssertEx.EqualTolerance(1, ElectricResistance.From(1, ElectricResistanceUnit.Megaohm).Megaohms, MegaohmsTolerance); - AssertEx.EqualTolerance(1, ElectricResistance.From(1, ElectricResistanceUnit.Milliohm).Milliohms, MilliohmsTolerance); - AssertEx.EqualTolerance(1, ElectricResistance.From(1, ElectricResistanceUnit.Ohm).Ohms, OhmsTolerance); - } - - [Fact] - public void FromOhms_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricResistance.FromOhms(double.PositiveInfinity)); - Assert.Throws(() => ElectricResistance.FromOhms(double.NegativeInfinity)); - } - - [Fact] - public void FromOhms_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricResistance.FromOhms(double.NaN)); - } - - [Fact] - public void As() - { - var ohm = ElectricResistance.FromOhms(1); - AssertEx.EqualTolerance(KiloohmsInOneOhm, ohm.As(ElectricResistanceUnit.Kiloohm), KiloohmsTolerance); - AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.As(ElectricResistanceUnit.Megaohm), MegaohmsTolerance); - AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.As(ElectricResistanceUnit.Milliohm), MilliohmsTolerance); - AssertEx.EqualTolerance(OhmsInOneOhm, ohm.As(ElectricResistanceUnit.Ohm), OhmsTolerance); - } - - [Fact] - public void ToUnit() - { - var ohm = ElectricResistance.FromOhms(1); - - var kiloohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Kiloohm); - AssertEx.EqualTolerance(KiloohmsInOneOhm, (double)kiloohmQuantity.Value, KiloohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Kiloohm, kiloohmQuantity.Unit); - - var megaohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Megaohm); - AssertEx.EqualTolerance(MegaohmsInOneOhm, (double)megaohmQuantity.Value, MegaohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Megaohm, megaohmQuantity.Unit); - - var milliohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Milliohm); - AssertEx.EqualTolerance(MilliohmsInOneOhm, (double)milliohmQuantity.Value, MilliohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Milliohm, milliohmQuantity.Unit); - - var ohmQuantity = ohm.ToUnit(ElectricResistanceUnit.Ohm); - AssertEx.EqualTolerance(OhmsInOneOhm, (double)ohmQuantity.Value, OhmsTolerance); - Assert.Equal(ElectricResistanceUnit.Ohm, ohmQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricResistance ohm = ElectricResistance.FromOhms(1); - AssertEx.EqualTolerance(1, ElectricResistance.FromKiloohms(ohm.Kiloohms).Ohms, KiloohmsTolerance); - AssertEx.EqualTolerance(1, ElectricResistance.FromMegaohms(ohm.Megaohms).Ohms, MegaohmsTolerance); - AssertEx.EqualTolerance(1, ElectricResistance.FromMilliohms(ohm.Milliohms).Ohms, MilliohmsTolerance); - AssertEx.EqualTolerance(1, ElectricResistance.FromOhms(ohm.Ohms).Ohms, OhmsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricResistance v = ElectricResistance.FromOhms(1); - AssertEx.EqualTolerance(-1, -v.Ohms, OhmsTolerance); - AssertEx.EqualTolerance(2, (ElectricResistance.FromOhms(3)-v).Ohms, OhmsTolerance); - AssertEx.EqualTolerance(2, (v + v).Ohms, OhmsTolerance); - AssertEx.EqualTolerance(10, (v*10).Ohms, OhmsTolerance); - AssertEx.EqualTolerance(10, (10*v).Ohms, OhmsTolerance); - AssertEx.EqualTolerance(2, (ElectricResistance.FromOhms(10)/5).Ohms, OhmsTolerance); - AssertEx.EqualTolerance(2, ElectricResistance.FromOhms(10)/ElectricResistance.FromOhms(5), OhmsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricResistance oneOhm = ElectricResistance.FromOhms(1); - ElectricResistance twoOhms = ElectricResistance.FromOhms(2); - - Assert.True(oneOhm < twoOhms); - Assert.True(oneOhm <= twoOhms); - Assert.True(twoOhms > oneOhm); - Assert.True(twoOhms >= oneOhm); - - Assert.False(oneOhm > twoOhms); - Assert.False(oneOhm >= twoOhms); - Assert.False(twoOhms < oneOhm); - Assert.False(twoOhms <= oneOhm); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricResistance ohm = ElectricResistance.FromOhms(1); - Assert.Equal(0, ohm.CompareTo(ohm)); - Assert.True(ohm.CompareTo(ElectricResistance.Zero) > 0); - Assert.True(ElectricResistance.Zero.CompareTo(ohm) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricResistance ohm = ElectricResistance.FromOhms(1); - Assert.Throws(() => ohm.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricResistance ohm = ElectricResistance.FromOhms(1); - Assert.Throws(() => ohm.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricResistance v = ElectricResistance.FromOhms(1); - Assert.True(v.Equals(ElectricResistance.FromOhms(1), OhmsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricResistance.Zero, OhmsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricResistance ohm = ElectricResistance.FromOhms(1); - Assert.False(ohm.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricResistance ohm = ElectricResistance.FromOhms(1); - Assert.False(ohm.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricResistanceUnit.Undefined, ElectricResistance.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricResistanceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricResistanceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricResistivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricResistivityTestsBase.g.cs deleted file mode 100644 index d04adb92ba..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ElectricResistivityTestsBase.g.cs +++ /dev/null @@ -1,254 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ElectricResistivity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricResistivityTestsBase - { - protected abstract double MicroohmMetersInOneOhmMeter { get; } - protected abstract double MilliohmMetersInOneOhmMeter { get; } - protected abstract double NanoohmMetersInOneOhmMeter { get; } - protected abstract double OhmMetersInOneOhmMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double MicroohmMetersTolerance { get { return 1e-5; } } - protected virtual double MilliohmMetersTolerance { get { return 1e-5; } } - protected virtual double NanoohmMetersTolerance { get { return 1e-5; } } - protected virtual double OhmMetersTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricResistivity((double)0.0, ElectricResistivityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricResistivity(double.PositiveInfinity, ElectricResistivityUnit.OhmMeter)); - Assert.Throws(() => new ElectricResistivity(double.NegativeInfinity, ElectricResistivityUnit.OhmMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricResistivity(double.NaN, ElectricResistivityUnit.OhmMeter)); - } - - [Fact] - public void OhmMeterToElectricResistivityUnits() - { - ElectricResistivity ohmmeter = ElectricResistivity.FromOhmMeters(1); - AssertEx.EqualTolerance(MicroohmMetersInOneOhmMeter, ohmmeter.MicroohmMeters, MicroohmMetersTolerance); - AssertEx.EqualTolerance(MilliohmMetersInOneOhmMeter, ohmmeter.MilliohmMeters, MilliohmMetersTolerance); - AssertEx.EqualTolerance(NanoohmMetersInOneOhmMeter, ohmmeter.NanoohmMeters, NanoohmMetersTolerance); - AssertEx.EqualTolerance(OhmMetersInOneOhmMeter, ohmmeter.OhmMeters, OhmMetersTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ElectricResistivity.From(1, ElectricResistivityUnit.MicroohmMeter).MicroohmMeters, MicroohmMetersTolerance); - AssertEx.EqualTolerance(1, ElectricResistivity.From(1, ElectricResistivityUnit.MilliohmMeter).MilliohmMeters, MilliohmMetersTolerance); - AssertEx.EqualTolerance(1, ElectricResistivity.From(1, ElectricResistivityUnit.NanoohmMeter).NanoohmMeters, NanoohmMetersTolerance); - AssertEx.EqualTolerance(1, ElectricResistivity.From(1, ElectricResistivityUnit.OhmMeter).OhmMeters, OhmMetersTolerance); - } - - [Fact] - public void FromOhmMeters_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricResistivity.FromOhmMeters(double.PositiveInfinity)); - Assert.Throws(() => ElectricResistivity.FromOhmMeters(double.NegativeInfinity)); - } - - [Fact] - public void FromOhmMeters_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricResistivity.FromOhmMeters(double.NaN)); - } - - [Fact] - public void As() - { - var ohmmeter = ElectricResistivity.FromOhmMeters(1); - AssertEx.EqualTolerance(MicroohmMetersInOneOhmMeter, ohmmeter.As(ElectricResistivityUnit.MicroohmMeter), MicroohmMetersTolerance); - AssertEx.EqualTolerance(MilliohmMetersInOneOhmMeter, ohmmeter.As(ElectricResistivityUnit.MilliohmMeter), MilliohmMetersTolerance); - AssertEx.EqualTolerance(NanoohmMetersInOneOhmMeter, ohmmeter.As(ElectricResistivityUnit.NanoohmMeter), NanoohmMetersTolerance); - AssertEx.EqualTolerance(OhmMetersInOneOhmMeter, ohmmeter.As(ElectricResistivityUnit.OhmMeter), OhmMetersTolerance); - } - - [Fact] - public void ToUnit() - { - var ohmmeter = ElectricResistivity.FromOhmMeters(1); - - var microohmmeterQuantity = ohmmeter.ToUnit(ElectricResistivityUnit.MicroohmMeter); - AssertEx.EqualTolerance(MicroohmMetersInOneOhmMeter, (double)microohmmeterQuantity.Value, MicroohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.MicroohmMeter, microohmmeterQuantity.Unit); - - var milliohmmeterQuantity = ohmmeter.ToUnit(ElectricResistivityUnit.MilliohmMeter); - AssertEx.EqualTolerance(MilliohmMetersInOneOhmMeter, (double)milliohmmeterQuantity.Value, MilliohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.MilliohmMeter, milliohmmeterQuantity.Unit); - - var nanoohmmeterQuantity = ohmmeter.ToUnit(ElectricResistivityUnit.NanoohmMeter); - AssertEx.EqualTolerance(NanoohmMetersInOneOhmMeter, (double)nanoohmmeterQuantity.Value, NanoohmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.NanoohmMeter, nanoohmmeterQuantity.Unit); - - var ohmmeterQuantity = ohmmeter.ToUnit(ElectricResistivityUnit.OhmMeter); - AssertEx.EqualTolerance(OhmMetersInOneOhmMeter, (double)ohmmeterQuantity.Value, OhmMetersTolerance); - Assert.Equal(ElectricResistivityUnit.OhmMeter, ohmmeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricResistivity ohmmeter = ElectricResistivity.FromOhmMeters(1); - AssertEx.EqualTolerance(1, ElectricResistivity.FromMicroohmMeters(ohmmeter.MicroohmMeters).OhmMeters, MicroohmMetersTolerance); - AssertEx.EqualTolerance(1, ElectricResistivity.FromMilliohmMeters(ohmmeter.MilliohmMeters).OhmMeters, MilliohmMetersTolerance); - AssertEx.EqualTolerance(1, ElectricResistivity.FromNanoohmMeters(ohmmeter.NanoohmMeters).OhmMeters, NanoohmMetersTolerance); - AssertEx.EqualTolerance(1, ElectricResistivity.FromOhmMeters(ohmmeter.OhmMeters).OhmMeters, OhmMetersTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricResistivity v = ElectricResistivity.FromOhmMeters(1); - AssertEx.EqualTolerance(-1, -v.OhmMeters, OhmMetersTolerance); - AssertEx.EqualTolerance(2, (ElectricResistivity.FromOhmMeters(3)-v).OhmMeters, OhmMetersTolerance); - AssertEx.EqualTolerance(2, (v + v).OhmMeters, OhmMetersTolerance); - AssertEx.EqualTolerance(10, (v*10).OhmMeters, OhmMetersTolerance); - AssertEx.EqualTolerance(10, (10*v).OhmMeters, OhmMetersTolerance); - AssertEx.EqualTolerance(2, (ElectricResistivity.FromOhmMeters(10)/5).OhmMeters, OhmMetersTolerance); - AssertEx.EqualTolerance(2, ElectricResistivity.FromOhmMeters(10)/ElectricResistivity.FromOhmMeters(5), OhmMetersTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricResistivity oneOhmMeter = ElectricResistivity.FromOhmMeters(1); - ElectricResistivity twoOhmMeters = ElectricResistivity.FromOhmMeters(2); - - Assert.True(oneOhmMeter < twoOhmMeters); - Assert.True(oneOhmMeter <= twoOhmMeters); - Assert.True(twoOhmMeters > oneOhmMeter); - Assert.True(twoOhmMeters >= oneOhmMeter); - - Assert.False(oneOhmMeter > twoOhmMeters); - Assert.False(oneOhmMeter >= twoOhmMeters); - Assert.False(twoOhmMeters < oneOhmMeter); - Assert.False(twoOhmMeters <= oneOhmMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricResistivity ohmmeter = ElectricResistivity.FromOhmMeters(1); - Assert.Equal(0, ohmmeter.CompareTo(ohmmeter)); - Assert.True(ohmmeter.CompareTo(ElectricResistivity.Zero) > 0); - Assert.True(ElectricResistivity.Zero.CompareTo(ohmmeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricResistivity ohmmeter = ElectricResistivity.FromOhmMeters(1); - Assert.Throws(() => ohmmeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricResistivity ohmmeter = ElectricResistivity.FromOhmMeters(1); - Assert.Throws(() => ohmmeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ElectricResistivity v = ElectricResistivity.FromOhmMeters(1); - Assert.True(v.Equals(ElectricResistivity.FromOhmMeters(1), OhmMetersTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricResistivity.Zero, OhmMetersTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricResistivity ohmmeter = ElectricResistivity.FromOhmMeters(1); - Assert.False(ohmmeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricResistivity ohmmeter = ElectricResistivity.FromOhmMeters(1); - Assert.False(ohmmeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ElectricResistivityUnit.Undefined, ElectricResistivity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricResistivityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ElectricResistivityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/EnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/EnergyTestsBase.g.cs deleted file mode 100644 index 697884b711..0000000000 --- a/UnitsNet.Tests/GeneratedCode/EnergyTestsBase.g.cs +++ /dev/null @@ -1,434 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Energy. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class EnergyTestsBase - { - protected abstract double BritishThermalUnitsInOneJoule { get; } - protected abstract double CaloriesInOneJoule { get; } - protected abstract double DecathermsEcInOneJoule { get; } - protected abstract double DecathermsImperialInOneJoule { get; } - protected abstract double DecathermsUsInOneJoule { get; } - protected abstract double ElectronVoltsInOneJoule { get; } - protected abstract double ErgsInOneJoule { get; } - protected abstract double FootPoundsInOneJoule { get; } - protected abstract double GigabritishThermalUnitsInOneJoule { get; } - protected abstract double GigawattHoursInOneJoule { get; } - protected abstract double JoulesInOneJoule { get; } - protected abstract double KilobritishThermalUnitsInOneJoule { get; } - protected abstract double KilocaloriesInOneJoule { get; } - protected abstract double KilojoulesInOneJoule { get; } - protected abstract double KilowattHoursInOneJoule { get; } - protected abstract double MegabritishThermalUnitsInOneJoule { get; } - protected abstract double MegajoulesInOneJoule { get; } - protected abstract double MegawattHoursInOneJoule { get; } - protected abstract double ThermsEcInOneJoule { get; } - protected abstract double ThermsImperialInOneJoule { get; } - protected abstract double ThermsUsInOneJoule { get; } - protected abstract double WattHoursInOneJoule { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double BritishThermalUnitsTolerance { get { return 1e-5; } } - protected virtual double CaloriesTolerance { get { return 1e-5; } } - protected virtual double DecathermsEcTolerance { get { return 1e-5; } } - protected virtual double DecathermsImperialTolerance { get { return 1e-5; } } - protected virtual double DecathermsUsTolerance { get { return 1e-5; } } - protected virtual double ElectronVoltsTolerance { get { return 1e-5; } } - protected virtual double ErgsTolerance { get { return 1e-5; } } - protected virtual double FootPoundsTolerance { get { return 1e-5; } } - protected virtual double GigabritishThermalUnitsTolerance { get { return 1e-5; } } - protected virtual double GigawattHoursTolerance { get { return 1e-5; } } - protected virtual double JoulesTolerance { get { return 1e-5; } } - protected virtual double KilobritishThermalUnitsTolerance { get { return 1e-5; } } - protected virtual double KilocaloriesTolerance { get { return 1e-5; } } - protected virtual double KilojoulesTolerance { get { return 1e-5; } } - protected virtual double KilowattHoursTolerance { get { return 1e-5; } } - protected virtual double MegabritishThermalUnitsTolerance { get { return 1e-5; } } - protected virtual double MegajoulesTolerance { get { return 1e-5; } } - protected virtual double MegawattHoursTolerance { get { return 1e-5; } } - protected virtual double ThermsEcTolerance { get { return 1e-5; } } - protected virtual double ThermsImperialTolerance { get { return 1e-5; } } - protected virtual double ThermsUsTolerance { get { return 1e-5; } } - protected virtual double WattHoursTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Energy((double)0.0, EnergyUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Energy(double.PositiveInfinity, EnergyUnit.Joule)); - Assert.Throws(() => new Energy(double.NegativeInfinity, EnergyUnit.Joule)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Energy(double.NaN, EnergyUnit.Joule)); - } - - [Fact] - public void JouleToEnergyUnits() - { - Energy joule = Energy.FromJoules(1); - AssertEx.EqualTolerance(BritishThermalUnitsInOneJoule, joule.BritishThermalUnits, BritishThermalUnitsTolerance); - AssertEx.EqualTolerance(CaloriesInOneJoule, joule.Calories, CaloriesTolerance); - AssertEx.EqualTolerance(DecathermsEcInOneJoule, joule.DecathermsEc, DecathermsEcTolerance); - AssertEx.EqualTolerance(DecathermsImperialInOneJoule, joule.DecathermsImperial, DecathermsImperialTolerance); - AssertEx.EqualTolerance(DecathermsUsInOneJoule, joule.DecathermsUs, DecathermsUsTolerance); - AssertEx.EqualTolerance(ElectronVoltsInOneJoule, joule.ElectronVolts, ElectronVoltsTolerance); - AssertEx.EqualTolerance(ErgsInOneJoule, joule.Ergs, ErgsTolerance); - AssertEx.EqualTolerance(FootPoundsInOneJoule, joule.FootPounds, FootPoundsTolerance); - AssertEx.EqualTolerance(GigabritishThermalUnitsInOneJoule, joule.GigabritishThermalUnits, GigabritishThermalUnitsTolerance); - AssertEx.EqualTolerance(GigawattHoursInOneJoule, joule.GigawattHours, GigawattHoursTolerance); - AssertEx.EqualTolerance(JoulesInOneJoule, joule.Joules, JoulesTolerance); - AssertEx.EqualTolerance(KilobritishThermalUnitsInOneJoule, joule.KilobritishThermalUnits, KilobritishThermalUnitsTolerance); - AssertEx.EqualTolerance(KilocaloriesInOneJoule, joule.Kilocalories, KilocaloriesTolerance); - AssertEx.EqualTolerance(KilojoulesInOneJoule, joule.Kilojoules, KilojoulesTolerance); - AssertEx.EqualTolerance(KilowattHoursInOneJoule, joule.KilowattHours, KilowattHoursTolerance); - AssertEx.EqualTolerance(MegabritishThermalUnitsInOneJoule, joule.MegabritishThermalUnits, MegabritishThermalUnitsTolerance); - AssertEx.EqualTolerance(MegajoulesInOneJoule, joule.Megajoules, MegajoulesTolerance); - AssertEx.EqualTolerance(MegawattHoursInOneJoule, joule.MegawattHours, MegawattHoursTolerance); - AssertEx.EqualTolerance(ThermsEcInOneJoule, joule.ThermsEc, ThermsEcTolerance); - AssertEx.EqualTolerance(ThermsImperialInOneJoule, joule.ThermsImperial, ThermsImperialTolerance); - AssertEx.EqualTolerance(ThermsUsInOneJoule, joule.ThermsUs, ThermsUsTolerance); - AssertEx.EqualTolerance(WattHoursInOneJoule, joule.WattHours, WattHoursTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.BritishThermalUnit).BritishThermalUnits, BritishThermalUnitsTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Calorie).Calories, CaloriesTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.DecathermEc).DecathermsEc, DecathermsEcTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.DecathermImperial).DecathermsImperial, DecathermsImperialTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.DecathermUs).DecathermsUs, DecathermsUsTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ElectronVolt).ElectronVolts, ElectronVoltsTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Erg).Ergs, ErgsTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.FootPound).FootPounds, FootPoundsTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.GigabritishThermalUnit).GigabritishThermalUnits, GigabritishThermalUnitsTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.GigawattHour).GigawattHours, GigawattHoursTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Joule).Joules, JoulesTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.KilobritishThermalUnit).KilobritishThermalUnits, KilobritishThermalUnitsTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Kilocalorie).Kilocalories, KilocaloriesTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Kilojoule).Kilojoules, KilojoulesTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.KilowattHour).KilowattHours, KilowattHoursTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.MegabritishThermalUnit).MegabritishThermalUnits, MegabritishThermalUnitsTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.Megajoule).Megajoules, MegajoulesTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.MegawattHour).MegawattHours, MegawattHoursTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ThermEc).ThermsEc, ThermsEcTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ThermImperial).ThermsImperial, ThermsImperialTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.ThermUs).ThermsUs, ThermsUsTolerance); - AssertEx.EqualTolerance(1, Energy.From(1, EnergyUnit.WattHour).WattHours, WattHoursTolerance); - } - - [Fact] - public void FromJoules_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Energy.FromJoules(double.PositiveInfinity)); - Assert.Throws(() => Energy.FromJoules(double.NegativeInfinity)); - } - - [Fact] - public void FromJoules_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Energy.FromJoules(double.NaN)); - } - - [Fact] - public void As() - { - var joule = Energy.FromJoules(1); - AssertEx.EqualTolerance(BritishThermalUnitsInOneJoule, joule.As(EnergyUnit.BritishThermalUnit), BritishThermalUnitsTolerance); - AssertEx.EqualTolerance(CaloriesInOneJoule, joule.As(EnergyUnit.Calorie), CaloriesTolerance); - AssertEx.EqualTolerance(DecathermsEcInOneJoule, joule.As(EnergyUnit.DecathermEc), DecathermsEcTolerance); - AssertEx.EqualTolerance(DecathermsImperialInOneJoule, joule.As(EnergyUnit.DecathermImperial), DecathermsImperialTolerance); - AssertEx.EqualTolerance(DecathermsUsInOneJoule, joule.As(EnergyUnit.DecathermUs), DecathermsUsTolerance); - AssertEx.EqualTolerance(ElectronVoltsInOneJoule, joule.As(EnergyUnit.ElectronVolt), ElectronVoltsTolerance); - AssertEx.EqualTolerance(ErgsInOneJoule, joule.As(EnergyUnit.Erg), ErgsTolerance); - AssertEx.EqualTolerance(FootPoundsInOneJoule, joule.As(EnergyUnit.FootPound), FootPoundsTolerance); - AssertEx.EqualTolerance(GigabritishThermalUnitsInOneJoule, joule.As(EnergyUnit.GigabritishThermalUnit), GigabritishThermalUnitsTolerance); - AssertEx.EqualTolerance(GigawattHoursInOneJoule, joule.As(EnergyUnit.GigawattHour), GigawattHoursTolerance); - AssertEx.EqualTolerance(JoulesInOneJoule, joule.As(EnergyUnit.Joule), JoulesTolerance); - AssertEx.EqualTolerance(KilobritishThermalUnitsInOneJoule, joule.As(EnergyUnit.KilobritishThermalUnit), KilobritishThermalUnitsTolerance); - AssertEx.EqualTolerance(KilocaloriesInOneJoule, joule.As(EnergyUnit.Kilocalorie), KilocaloriesTolerance); - AssertEx.EqualTolerance(KilojoulesInOneJoule, joule.As(EnergyUnit.Kilojoule), KilojoulesTolerance); - AssertEx.EqualTolerance(KilowattHoursInOneJoule, joule.As(EnergyUnit.KilowattHour), KilowattHoursTolerance); - AssertEx.EqualTolerance(MegabritishThermalUnitsInOneJoule, joule.As(EnergyUnit.MegabritishThermalUnit), MegabritishThermalUnitsTolerance); - AssertEx.EqualTolerance(MegajoulesInOneJoule, joule.As(EnergyUnit.Megajoule), MegajoulesTolerance); - AssertEx.EqualTolerance(MegawattHoursInOneJoule, joule.As(EnergyUnit.MegawattHour), MegawattHoursTolerance); - AssertEx.EqualTolerance(ThermsEcInOneJoule, joule.As(EnergyUnit.ThermEc), ThermsEcTolerance); - AssertEx.EqualTolerance(ThermsImperialInOneJoule, joule.As(EnergyUnit.ThermImperial), ThermsImperialTolerance); - AssertEx.EqualTolerance(ThermsUsInOneJoule, joule.As(EnergyUnit.ThermUs), ThermsUsTolerance); - AssertEx.EqualTolerance(WattHoursInOneJoule, joule.As(EnergyUnit.WattHour), WattHoursTolerance); - } - - [Fact] - public void ToUnit() - { - var joule = Energy.FromJoules(1); - - var britishthermalunitQuantity = joule.ToUnit(EnergyUnit.BritishThermalUnit); - AssertEx.EqualTolerance(BritishThermalUnitsInOneJoule, (double)britishthermalunitQuantity.Value, BritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.BritishThermalUnit, britishthermalunitQuantity.Unit); - - var calorieQuantity = joule.ToUnit(EnergyUnit.Calorie); - AssertEx.EqualTolerance(CaloriesInOneJoule, (double)calorieQuantity.Value, CaloriesTolerance); - Assert.Equal(EnergyUnit.Calorie, calorieQuantity.Unit); - - var decathermecQuantity = joule.ToUnit(EnergyUnit.DecathermEc); - AssertEx.EqualTolerance(DecathermsEcInOneJoule, (double)decathermecQuantity.Value, DecathermsEcTolerance); - Assert.Equal(EnergyUnit.DecathermEc, decathermecQuantity.Unit); - - var decathermimperialQuantity = joule.ToUnit(EnergyUnit.DecathermImperial); - AssertEx.EqualTolerance(DecathermsImperialInOneJoule, (double)decathermimperialQuantity.Value, DecathermsImperialTolerance); - Assert.Equal(EnergyUnit.DecathermImperial, decathermimperialQuantity.Unit); - - var decathermusQuantity = joule.ToUnit(EnergyUnit.DecathermUs); - AssertEx.EqualTolerance(DecathermsUsInOneJoule, (double)decathermusQuantity.Value, DecathermsUsTolerance); - Assert.Equal(EnergyUnit.DecathermUs, decathermusQuantity.Unit); - - var electronvoltQuantity = joule.ToUnit(EnergyUnit.ElectronVolt); - AssertEx.EqualTolerance(ElectronVoltsInOneJoule, (double)electronvoltQuantity.Value, ElectronVoltsTolerance); - Assert.Equal(EnergyUnit.ElectronVolt, electronvoltQuantity.Unit); - - var ergQuantity = joule.ToUnit(EnergyUnit.Erg); - AssertEx.EqualTolerance(ErgsInOneJoule, (double)ergQuantity.Value, ErgsTolerance); - Assert.Equal(EnergyUnit.Erg, ergQuantity.Unit); - - var footpoundQuantity = joule.ToUnit(EnergyUnit.FootPound); - AssertEx.EqualTolerance(FootPoundsInOneJoule, (double)footpoundQuantity.Value, FootPoundsTolerance); - Assert.Equal(EnergyUnit.FootPound, footpoundQuantity.Unit); - - var gigabritishthermalunitQuantity = joule.ToUnit(EnergyUnit.GigabritishThermalUnit); - AssertEx.EqualTolerance(GigabritishThermalUnitsInOneJoule, (double)gigabritishthermalunitQuantity.Value, GigabritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.GigabritishThermalUnit, gigabritishthermalunitQuantity.Unit); - - var gigawatthourQuantity = joule.ToUnit(EnergyUnit.GigawattHour); - AssertEx.EqualTolerance(GigawattHoursInOneJoule, (double)gigawatthourQuantity.Value, GigawattHoursTolerance); - Assert.Equal(EnergyUnit.GigawattHour, gigawatthourQuantity.Unit); - - var jouleQuantity = joule.ToUnit(EnergyUnit.Joule); - AssertEx.EqualTolerance(JoulesInOneJoule, (double)jouleQuantity.Value, JoulesTolerance); - Assert.Equal(EnergyUnit.Joule, jouleQuantity.Unit); - - var kilobritishthermalunitQuantity = joule.ToUnit(EnergyUnit.KilobritishThermalUnit); - AssertEx.EqualTolerance(KilobritishThermalUnitsInOneJoule, (double)kilobritishthermalunitQuantity.Value, KilobritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.KilobritishThermalUnit, kilobritishthermalunitQuantity.Unit); - - var kilocalorieQuantity = joule.ToUnit(EnergyUnit.Kilocalorie); - AssertEx.EqualTolerance(KilocaloriesInOneJoule, (double)kilocalorieQuantity.Value, KilocaloriesTolerance); - Assert.Equal(EnergyUnit.Kilocalorie, kilocalorieQuantity.Unit); - - var kilojouleQuantity = joule.ToUnit(EnergyUnit.Kilojoule); - AssertEx.EqualTolerance(KilojoulesInOneJoule, (double)kilojouleQuantity.Value, KilojoulesTolerance); - Assert.Equal(EnergyUnit.Kilojoule, kilojouleQuantity.Unit); - - var kilowatthourQuantity = joule.ToUnit(EnergyUnit.KilowattHour); - AssertEx.EqualTolerance(KilowattHoursInOneJoule, (double)kilowatthourQuantity.Value, KilowattHoursTolerance); - Assert.Equal(EnergyUnit.KilowattHour, kilowatthourQuantity.Unit); - - var megabritishthermalunitQuantity = joule.ToUnit(EnergyUnit.MegabritishThermalUnit); - AssertEx.EqualTolerance(MegabritishThermalUnitsInOneJoule, (double)megabritishthermalunitQuantity.Value, MegabritishThermalUnitsTolerance); - Assert.Equal(EnergyUnit.MegabritishThermalUnit, megabritishthermalunitQuantity.Unit); - - var megajouleQuantity = joule.ToUnit(EnergyUnit.Megajoule); - AssertEx.EqualTolerance(MegajoulesInOneJoule, (double)megajouleQuantity.Value, MegajoulesTolerance); - Assert.Equal(EnergyUnit.Megajoule, megajouleQuantity.Unit); - - var megawatthourQuantity = joule.ToUnit(EnergyUnit.MegawattHour); - AssertEx.EqualTolerance(MegawattHoursInOneJoule, (double)megawatthourQuantity.Value, MegawattHoursTolerance); - Assert.Equal(EnergyUnit.MegawattHour, megawatthourQuantity.Unit); - - var thermecQuantity = joule.ToUnit(EnergyUnit.ThermEc); - AssertEx.EqualTolerance(ThermsEcInOneJoule, (double)thermecQuantity.Value, ThermsEcTolerance); - Assert.Equal(EnergyUnit.ThermEc, thermecQuantity.Unit); - - var thermimperialQuantity = joule.ToUnit(EnergyUnit.ThermImperial); - AssertEx.EqualTolerance(ThermsImperialInOneJoule, (double)thermimperialQuantity.Value, ThermsImperialTolerance); - Assert.Equal(EnergyUnit.ThermImperial, thermimperialQuantity.Unit); - - var thermusQuantity = joule.ToUnit(EnergyUnit.ThermUs); - AssertEx.EqualTolerance(ThermsUsInOneJoule, (double)thermusQuantity.Value, ThermsUsTolerance); - Assert.Equal(EnergyUnit.ThermUs, thermusQuantity.Unit); - - var watthourQuantity = joule.ToUnit(EnergyUnit.WattHour); - AssertEx.EqualTolerance(WattHoursInOneJoule, (double)watthourQuantity.Value, WattHoursTolerance); - Assert.Equal(EnergyUnit.WattHour, watthourQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Energy joule = Energy.FromJoules(1); - AssertEx.EqualTolerance(1, Energy.FromBritishThermalUnits(joule.BritishThermalUnits).Joules, BritishThermalUnitsTolerance); - AssertEx.EqualTolerance(1, Energy.FromCalories(joule.Calories).Joules, CaloriesTolerance); - AssertEx.EqualTolerance(1, Energy.FromDecathermsEc(joule.DecathermsEc).Joules, DecathermsEcTolerance); - AssertEx.EqualTolerance(1, Energy.FromDecathermsImperial(joule.DecathermsImperial).Joules, DecathermsImperialTolerance); - AssertEx.EqualTolerance(1, Energy.FromDecathermsUs(joule.DecathermsUs).Joules, DecathermsUsTolerance); - AssertEx.EqualTolerance(1, Energy.FromElectronVolts(joule.ElectronVolts).Joules, ElectronVoltsTolerance); - AssertEx.EqualTolerance(1, Energy.FromErgs(joule.Ergs).Joules, ErgsTolerance); - AssertEx.EqualTolerance(1, Energy.FromFootPounds(joule.FootPounds).Joules, FootPoundsTolerance); - AssertEx.EqualTolerance(1, Energy.FromGigabritishThermalUnits(joule.GigabritishThermalUnits).Joules, GigabritishThermalUnitsTolerance); - AssertEx.EqualTolerance(1, Energy.FromGigawattHours(joule.GigawattHours).Joules, GigawattHoursTolerance); - AssertEx.EqualTolerance(1, Energy.FromJoules(joule.Joules).Joules, JoulesTolerance); - AssertEx.EqualTolerance(1, Energy.FromKilobritishThermalUnits(joule.KilobritishThermalUnits).Joules, KilobritishThermalUnitsTolerance); - AssertEx.EqualTolerance(1, Energy.FromKilocalories(joule.Kilocalories).Joules, KilocaloriesTolerance); - AssertEx.EqualTolerance(1, Energy.FromKilojoules(joule.Kilojoules).Joules, KilojoulesTolerance); - AssertEx.EqualTolerance(1, Energy.FromKilowattHours(joule.KilowattHours).Joules, KilowattHoursTolerance); - AssertEx.EqualTolerance(1, Energy.FromMegabritishThermalUnits(joule.MegabritishThermalUnits).Joules, MegabritishThermalUnitsTolerance); - AssertEx.EqualTolerance(1, Energy.FromMegajoules(joule.Megajoules).Joules, MegajoulesTolerance); - AssertEx.EqualTolerance(1, Energy.FromMegawattHours(joule.MegawattHours).Joules, MegawattHoursTolerance); - AssertEx.EqualTolerance(1, Energy.FromThermsEc(joule.ThermsEc).Joules, ThermsEcTolerance); - AssertEx.EqualTolerance(1, Energy.FromThermsImperial(joule.ThermsImperial).Joules, ThermsImperialTolerance); - AssertEx.EqualTolerance(1, Energy.FromThermsUs(joule.ThermsUs).Joules, ThermsUsTolerance); - AssertEx.EqualTolerance(1, Energy.FromWattHours(joule.WattHours).Joules, WattHoursTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Energy v = Energy.FromJoules(1); - AssertEx.EqualTolerance(-1, -v.Joules, JoulesTolerance); - AssertEx.EqualTolerance(2, (Energy.FromJoules(3)-v).Joules, JoulesTolerance); - AssertEx.EqualTolerance(2, (v + v).Joules, JoulesTolerance); - AssertEx.EqualTolerance(10, (v*10).Joules, JoulesTolerance); - AssertEx.EqualTolerance(10, (10*v).Joules, JoulesTolerance); - AssertEx.EqualTolerance(2, (Energy.FromJoules(10)/5).Joules, JoulesTolerance); - AssertEx.EqualTolerance(2, Energy.FromJoules(10)/Energy.FromJoules(5), JoulesTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Energy oneJoule = Energy.FromJoules(1); - Energy twoJoules = Energy.FromJoules(2); - - Assert.True(oneJoule < twoJoules); - Assert.True(oneJoule <= twoJoules); - Assert.True(twoJoules > oneJoule); - Assert.True(twoJoules >= oneJoule); - - Assert.False(oneJoule > twoJoules); - Assert.False(oneJoule >= twoJoules); - Assert.False(twoJoules < oneJoule); - Assert.False(twoJoules <= oneJoule); - } - - [Fact] - public void CompareToIsImplemented() - { - Energy joule = Energy.FromJoules(1); - Assert.Equal(0, joule.CompareTo(joule)); - Assert.True(joule.CompareTo(Energy.Zero) > 0); - Assert.True(Energy.Zero.CompareTo(joule) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Energy joule = Energy.FromJoules(1); - Assert.Throws(() => joule.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Energy joule = Energy.FromJoules(1); - Assert.Throws(() => joule.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Energy v = Energy.FromJoules(1); - Assert.True(v.Equals(Energy.FromJoules(1), JoulesTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Energy.Zero, JoulesTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Energy joule = Energy.FromJoules(1); - Assert.False(joule.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Energy joule = Energy.FromJoules(1); - Assert.False(joule.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(EnergyUnit.Undefined, Energy.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(EnergyUnit)).Cast(); - foreach(var unit in units) - { - if(unit == EnergyUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/EntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/EntropyTestsBase.g.cs deleted file mode 100644 index 98cd982765..0000000000 --- a/UnitsNet.Tests/GeneratedCode/EntropyTestsBase.g.cs +++ /dev/null @@ -1,284 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Entropy. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class EntropyTestsBase - { - protected abstract double CaloriesPerKelvinInOneJoulePerKelvin { get; } - protected abstract double JoulesPerDegreeCelsiusInOneJoulePerKelvin { get; } - protected abstract double JoulesPerKelvinInOneJoulePerKelvin { get; } - protected abstract double KilocaloriesPerKelvinInOneJoulePerKelvin { get; } - protected abstract double KilojoulesPerDegreeCelsiusInOneJoulePerKelvin { get; } - protected abstract double KilojoulesPerKelvinInOneJoulePerKelvin { get; } - protected abstract double MegajoulesPerKelvinInOneJoulePerKelvin { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CaloriesPerKelvinTolerance { get { return 1e-5; } } - protected virtual double JoulesPerDegreeCelsiusTolerance { get { return 1e-5; } } - protected virtual double JoulesPerKelvinTolerance { get { return 1e-5; } } - protected virtual double KilocaloriesPerKelvinTolerance { get { return 1e-5; } } - protected virtual double KilojoulesPerDegreeCelsiusTolerance { get { return 1e-5; } } - protected virtual double KilojoulesPerKelvinTolerance { get { return 1e-5; } } - protected virtual double MegajoulesPerKelvinTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Entropy((double)0.0, EntropyUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Entropy(double.PositiveInfinity, EntropyUnit.JoulePerKelvin)); - Assert.Throws(() => new Entropy(double.NegativeInfinity, EntropyUnit.JoulePerKelvin)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Entropy(double.NaN, EntropyUnit.JoulePerKelvin)); - } - - [Fact] - public void JoulePerKelvinToEntropyUnits() - { - Entropy jouleperkelvin = Entropy.FromJoulesPerKelvin(1); - AssertEx.EqualTolerance(CaloriesPerKelvinInOneJoulePerKelvin, jouleperkelvin.CaloriesPerKelvin, CaloriesPerKelvinTolerance); - AssertEx.EqualTolerance(JoulesPerDegreeCelsiusInOneJoulePerKelvin, jouleperkelvin.JoulesPerDegreeCelsius, JoulesPerDegreeCelsiusTolerance); - AssertEx.EqualTolerance(JoulesPerKelvinInOneJoulePerKelvin, jouleperkelvin.JoulesPerKelvin, JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(KilocaloriesPerKelvinInOneJoulePerKelvin, jouleperkelvin.KilocaloriesPerKelvin, KilocaloriesPerKelvinTolerance); - AssertEx.EqualTolerance(KilojoulesPerDegreeCelsiusInOneJoulePerKelvin, jouleperkelvin.KilojoulesPerDegreeCelsius, KilojoulesPerDegreeCelsiusTolerance); - AssertEx.EqualTolerance(KilojoulesPerKelvinInOneJoulePerKelvin, jouleperkelvin.KilojoulesPerKelvin, KilojoulesPerKelvinTolerance); - AssertEx.EqualTolerance(MegajoulesPerKelvinInOneJoulePerKelvin, jouleperkelvin.MegajoulesPerKelvin, MegajoulesPerKelvinTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Entropy.From(1, EntropyUnit.CaloriePerKelvin).CaloriesPerKelvin, CaloriesPerKelvinTolerance); - AssertEx.EqualTolerance(1, Entropy.From(1, EntropyUnit.JoulePerDegreeCelsius).JoulesPerDegreeCelsius, JoulesPerDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, Entropy.From(1, EntropyUnit.JoulePerKelvin).JoulesPerKelvin, JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(1, Entropy.From(1, EntropyUnit.KilocaloriePerKelvin).KilocaloriesPerKelvin, KilocaloriesPerKelvinTolerance); - AssertEx.EqualTolerance(1, Entropy.From(1, EntropyUnit.KilojoulePerDegreeCelsius).KilojoulesPerDegreeCelsius, KilojoulesPerDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, Entropy.From(1, EntropyUnit.KilojoulePerKelvin).KilojoulesPerKelvin, KilojoulesPerKelvinTolerance); - AssertEx.EqualTolerance(1, Entropy.From(1, EntropyUnit.MegajoulePerKelvin).MegajoulesPerKelvin, MegajoulesPerKelvinTolerance); - } - - [Fact] - public void FromJoulesPerKelvin_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Entropy.FromJoulesPerKelvin(double.PositiveInfinity)); - Assert.Throws(() => Entropy.FromJoulesPerKelvin(double.NegativeInfinity)); - } - - [Fact] - public void FromJoulesPerKelvin_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Entropy.FromJoulesPerKelvin(double.NaN)); - } - - [Fact] - public void As() - { - var jouleperkelvin = Entropy.FromJoulesPerKelvin(1); - AssertEx.EqualTolerance(CaloriesPerKelvinInOneJoulePerKelvin, jouleperkelvin.As(EntropyUnit.CaloriePerKelvin), CaloriesPerKelvinTolerance); - AssertEx.EqualTolerance(JoulesPerDegreeCelsiusInOneJoulePerKelvin, jouleperkelvin.As(EntropyUnit.JoulePerDegreeCelsius), JoulesPerDegreeCelsiusTolerance); - AssertEx.EqualTolerance(JoulesPerKelvinInOneJoulePerKelvin, jouleperkelvin.As(EntropyUnit.JoulePerKelvin), JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(KilocaloriesPerKelvinInOneJoulePerKelvin, jouleperkelvin.As(EntropyUnit.KilocaloriePerKelvin), KilocaloriesPerKelvinTolerance); - AssertEx.EqualTolerance(KilojoulesPerDegreeCelsiusInOneJoulePerKelvin, jouleperkelvin.As(EntropyUnit.KilojoulePerDegreeCelsius), KilojoulesPerDegreeCelsiusTolerance); - AssertEx.EqualTolerance(KilojoulesPerKelvinInOneJoulePerKelvin, jouleperkelvin.As(EntropyUnit.KilojoulePerKelvin), KilojoulesPerKelvinTolerance); - AssertEx.EqualTolerance(MegajoulesPerKelvinInOneJoulePerKelvin, jouleperkelvin.As(EntropyUnit.MegajoulePerKelvin), MegajoulesPerKelvinTolerance); - } - - [Fact] - public void ToUnit() - { - var jouleperkelvin = Entropy.FromJoulesPerKelvin(1); - - var calorieperkelvinQuantity = jouleperkelvin.ToUnit(EntropyUnit.CaloriePerKelvin); - AssertEx.EqualTolerance(CaloriesPerKelvinInOneJoulePerKelvin, (double)calorieperkelvinQuantity.Value, CaloriesPerKelvinTolerance); - Assert.Equal(EntropyUnit.CaloriePerKelvin, calorieperkelvinQuantity.Unit); - - var jouleperdegreecelsiusQuantity = jouleperkelvin.ToUnit(EntropyUnit.JoulePerDegreeCelsius); - AssertEx.EqualTolerance(JoulesPerDegreeCelsiusInOneJoulePerKelvin, (double)jouleperdegreecelsiusQuantity.Value, JoulesPerDegreeCelsiusTolerance); - Assert.Equal(EntropyUnit.JoulePerDegreeCelsius, jouleperdegreecelsiusQuantity.Unit); - - var jouleperkelvinQuantity = jouleperkelvin.ToUnit(EntropyUnit.JoulePerKelvin); - AssertEx.EqualTolerance(JoulesPerKelvinInOneJoulePerKelvin, (double)jouleperkelvinQuantity.Value, JoulesPerKelvinTolerance); - Assert.Equal(EntropyUnit.JoulePerKelvin, jouleperkelvinQuantity.Unit); - - var kilocalorieperkelvinQuantity = jouleperkelvin.ToUnit(EntropyUnit.KilocaloriePerKelvin); - AssertEx.EqualTolerance(KilocaloriesPerKelvinInOneJoulePerKelvin, (double)kilocalorieperkelvinQuantity.Value, KilocaloriesPerKelvinTolerance); - Assert.Equal(EntropyUnit.KilocaloriePerKelvin, kilocalorieperkelvinQuantity.Unit); - - var kilojouleperdegreecelsiusQuantity = jouleperkelvin.ToUnit(EntropyUnit.KilojoulePerDegreeCelsius); - AssertEx.EqualTolerance(KilojoulesPerDegreeCelsiusInOneJoulePerKelvin, (double)kilojouleperdegreecelsiusQuantity.Value, KilojoulesPerDegreeCelsiusTolerance); - Assert.Equal(EntropyUnit.KilojoulePerDegreeCelsius, kilojouleperdegreecelsiusQuantity.Unit); - - var kilojouleperkelvinQuantity = jouleperkelvin.ToUnit(EntropyUnit.KilojoulePerKelvin); - AssertEx.EqualTolerance(KilojoulesPerKelvinInOneJoulePerKelvin, (double)kilojouleperkelvinQuantity.Value, KilojoulesPerKelvinTolerance); - Assert.Equal(EntropyUnit.KilojoulePerKelvin, kilojouleperkelvinQuantity.Unit); - - var megajouleperkelvinQuantity = jouleperkelvin.ToUnit(EntropyUnit.MegajoulePerKelvin); - AssertEx.EqualTolerance(MegajoulesPerKelvinInOneJoulePerKelvin, (double)megajouleperkelvinQuantity.Value, MegajoulesPerKelvinTolerance); - Assert.Equal(EntropyUnit.MegajoulePerKelvin, megajouleperkelvinQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Entropy jouleperkelvin = Entropy.FromJoulesPerKelvin(1); - AssertEx.EqualTolerance(1, Entropy.FromCaloriesPerKelvin(jouleperkelvin.CaloriesPerKelvin).JoulesPerKelvin, CaloriesPerKelvinTolerance); - AssertEx.EqualTolerance(1, Entropy.FromJoulesPerDegreeCelsius(jouleperkelvin.JoulesPerDegreeCelsius).JoulesPerKelvin, JoulesPerDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, Entropy.FromJoulesPerKelvin(jouleperkelvin.JoulesPerKelvin).JoulesPerKelvin, JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(1, Entropy.FromKilocaloriesPerKelvin(jouleperkelvin.KilocaloriesPerKelvin).JoulesPerKelvin, KilocaloriesPerKelvinTolerance); - AssertEx.EqualTolerance(1, Entropy.FromKilojoulesPerDegreeCelsius(jouleperkelvin.KilojoulesPerDegreeCelsius).JoulesPerKelvin, KilojoulesPerDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, Entropy.FromKilojoulesPerKelvin(jouleperkelvin.KilojoulesPerKelvin).JoulesPerKelvin, KilojoulesPerKelvinTolerance); - AssertEx.EqualTolerance(1, Entropy.FromMegajoulesPerKelvin(jouleperkelvin.MegajoulesPerKelvin).JoulesPerKelvin, MegajoulesPerKelvinTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Entropy v = Entropy.FromJoulesPerKelvin(1); - AssertEx.EqualTolerance(-1, -v.JoulesPerKelvin, JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(2, (Entropy.FromJoulesPerKelvin(3)-v).JoulesPerKelvin, JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(2, (v + v).JoulesPerKelvin, JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(10, (v*10).JoulesPerKelvin, JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(10, (10*v).JoulesPerKelvin, JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(2, (Entropy.FromJoulesPerKelvin(10)/5).JoulesPerKelvin, JoulesPerKelvinTolerance); - AssertEx.EqualTolerance(2, Entropy.FromJoulesPerKelvin(10)/Entropy.FromJoulesPerKelvin(5), JoulesPerKelvinTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Entropy oneJoulePerKelvin = Entropy.FromJoulesPerKelvin(1); - Entropy twoJoulesPerKelvin = Entropy.FromJoulesPerKelvin(2); - - Assert.True(oneJoulePerKelvin < twoJoulesPerKelvin); - Assert.True(oneJoulePerKelvin <= twoJoulesPerKelvin); - Assert.True(twoJoulesPerKelvin > oneJoulePerKelvin); - Assert.True(twoJoulesPerKelvin >= oneJoulePerKelvin); - - Assert.False(oneJoulePerKelvin > twoJoulesPerKelvin); - Assert.False(oneJoulePerKelvin >= twoJoulesPerKelvin); - Assert.False(twoJoulesPerKelvin < oneJoulePerKelvin); - Assert.False(twoJoulesPerKelvin <= oneJoulePerKelvin); - } - - [Fact] - public void CompareToIsImplemented() - { - Entropy jouleperkelvin = Entropy.FromJoulesPerKelvin(1); - Assert.Equal(0, jouleperkelvin.CompareTo(jouleperkelvin)); - Assert.True(jouleperkelvin.CompareTo(Entropy.Zero) > 0); - Assert.True(Entropy.Zero.CompareTo(jouleperkelvin) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Entropy jouleperkelvin = Entropy.FromJoulesPerKelvin(1); - Assert.Throws(() => jouleperkelvin.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Entropy jouleperkelvin = Entropy.FromJoulesPerKelvin(1); - Assert.Throws(() => jouleperkelvin.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Entropy v = Entropy.FromJoulesPerKelvin(1); - Assert.True(v.Equals(Entropy.FromJoulesPerKelvin(1), JoulesPerKelvinTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Entropy.Zero, JoulesPerKelvinTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Entropy jouleperkelvin = Entropy.FromJoulesPerKelvin(1); - Assert.False(jouleperkelvin.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Entropy jouleperkelvin = Entropy.FromJoulesPerKelvin(1); - Assert.False(jouleperkelvin.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(EntropyUnit.Undefined, Entropy.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(EntropyUnit)).Cast(); - foreach(var unit in units) - { - if(unit == EntropyUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ForceChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ForceChangeRateTestsBase.g.cs deleted file mode 100644 index 3aa6fd1817..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ForceChangeRateTestsBase.g.cs +++ /dev/null @@ -1,324 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ForceChangeRate. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ForceChangeRateTestsBase - { - protected abstract double CentinewtonsPerSecondInOneNewtonPerSecond { get; } - protected abstract double DecanewtonsPerMinuteInOneNewtonPerSecond { get; } - protected abstract double DecanewtonsPerSecondInOneNewtonPerSecond { get; } - protected abstract double DecinewtonsPerSecondInOneNewtonPerSecond { get; } - protected abstract double KilonewtonsPerMinuteInOneNewtonPerSecond { get; } - protected abstract double KilonewtonsPerSecondInOneNewtonPerSecond { get; } - protected abstract double MicronewtonsPerSecondInOneNewtonPerSecond { get; } - protected abstract double MillinewtonsPerSecondInOneNewtonPerSecond { get; } - protected abstract double NanonewtonsPerSecondInOneNewtonPerSecond { get; } - protected abstract double NewtonsPerMinuteInOneNewtonPerSecond { get; } - protected abstract double NewtonsPerSecondInOneNewtonPerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentinewtonsPerSecondTolerance { get { return 1e-5; } } - protected virtual double DecanewtonsPerMinuteTolerance { get { return 1e-5; } } - protected virtual double DecanewtonsPerSecondTolerance { get { return 1e-5; } } - protected virtual double DecinewtonsPerSecondTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsPerMinuteTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsPerSecondTolerance { get { return 1e-5; } } - protected virtual double MicronewtonsPerSecondTolerance { get { return 1e-5; } } - protected virtual double MillinewtonsPerSecondTolerance { get { return 1e-5; } } - protected virtual double NanonewtonsPerSecondTolerance { get { return 1e-5; } } - protected virtual double NewtonsPerMinuteTolerance { get { return 1e-5; } } - protected virtual double NewtonsPerSecondTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ForceChangeRate((double)0.0, ForceChangeRateUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ForceChangeRate(double.PositiveInfinity, ForceChangeRateUnit.NewtonPerSecond)); - Assert.Throws(() => new ForceChangeRate(double.NegativeInfinity, ForceChangeRateUnit.NewtonPerSecond)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ForceChangeRate(double.NaN, ForceChangeRateUnit.NewtonPerSecond)); - } - - [Fact] - public void NewtonPerSecondToForceChangeRateUnits() - { - ForceChangeRate newtonpersecond = ForceChangeRate.FromNewtonsPerSecond(1); - AssertEx.EqualTolerance(CentinewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.CentinewtonsPerSecond, CentinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(DecanewtonsPerMinuteInOneNewtonPerSecond, newtonpersecond.DecanewtonsPerMinute, DecanewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(DecanewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.DecanewtonsPerSecond, DecanewtonsPerSecondTolerance); - AssertEx.EqualTolerance(DecinewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.DecinewtonsPerSecond, DecinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(KilonewtonsPerMinuteInOneNewtonPerSecond, newtonpersecond.KilonewtonsPerMinute, KilonewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(KilonewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.KilonewtonsPerSecond, KilonewtonsPerSecondTolerance); - AssertEx.EqualTolerance(MicronewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.MicronewtonsPerSecond, MicronewtonsPerSecondTolerance); - AssertEx.EqualTolerance(MillinewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.MillinewtonsPerSecond, MillinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(NanonewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.NanonewtonsPerSecond, NanonewtonsPerSecondTolerance); - AssertEx.EqualTolerance(NewtonsPerMinuteInOneNewtonPerSecond, newtonpersecond.NewtonsPerMinute, NewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(NewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.NewtonsPerSecond, NewtonsPerSecondTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.CentinewtonPerSecond).CentinewtonsPerSecond, CentinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.DecanewtonPerMinute).DecanewtonsPerMinute, DecanewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.DecanewtonPerSecond).DecanewtonsPerSecond, DecanewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.DecinewtonPerSecond).DecinewtonsPerSecond, DecinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.KilonewtonPerMinute).KilonewtonsPerMinute, KilonewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.KilonewtonPerSecond).KilonewtonsPerSecond, KilonewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.MicronewtonPerSecond).MicronewtonsPerSecond, MicronewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.MillinewtonPerSecond).MillinewtonsPerSecond, MillinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.NanonewtonPerSecond).NanonewtonsPerSecond, NanonewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.NewtonPerMinute).NewtonsPerMinute, NewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.From(1, ForceChangeRateUnit.NewtonPerSecond).NewtonsPerSecond, NewtonsPerSecondTolerance); - } - - [Fact] - public void FromNewtonsPerSecond_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ForceChangeRate.FromNewtonsPerSecond(double.PositiveInfinity)); - Assert.Throws(() => ForceChangeRate.FromNewtonsPerSecond(double.NegativeInfinity)); - } - - [Fact] - public void FromNewtonsPerSecond_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ForceChangeRate.FromNewtonsPerSecond(double.NaN)); - } - - [Fact] - public void As() - { - var newtonpersecond = ForceChangeRate.FromNewtonsPerSecond(1); - AssertEx.EqualTolerance(CentinewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.CentinewtonPerSecond), CentinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(DecanewtonsPerMinuteInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.DecanewtonPerMinute), DecanewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(DecanewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.DecanewtonPerSecond), DecanewtonsPerSecondTolerance); - AssertEx.EqualTolerance(DecinewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.DecinewtonPerSecond), DecinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(KilonewtonsPerMinuteInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.KilonewtonPerMinute), KilonewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(KilonewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.KilonewtonPerSecond), KilonewtonsPerSecondTolerance); - AssertEx.EqualTolerance(MicronewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.MicronewtonPerSecond), MicronewtonsPerSecondTolerance); - AssertEx.EqualTolerance(MillinewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.MillinewtonPerSecond), MillinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(NanonewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.NanonewtonPerSecond), NanonewtonsPerSecondTolerance); - AssertEx.EqualTolerance(NewtonsPerMinuteInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.NewtonPerMinute), NewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(NewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.NewtonPerSecond), NewtonsPerSecondTolerance); - } - - [Fact] - public void ToUnit() - { - var newtonpersecond = ForceChangeRate.FromNewtonsPerSecond(1); - - var centinewtonpersecondQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.CentinewtonPerSecond); - AssertEx.EqualTolerance(CentinewtonsPerSecondInOneNewtonPerSecond, (double)centinewtonpersecondQuantity.Value, CentinewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.CentinewtonPerSecond, centinewtonpersecondQuantity.Unit); - - var decanewtonperminuteQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.DecanewtonPerMinute); - AssertEx.EqualTolerance(DecanewtonsPerMinuteInOneNewtonPerSecond, (double)decanewtonperminuteQuantity.Value, DecanewtonsPerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerMinute, decanewtonperminuteQuantity.Unit); - - var decanewtonpersecondQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.DecanewtonPerSecond); - AssertEx.EqualTolerance(DecanewtonsPerSecondInOneNewtonPerSecond, (double)decanewtonpersecondQuantity.Value, DecanewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerSecond, decanewtonpersecondQuantity.Unit); - - var decinewtonpersecondQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.DecinewtonPerSecond); - AssertEx.EqualTolerance(DecinewtonsPerSecondInOneNewtonPerSecond, (double)decinewtonpersecondQuantity.Value, DecinewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.DecinewtonPerSecond, decinewtonpersecondQuantity.Unit); - - var kilonewtonperminuteQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.KilonewtonPerMinute); - AssertEx.EqualTolerance(KilonewtonsPerMinuteInOneNewtonPerSecond, (double)kilonewtonperminuteQuantity.Value, KilonewtonsPerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerMinute, kilonewtonperminuteQuantity.Unit); - - var kilonewtonpersecondQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.KilonewtonPerSecond); - AssertEx.EqualTolerance(KilonewtonsPerSecondInOneNewtonPerSecond, (double)kilonewtonpersecondQuantity.Value, KilonewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerSecond, kilonewtonpersecondQuantity.Unit); - - var micronewtonpersecondQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.MicronewtonPerSecond); - AssertEx.EqualTolerance(MicronewtonsPerSecondInOneNewtonPerSecond, (double)micronewtonpersecondQuantity.Value, MicronewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.MicronewtonPerSecond, micronewtonpersecondQuantity.Unit); - - var millinewtonpersecondQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.MillinewtonPerSecond); - AssertEx.EqualTolerance(MillinewtonsPerSecondInOneNewtonPerSecond, (double)millinewtonpersecondQuantity.Value, MillinewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.MillinewtonPerSecond, millinewtonpersecondQuantity.Unit); - - var nanonewtonpersecondQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.NanonewtonPerSecond); - AssertEx.EqualTolerance(NanonewtonsPerSecondInOneNewtonPerSecond, (double)nanonewtonpersecondQuantity.Value, NanonewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.NanonewtonPerSecond, nanonewtonpersecondQuantity.Unit); - - var newtonperminuteQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.NewtonPerMinute); - AssertEx.EqualTolerance(NewtonsPerMinuteInOneNewtonPerSecond, (double)newtonperminuteQuantity.Value, NewtonsPerMinuteTolerance); - Assert.Equal(ForceChangeRateUnit.NewtonPerMinute, newtonperminuteQuantity.Unit); - - var newtonpersecondQuantity = newtonpersecond.ToUnit(ForceChangeRateUnit.NewtonPerSecond); - AssertEx.EqualTolerance(NewtonsPerSecondInOneNewtonPerSecond, (double)newtonpersecondQuantity.Value, NewtonsPerSecondTolerance); - Assert.Equal(ForceChangeRateUnit.NewtonPerSecond, newtonpersecondQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ForceChangeRate newtonpersecond = ForceChangeRate.FromNewtonsPerSecond(1); - AssertEx.EqualTolerance(1, ForceChangeRate.FromCentinewtonsPerSecond(newtonpersecond.CentinewtonsPerSecond).NewtonsPerSecond, CentinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromDecanewtonsPerMinute(newtonpersecond.DecanewtonsPerMinute).NewtonsPerSecond, DecanewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromDecanewtonsPerSecond(newtonpersecond.DecanewtonsPerSecond).NewtonsPerSecond, DecanewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromDecinewtonsPerSecond(newtonpersecond.DecinewtonsPerSecond).NewtonsPerSecond, DecinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromKilonewtonsPerMinute(newtonpersecond.KilonewtonsPerMinute).NewtonsPerSecond, KilonewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromKilonewtonsPerSecond(newtonpersecond.KilonewtonsPerSecond).NewtonsPerSecond, KilonewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromMicronewtonsPerSecond(newtonpersecond.MicronewtonsPerSecond).NewtonsPerSecond, MicronewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromMillinewtonsPerSecond(newtonpersecond.MillinewtonsPerSecond).NewtonsPerSecond, MillinewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromNanonewtonsPerSecond(newtonpersecond.NanonewtonsPerSecond).NewtonsPerSecond, NanonewtonsPerSecondTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromNewtonsPerMinute(newtonpersecond.NewtonsPerMinute).NewtonsPerSecond, NewtonsPerMinuteTolerance); - AssertEx.EqualTolerance(1, ForceChangeRate.FromNewtonsPerSecond(newtonpersecond.NewtonsPerSecond).NewtonsPerSecond, NewtonsPerSecondTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ForceChangeRate v = ForceChangeRate.FromNewtonsPerSecond(1); - AssertEx.EqualTolerance(-1, -v.NewtonsPerSecond, NewtonsPerSecondTolerance); - AssertEx.EqualTolerance(2, (ForceChangeRate.FromNewtonsPerSecond(3)-v).NewtonsPerSecond, NewtonsPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).NewtonsPerSecond, NewtonsPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).NewtonsPerSecond, NewtonsPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).NewtonsPerSecond, NewtonsPerSecondTolerance); - AssertEx.EqualTolerance(2, (ForceChangeRate.FromNewtonsPerSecond(10)/5).NewtonsPerSecond, NewtonsPerSecondTolerance); - AssertEx.EqualTolerance(2, ForceChangeRate.FromNewtonsPerSecond(10)/ForceChangeRate.FromNewtonsPerSecond(5), NewtonsPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ForceChangeRate oneNewtonPerSecond = ForceChangeRate.FromNewtonsPerSecond(1); - ForceChangeRate twoNewtonsPerSecond = ForceChangeRate.FromNewtonsPerSecond(2); - - Assert.True(oneNewtonPerSecond < twoNewtonsPerSecond); - Assert.True(oneNewtonPerSecond <= twoNewtonsPerSecond); - Assert.True(twoNewtonsPerSecond > oneNewtonPerSecond); - Assert.True(twoNewtonsPerSecond >= oneNewtonPerSecond); - - Assert.False(oneNewtonPerSecond > twoNewtonsPerSecond); - Assert.False(oneNewtonPerSecond >= twoNewtonsPerSecond); - Assert.False(twoNewtonsPerSecond < oneNewtonPerSecond); - Assert.False(twoNewtonsPerSecond <= oneNewtonPerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - ForceChangeRate newtonpersecond = ForceChangeRate.FromNewtonsPerSecond(1); - Assert.Equal(0, newtonpersecond.CompareTo(newtonpersecond)); - Assert.True(newtonpersecond.CompareTo(ForceChangeRate.Zero) > 0); - Assert.True(ForceChangeRate.Zero.CompareTo(newtonpersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ForceChangeRate newtonpersecond = ForceChangeRate.FromNewtonsPerSecond(1); - Assert.Throws(() => newtonpersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ForceChangeRate newtonpersecond = ForceChangeRate.FromNewtonsPerSecond(1); - Assert.Throws(() => newtonpersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ForceChangeRate v = ForceChangeRate.FromNewtonsPerSecond(1); - Assert.True(v.Equals(ForceChangeRate.FromNewtonsPerSecond(1), NewtonsPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ForceChangeRate.Zero, NewtonsPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ForceChangeRate newtonpersecond = ForceChangeRate.FromNewtonsPerSecond(1); - Assert.False(newtonpersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ForceChangeRate newtonpersecond = ForceChangeRate.FromNewtonsPerSecond(1); - Assert.False(newtonpersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ForceChangeRateUnit.Undefined, ForceChangeRate.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ForceChangeRateUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ForceChangeRateUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ForcePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ForcePerLengthTestsBase.g.cs deleted file mode 100644 index 3d38fe444d..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ForcePerLengthTestsBase.g.cs +++ /dev/null @@ -1,304 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ForcePerLength. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ForcePerLengthTestsBase - { - protected abstract double CentinewtonsPerMeterInOneNewtonPerMeter { get; } - protected abstract double DecinewtonsPerMeterInOneNewtonPerMeter { get; } - protected abstract double KilogramsForcePerMeterInOneNewtonPerMeter { get; } - protected abstract double KilonewtonsPerMeterInOneNewtonPerMeter { get; } - protected abstract double MeganewtonsPerMeterInOneNewtonPerMeter { get; } - protected abstract double MicronewtonsPerMeterInOneNewtonPerMeter { get; } - protected abstract double MillinewtonsPerMeterInOneNewtonPerMeter { get; } - protected abstract double NanonewtonsPerMeterInOneNewtonPerMeter { get; } - protected abstract double NewtonsPerMeterInOneNewtonPerMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentinewtonsPerMeterTolerance { get { return 1e-5; } } - protected virtual double DecinewtonsPerMeterTolerance { get { return 1e-5; } } - protected virtual double KilogramsForcePerMeterTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsPerMeterTolerance { get { return 1e-5; } } - protected virtual double MeganewtonsPerMeterTolerance { get { return 1e-5; } } - protected virtual double MicronewtonsPerMeterTolerance { get { return 1e-5; } } - protected virtual double MillinewtonsPerMeterTolerance { get { return 1e-5; } } - protected virtual double NanonewtonsPerMeterTolerance { get { return 1e-5; } } - protected virtual double NewtonsPerMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ForcePerLength((double)0.0, ForcePerLengthUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ForcePerLength(double.PositiveInfinity, ForcePerLengthUnit.NewtonPerMeter)); - Assert.Throws(() => new ForcePerLength(double.NegativeInfinity, ForcePerLengthUnit.NewtonPerMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ForcePerLength(double.NaN, ForcePerLengthUnit.NewtonPerMeter)); - } - - [Fact] - public void NewtonPerMeterToForcePerLengthUnits() - { - ForcePerLength newtonpermeter = ForcePerLength.FromNewtonsPerMeter(1); - AssertEx.EqualTolerance(CentinewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.CentinewtonsPerMeter, CentinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(DecinewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.DecinewtonsPerMeter, DecinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerMeterInOneNewtonPerMeter, newtonpermeter.KilogramsForcePerMeter, KilogramsForcePerMeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.KilonewtonsPerMeter, KilonewtonsPerMeterTolerance); - AssertEx.EqualTolerance(MeganewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.MeganewtonsPerMeter, MeganewtonsPerMeterTolerance); - AssertEx.EqualTolerance(MicronewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.MicronewtonsPerMeter, MicronewtonsPerMeterTolerance); - AssertEx.EqualTolerance(MillinewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.MillinewtonsPerMeter, MillinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(NanonewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.NanonewtonsPerMeter, NanonewtonsPerMeterTolerance); - AssertEx.EqualTolerance(NewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.NewtonsPerMeter, NewtonsPerMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ForcePerLength.From(1, ForcePerLengthUnit.CentinewtonPerMeter).CentinewtonsPerMeter, CentinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.From(1, ForcePerLengthUnit.DecinewtonPerMeter).DecinewtonsPerMeter, DecinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.From(1, ForcePerLengthUnit.KilogramForcePerMeter).KilogramsForcePerMeter, KilogramsForcePerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.From(1, ForcePerLengthUnit.KilonewtonPerMeter).KilonewtonsPerMeter, KilonewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.From(1, ForcePerLengthUnit.MeganewtonPerMeter).MeganewtonsPerMeter, MeganewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.From(1, ForcePerLengthUnit.MicronewtonPerMeter).MicronewtonsPerMeter, MicronewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.From(1, ForcePerLengthUnit.MillinewtonPerMeter).MillinewtonsPerMeter, MillinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.From(1, ForcePerLengthUnit.NanonewtonPerMeter).NanonewtonsPerMeter, NanonewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.From(1, ForcePerLengthUnit.NewtonPerMeter).NewtonsPerMeter, NewtonsPerMeterTolerance); - } - - [Fact] - public void FromNewtonsPerMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ForcePerLength.FromNewtonsPerMeter(double.PositiveInfinity)); - Assert.Throws(() => ForcePerLength.FromNewtonsPerMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromNewtonsPerMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ForcePerLength.FromNewtonsPerMeter(double.NaN)); - } - - [Fact] - public void As() - { - var newtonpermeter = ForcePerLength.FromNewtonsPerMeter(1); - AssertEx.EqualTolerance(CentinewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.CentinewtonPerMeter), CentinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(DecinewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.DecinewtonPerMeter), DecinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerMeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.KilogramForcePerMeter), KilogramsForcePerMeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.KilonewtonPerMeter), KilonewtonsPerMeterTolerance); - AssertEx.EqualTolerance(MeganewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.MeganewtonPerMeter), MeganewtonsPerMeterTolerance); - AssertEx.EqualTolerance(MicronewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.MicronewtonPerMeter), MicronewtonsPerMeterTolerance); - AssertEx.EqualTolerance(MillinewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.MillinewtonPerMeter), MillinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(NanonewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.NanonewtonPerMeter), NanonewtonsPerMeterTolerance); - AssertEx.EqualTolerance(NewtonsPerMeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.NewtonPerMeter), NewtonsPerMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var newtonpermeter = ForcePerLength.FromNewtonsPerMeter(1); - - var centinewtonpermeterQuantity = newtonpermeter.ToUnit(ForcePerLengthUnit.CentinewtonPerMeter); - AssertEx.EqualTolerance(CentinewtonsPerMeterInOneNewtonPerMeter, (double)centinewtonpermeterQuantity.Value, CentinewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerMeter, centinewtonpermeterQuantity.Unit); - - var decinewtonpermeterQuantity = newtonpermeter.ToUnit(ForcePerLengthUnit.DecinewtonPerMeter); - AssertEx.EqualTolerance(DecinewtonsPerMeterInOneNewtonPerMeter, (double)decinewtonpermeterQuantity.Value, DecinewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerMeter, decinewtonpermeterQuantity.Unit); - - var kilogramforcepermeterQuantity = newtonpermeter.ToUnit(ForcePerLengthUnit.KilogramForcePerMeter); - AssertEx.EqualTolerance(KilogramsForcePerMeterInOneNewtonPerMeter, (double)kilogramforcepermeterQuantity.Value, KilogramsForcePerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMeter, kilogramforcepermeterQuantity.Unit); - - var kilonewtonpermeterQuantity = newtonpermeter.ToUnit(ForcePerLengthUnit.KilonewtonPerMeter); - AssertEx.EqualTolerance(KilonewtonsPerMeterInOneNewtonPerMeter, (double)kilonewtonpermeterQuantity.Value, KilonewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerMeter, kilonewtonpermeterQuantity.Unit); - - var meganewtonpermeterQuantity = newtonpermeter.ToUnit(ForcePerLengthUnit.MeganewtonPerMeter); - AssertEx.EqualTolerance(MeganewtonsPerMeterInOneNewtonPerMeter, (double)meganewtonpermeterQuantity.Value, MeganewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.MeganewtonPerMeter, meganewtonpermeterQuantity.Unit); - - var micronewtonpermeterQuantity = newtonpermeter.ToUnit(ForcePerLengthUnit.MicronewtonPerMeter); - AssertEx.EqualTolerance(MicronewtonsPerMeterInOneNewtonPerMeter, (double)micronewtonpermeterQuantity.Value, MicronewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerMeter, micronewtonpermeterQuantity.Unit); - - var millinewtonpermeterQuantity = newtonpermeter.ToUnit(ForcePerLengthUnit.MillinewtonPerMeter); - AssertEx.EqualTolerance(MillinewtonsPerMeterInOneNewtonPerMeter, (double)millinewtonpermeterQuantity.Value, MillinewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.MillinewtonPerMeter, millinewtonpermeterQuantity.Unit); - - var nanonewtonpermeterQuantity = newtonpermeter.ToUnit(ForcePerLengthUnit.NanonewtonPerMeter); - AssertEx.EqualTolerance(NanonewtonsPerMeterInOneNewtonPerMeter, (double)nanonewtonpermeterQuantity.Value, NanonewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerMeter, nanonewtonpermeterQuantity.Unit); - - var newtonpermeterQuantity = newtonpermeter.ToUnit(ForcePerLengthUnit.NewtonPerMeter); - AssertEx.EqualTolerance(NewtonsPerMeterInOneNewtonPerMeter, (double)newtonpermeterQuantity.Value, NewtonsPerMeterTolerance); - Assert.Equal(ForcePerLengthUnit.NewtonPerMeter, newtonpermeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ForcePerLength newtonpermeter = ForcePerLength.FromNewtonsPerMeter(1); - AssertEx.EqualTolerance(1, ForcePerLength.FromCentinewtonsPerMeter(newtonpermeter.CentinewtonsPerMeter).NewtonsPerMeter, CentinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.FromDecinewtonsPerMeter(newtonpermeter.DecinewtonsPerMeter).NewtonsPerMeter, DecinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.FromKilogramsForcePerMeter(newtonpermeter.KilogramsForcePerMeter).NewtonsPerMeter, KilogramsForcePerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.FromKilonewtonsPerMeter(newtonpermeter.KilonewtonsPerMeter).NewtonsPerMeter, KilonewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.FromMeganewtonsPerMeter(newtonpermeter.MeganewtonsPerMeter).NewtonsPerMeter, MeganewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.FromMicronewtonsPerMeter(newtonpermeter.MicronewtonsPerMeter).NewtonsPerMeter, MicronewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.FromMillinewtonsPerMeter(newtonpermeter.MillinewtonsPerMeter).NewtonsPerMeter, MillinewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.FromNanonewtonsPerMeter(newtonpermeter.NanonewtonsPerMeter).NewtonsPerMeter, NanonewtonsPerMeterTolerance); - AssertEx.EqualTolerance(1, ForcePerLength.FromNewtonsPerMeter(newtonpermeter.NewtonsPerMeter).NewtonsPerMeter, NewtonsPerMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ForcePerLength v = ForcePerLength.FromNewtonsPerMeter(1); - AssertEx.EqualTolerance(-1, -v.NewtonsPerMeter, NewtonsPerMeterTolerance); - AssertEx.EqualTolerance(2, (ForcePerLength.FromNewtonsPerMeter(3)-v).NewtonsPerMeter, NewtonsPerMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).NewtonsPerMeter, NewtonsPerMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).NewtonsPerMeter, NewtonsPerMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).NewtonsPerMeter, NewtonsPerMeterTolerance); - AssertEx.EqualTolerance(2, (ForcePerLength.FromNewtonsPerMeter(10)/5).NewtonsPerMeter, NewtonsPerMeterTolerance); - AssertEx.EqualTolerance(2, ForcePerLength.FromNewtonsPerMeter(10)/ForcePerLength.FromNewtonsPerMeter(5), NewtonsPerMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ForcePerLength oneNewtonPerMeter = ForcePerLength.FromNewtonsPerMeter(1); - ForcePerLength twoNewtonsPerMeter = ForcePerLength.FromNewtonsPerMeter(2); - - Assert.True(oneNewtonPerMeter < twoNewtonsPerMeter); - Assert.True(oneNewtonPerMeter <= twoNewtonsPerMeter); - Assert.True(twoNewtonsPerMeter > oneNewtonPerMeter); - Assert.True(twoNewtonsPerMeter >= oneNewtonPerMeter); - - Assert.False(oneNewtonPerMeter > twoNewtonsPerMeter); - Assert.False(oneNewtonPerMeter >= twoNewtonsPerMeter); - Assert.False(twoNewtonsPerMeter < oneNewtonPerMeter); - Assert.False(twoNewtonsPerMeter <= oneNewtonPerMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - ForcePerLength newtonpermeter = ForcePerLength.FromNewtonsPerMeter(1); - Assert.Equal(0, newtonpermeter.CompareTo(newtonpermeter)); - Assert.True(newtonpermeter.CompareTo(ForcePerLength.Zero) > 0); - Assert.True(ForcePerLength.Zero.CompareTo(newtonpermeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ForcePerLength newtonpermeter = ForcePerLength.FromNewtonsPerMeter(1); - Assert.Throws(() => newtonpermeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ForcePerLength newtonpermeter = ForcePerLength.FromNewtonsPerMeter(1); - Assert.Throws(() => newtonpermeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ForcePerLength v = ForcePerLength.FromNewtonsPerMeter(1); - Assert.True(v.Equals(ForcePerLength.FromNewtonsPerMeter(1), NewtonsPerMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ForcePerLength.Zero, NewtonsPerMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ForcePerLength newtonpermeter = ForcePerLength.FromNewtonsPerMeter(1); - Assert.False(newtonpermeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ForcePerLength newtonpermeter = ForcePerLength.FromNewtonsPerMeter(1); - Assert.False(newtonpermeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ForcePerLengthUnit.Undefined, ForcePerLength.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ForcePerLengthUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ForcePerLengthUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ForceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ForceTestsBase.g.cs deleted file mode 100644 index 1e1e29d3a6..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ForceTestsBase.g.cs +++ /dev/null @@ -1,314 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Force. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ForceTestsBase - { - protected abstract double DecanewtonsInOneNewton { get; } - protected abstract double DyneInOneNewton { get; } - protected abstract double KilogramsForceInOneNewton { get; } - protected abstract double KilonewtonsInOneNewton { get; } - protected abstract double KiloPondsInOneNewton { get; } - protected abstract double MeganewtonsInOneNewton { get; } - protected abstract double NewtonsInOneNewton { get; } - protected abstract double PoundalsInOneNewton { get; } - protected abstract double PoundsForceInOneNewton { get; } - protected abstract double TonnesForceInOneNewton { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DecanewtonsTolerance { get { return 1e-5; } } - protected virtual double DyneTolerance { get { return 1e-5; } } - protected virtual double KilogramsForceTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsTolerance { get { return 1e-5; } } - protected virtual double KiloPondsTolerance { get { return 1e-5; } } - protected virtual double MeganewtonsTolerance { get { return 1e-5; } } - protected virtual double NewtonsTolerance { get { return 1e-5; } } - protected virtual double PoundalsTolerance { get { return 1e-5; } } - protected virtual double PoundsForceTolerance { get { return 1e-5; } } - protected virtual double TonnesForceTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Force((double)0.0, ForceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Force(double.PositiveInfinity, ForceUnit.Newton)); - Assert.Throws(() => new Force(double.NegativeInfinity, ForceUnit.Newton)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Force(double.NaN, ForceUnit.Newton)); - } - - [Fact] - public void NewtonToForceUnits() - { - Force newton = Force.FromNewtons(1); - AssertEx.EqualTolerance(DecanewtonsInOneNewton, newton.Decanewtons, DecanewtonsTolerance); - AssertEx.EqualTolerance(DyneInOneNewton, newton.Dyne, DyneTolerance); - AssertEx.EqualTolerance(KilogramsForceInOneNewton, newton.KilogramsForce, KilogramsForceTolerance); - AssertEx.EqualTolerance(KilonewtonsInOneNewton, newton.Kilonewtons, KilonewtonsTolerance); - AssertEx.EqualTolerance(KiloPondsInOneNewton, newton.KiloPonds, KiloPondsTolerance); - AssertEx.EqualTolerance(MeganewtonsInOneNewton, newton.Meganewtons, MeganewtonsTolerance); - AssertEx.EqualTolerance(NewtonsInOneNewton, newton.Newtons, NewtonsTolerance); - AssertEx.EqualTolerance(PoundalsInOneNewton, newton.Poundals, PoundalsTolerance); - AssertEx.EqualTolerance(PoundsForceInOneNewton, newton.PoundsForce, PoundsForceTolerance); - AssertEx.EqualTolerance(TonnesForceInOneNewton, newton.TonnesForce, TonnesForceTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Decanewton).Decanewtons, DecanewtonsTolerance); - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Dyn).Dyne, DyneTolerance); - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.KilogramForce).KilogramsForce, KilogramsForceTolerance); - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Kilonewton).Kilonewtons, KilonewtonsTolerance); - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.KiloPond).KiloPonds, KiloPondsTolerance); - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Meganewton).Meganewtons, MeganewtonsTolerance); - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Newton).Newtons, NewtonsTolerance); - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Poundal).Poundals, PoundalsTolerance); - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.PoundForce).PoundsForce, PoundsForceTolerance); - AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.TonneForce).TonnesForce, TonnesForceTolerance); - } - - [Fact] - public void FromNewtons_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Force.FromNewtons(double.PositiveInfinity)); - Assert.Throws(() => Force.FromNewtons(double.NegativeInfinity)); - } - - [Fact] - public void FromNewtons_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Force.FromNewtons(double.NaN)); - } - - [Fact] - public void As() - { - var newton = Force.FromNewtons(1); - AssertEx.EqualTolerance(DecanewtonsInOneNewton, newton.As(ForceUnit.Decanewton), DecanewtonsTolerance); - AssertEx.EqualTolerance(DyneInOneNewton, newton.As(ForceUnit.Dyn), DyneTolerance); - AssertEx.EqualTolerance(KilogramsForceInOneNewton, newton.As(ForceUnit.KilogramForce), KilogramsForceTolerance); - AssertEx.EqualTolerance(KilonewtonsInOneNewton, newton.As(ForceUnit.Kilonewton), KilonewtonsTolerance); - AssertEx.EqualTolerance(KiloPondsInOneNewton, newton.As(ForceUnit.KiloPond), KiloPondsTolerance); - AssertEx.EqualTolerance(MeganewtonsInOneNewton, newton.As(ForceUnit.Meganewton), MeganewtonsTolerance); - AssertEx.EqualTolerance(NewtonsInOneNewton, newton.As(ForceUnit.Newton), NewtonsTolerance); - AssertEx.EqualTolerance(PoundalsInOneNewton, newton.As(ForceUnit.Poundal), PoundalsTolerance); - AssertEx.EqualTolerance(PoundsForceInOneNewton, newton.As(ForceUnit.PoundForce), PoundsForceTolerance); - AssertEx.EqualTolerance(TonnesForceInOneNewton, newton.As(ForceUnit.TonneForce), TonnesForceTolerance); - } - - [Fact] - public void ToUnit() - { - var newton = Force.FromNewtons(1); - - var decanewtonQuantity = newton.ToUnit(ForceUnit.Decanewton); - AssertEx.EqualTolerance(DecanewtonsInOneNewton, (double)decanewtonQuantity.Value, DecanewtonsTolerance); - Assert.Equal(ForceUnit.Decanewton, decanewtonQuantity.Unit); - - var dynQuantity = newton.ToUnit(ForceUnit.Dyn); - AssertEx.EqualTolerance(DyneInOneNewton, (double)dynQuantity.Value, DyneTolerance); - Assert.Equal(ForceUnit.Dyn, dynQuantity.Unit); - - var kilogramforceQuantity = newton.ToUnit(ForceUnit.KilogramForce); - AssertEx.EqualTolerance(KilogramsForceInOneNewton, (double)kilogramforceQuantity.Value, KilogramsForceTolerance); - Assert.Equal(ForceUnit.KilogramForce, kilogramforceQuantity.Unit); - - var kilonewtonQuantity = newton.ToUnit(ForceUnit.Kilonewton); - AssertEx.EqualTolerance(KilonewtonsInOneNewton, (double)kilonewtonQuantity.Value, KilonewtonsTolerance); - Assert.Equal(ForceUnit.Kilonewton, kilonewtonQuantity.Unit); - - var kilopondQuantity = newton.ToUnit(ForceUnit.KiloPond); - AssertEx.EqualTolerance(KiloPondsInOneNewton, (double)kilopondQuantity.Value, KiloPondsTolerance); - Assert.Equal(ForceUnit.KiloPond, kilopondQuantity.Unit); - - var meganewtonQuantity = newton.ToUnit(ForceUnit.Meganewton); - AssertEx.EqualTolerance(MeganewtonsInOneNewton, (double)meganewtonQuantity.Value, MeganewtonsTolerance); - Assert.Equal(ForceUnit.Meganewton, meganewtonQuantity.Unit); - - var newtonQuantity = newton.ToUnit(ForceUnit.Newton); - AssertEx.EqualTolerance(NewtonsInOneNewton, (double)newtonQuantity.Value, NewtonsTolerance); - Assert.Equal(ForceUnit.Newton, newtonQuantity.Unit); - - var poundalQuantity = newton.ToUnit(ForceUnit.Poundal); - AssertEx.EqualTolerance(PoundalsInOneNewton, (double)poundalQuantity.Value, PoundalsTolerance); - Assert.Equal(ForceUnit.Poundal, poundalQuantity.Unit); - - var poundforceQuantity = newton.ToUnit(ForceUnit.PoundForce); - AssertEx.EqualTolerance(PoundsForceInOneNewton, (double)poundforceQuantity.Value, PoundsForceTolerance); - Assert.Equal(ForceUnit.PoundForce, poundforceQuantity.Unit); - - var tonneforceQuantity = newton.ToUnit(ForceUnit.TonneForce); - AssertEx.EqualTolerance(TonnesForceInOneNewton, (double)tonneforceQuantity.Value, TonnesForceTolerance); - Assert.Equal(ForceUnit.TonneForce, tonneforceQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Force newton = Force.FromNewtons(1); - AssertEx.EqualTolerance(1, Force.FromDecanewtons(newton.Decanewtons).Newtons, DecanewtonsTolerance); - AssertEx.EqualTolerance(1, Force.FromDyne(newton.Dyne).Newtons, DyneTolerance); - AssertEx.EqualTolerance(1, Force.FromKilogramsForce(newton.KilogramsForce).Newtons, KilogramsForceTolerance); - AssertEx.EqualTolerance(1, Force.FromKilonewtons(newton.Kilonewtons).Newtons, KilonewtonsTolerance); - AssertEx.EqualTolerance(1, Force.FromKiloPonds(newton.KiloPonds).Newtons, KiloPondsTolerance); - AssertEx.EqualTolerance(1, Force.FromMeganewtons(newton.Meganewtons).Newtons, MeganewtonsTolerance); - AssertEx.EqualTolerance(1, Force.FromNewtons(newton.Newtons).Newtons, NewtonsTolerance); - AssertEx.EqualTolerance(1, Force.FromPoundals(newton.Poundals).Newtons, PoundalsTolerance); - AssertEx.EqualTolerance(1, Force.FromPoundsForce(newton.PoundsForce).Newtons, PoundsForceTolerance); - AssertEx.EqualTolerance(1, Force.FromTonnesForce(newton.TonnesForce).Newtons, TonnesForceTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Force v = Force.FromNewtons(1); - AssertEx.EqualTolerance(-1, -v.Newtons, NewtonsTolerance); - AssertEx.EqualTolerance(2, (Force.FromNewtons(3)-v).Newtons, NewtonsTolerance); - AssertEx.EqualTolerance(2, (v + v).Newtons, NewtonsTolerance); - AssertEx.EqualTolerance(10, (v*10).Newtons, NewtonsTolerance); - AssertEx.EqualTolerance(10, (10*v).Newtons, NewtonsTolerance); - AssertEx.EqualTolerance(2, (Force.FromNewtons(10)/5).Newtons, NewtonsTolerance); - AssertEx.EqualTolerance(2, Force.FromNewtons(10)/Force.FromNewtons(5), NewtonsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Force oneNewton = Force.FromNewtons(1); - Force twoNewtons = Force.FromNewtons(2); - - Assert.True(oneNewton < twoNewtons); - Assert.True(oneNewton <= twoNewtons); - Assert.True(twoNewtons > oneNewton); - Assert.True(twoNewtons >= oneNewton); - - Assert.False(oneNewton > twoNewtons); - Assert.False(oneNewton >= twoNewtons); - Assert.False(twoNewtons < oneNewton); - Assert.False(twoNewtons <= oneNewton); - } - - [Fact] - public void CompareToIsImplemented() - { - Force newton = Force.FromNewtons(1); - Assert.Equal(0, newton.CompareTo(newton)); - Assert.True(newton.CompareTo(Force.Zero) > 0); - Assert.True(Force.Zero.CompareTo(newton) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Force newton = Force.FromNewtons(1); - Assert.Throws(() => newton.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Force newton = Force.FromNewtons(1); - Assert.Throws(() => newton.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Force v = Force.FromNewtons(1); - Assert.True(v.Equals(Force.FromNewtons(1), NewtonsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Force.Zero, NewtonsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Force newton = Force.FromNewtons(1); - Assert.False(newton.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Force newton = Force.FromNewtons(1); - Assert.False(newton.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ForceUnit.Undefined, Force.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ForceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ForceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/FrequencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/FrequencyTestsBase.g.cs deleted file mode 100644 index ab9735e592..0000000000 --- a/UnitsNet.Tests/GeneratedCode/FrequencyTestsBase.g.cs +++ /dev/null @@ -1,294 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Frequency. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class FrequencyTestsBase - { - protected abstract double CyclesPerHourInOneHertz { get; } - protected abstract double CyclesPerMinuteInOneHertz { get; } - protected abstract double GigahertzInOneHertz { get; } - protected abstract double HertzInOneHertz { get; } - protected abstract double KilohertzInOneHertz { get; } - protected abstract double MegahertzInOneHertz { get; } - protected abstract double RadiansPerSecondInOneHertz { get; } - protected abstract double TerahertzInOneHertz { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CyclesPerHourTolerance { get { return 1e-5; } } - protected virtual double CyclesPerMinuteTolerance { get { return 1e-5; } } - protected virtual double GigahertzTolerance { get { return 1e-5; } } - protected virtual double HertzTolerance { get { return 1e-5; } } - protected virtual double KilohertzTolerance { get { return 1e-5; } } - protected virtual double MegahertzTolerance { get { return 1e-5; } } - protected virtual double RadiansPerSecondTolerance { get { return 1e-5; } } - protected virtual double TerahertzTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Frequency((double)0.0, FrequencyUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Frequency(double.PositiveInfinity, FrequencyUnit.Hertz)); - Assert.Throws(() => new Frequency(double.NegativeInfinity, FrequencyUnit.Hertz)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Frequency(double.NaN, FrequencyUnit.Hertz)); - } - - [Fact] - public void HertzToFrequencyUnits() - { - Frequency hertz = Frequency.FromHertz(1); - AssertEx.EqualTolerance(CyclesPerHourInOneHertz, hertz.CyclesPerHour, CyclesPerHourTolerance); - AssertEx.EqualTolerance(CyclesPerMinuteInOneHertz, hertz.CyclesPerMinute, CyclesPerMinuteTolerance); - AssertEx.EqualTolerance(GigahertzInOneHertz, hertz.Gigahertz, GigahertzTolerance); - AssertEx.EqualTolerance(HertzInOneHertz, hertz.Hertz, HertzTolerance); - AssertEx.EqualTolerance(KilohertzInOneHertz, hertz.Kilohertz, KilohertzTolerance); - AssertEx.EqualTolerance(MegahertzInOneHertz, hertz.Megahertz, MegahertzTolerance); - AssertEx.EqualTolerance(RadiansPerSecondInOneHertz, hertz.RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(TerahertzInOneHertz, hertz.Terahertz, TerahertzTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Frequency.From(1, FrequencyUnit.CyclePerHour).CyclesPerHour, CyclesPerHourTolerance); - AssertEx.EqualTolerance(1, Frequency.From(1, FrequencyUnit.CyclePerMinute).CyclesPerMinute, CyclesPerMinuteTolerance); - AssertEx.EqualTolerance(1, Frequency.From(1, FrequencyUnit.Gigahertz).Gigahertz, GigahertzTolerance); - AssertEx.EqualTolerance(1, Frequency.From(1, FrequencyUnit.Hertz).Hertz, HertzTolerance); - AssertEx.EqualTolerance(1, Frequency.From(1, FrequencyUnit.Kilohertz).Kilohertz, KilohertzTolerance); - AssertEx.EqualTolerance(1, Frequency.From(1, FrequencyUnit.Megahertz).Megahertz, MegahertzTolerance); - AssertEx.EqualTolerance(1, Frequency.From(1, FrequencyUnit.RadianPerSecond).RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(1, Frequency.From(1, FrequencyUnit.Terahertz).Terahertz, TerahertzTolerance); - } - - [Fact] - public void FromHertz_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Frequency.FromHertz(double.PositiveInfinity)); - Assert.Throws(() => Frequency.FromHertz(double.NegativeInfinity)); - } - - [Fact] - public void FromHertz_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Frequency.FromHertz(double.NaN)); - } - - [Fact] - public void As() - { - var hertz = Frequency.FromHertz(1); - AssertEx.EqualTolerance(CyclesPerHourInOneHertz, hertz.As(FrequencyUnit.CyclePerHour), CyclesPerHourTolerance); - AssertEx.EqualTolerance(CyclesPerMinuteInOneHertz, hertz.As(FrequencyUnit.CyclePerMinute), CyclesPerMinuteTolerance); - AssertEx.EqualTolerance(GigahertzInOneHertz, hertz.As(FrequencyUnit.Gigahertz), GigahertzTolerance); - AssertEx.EqualTolerance(HertzInOneHertz, hertz.As(FrequencyUnit.Hertz), HertzTolerance); - AssertEx.EqualTolerance(KilohertzInOneHertz, hertz.As(FrequencyUnit.Kilohertz), KilohertzTolerance); - AssertEx.EqualTolerance(MegahertzInOneHertz, hertz.As(FrequencyUnit.Megahertz), MegahertzTolerance); - AssertEx.EqualTolerance(RadiansPerSecondInOneHertz, hertz.As(FrequencyUnit.RadianPerSecond), RadiansPerSecondTolerance); - AssertEx.EqualTolerance(TerahertzInOneHertz, hertz.As(FrequencyUnit.Terahertz), TerahertzTolerance); - } - - [Fact] - public void ToUnit() - { - var hertz = Frequency.FromHertz(1); - - var cycleperhourQuantity = hertz.ToUnit(FrequencyUnit.CyclePerHour); - AssertEx.EqualTolerance(CyclesPerHourInOneHertz, (double)cycleperhourQuantity.Value, CyclesPerHourTolerance); - Assert.Equal(FrequencyUnit.CyclePerHour, cycleperhourQuantity.Unit); - - var cycleperminuteQuantity = hertz.ToUnit(FrequencyUnit.CyclePerMinute); - AssertEx.EqualTolerance(CyclesPerMinuteInOneHertz, (double)cycleperminuteQuantity.Value, CyclesPerMinuteTolerance); - Assert.Equal(FrequencyUnit.CyclePerMinute, cycleperminuteQuantity.Unit); - - var gigahertzQuantity = hertz.ToUnit(FrequencyUnit.Gigahertz); - AssertEx.EqualTolerance(GigahertzInOneHertz, (double)gigahertzQuantity.Value, GigahertzTolerance); - Assert.Equal(FrequencyUnit.Gigahertz, gigahertzQuantity.Unit); - - var hertzQuantity = hertz.ToUnit(FrequencyUnit.Hertz); - AssertEx.EqualTolerance(HertzInOneHertz, (double)hertzQuantity.Value, HertzTolerance); - Assert.Equal(FrequencyUnit.Hertz, hertzQuantity.Unit); - - var kilohertzQuantity = hertz.ToUnit(FrequencyUnit.Kilohertz); - AssertEx.EqualTolerance(KilohertzInOneHertz, (double)kilohertzQuantity.Value, KilohertzTolerance); - Assert.Equal(FrequencyUnit.Kilohertz, kilohertzQuantity.Unit); - - var megahertzQuantity = hertz.ToUnit(FrequencyUnit.Megahertz); - AssertEx.EqualTolerance(MegahertzInOneHertz, (double)megahertzQuantity.Value, MegahertzTolerance); - Assert.Equal(FrequencyUnit.Megahertz, megahertzQuantity.Unit); - - var radianpersecondQuantity = hertz.ToUnit(FrequencyUnit.RadianPerSecond); - AssertEx.EqualTolerance(RadiansPerSecondInOneHertz, (double)radianpersecondQuantity.Value, RadiansPerSecondTolerance); - Assert.Equal(FrequencyUnit.RadianPerSecond, radianpersecondQuantity.Unit); - - var terahertzQuantity = hertz.ToUnit(FrequencyUnit.Terahertz); - AssertEx.EqualTolerance(TerahertzInOneHertz, (double)terahertzQuantity.Value, TerahertzTolerance); - Assert.Equal(FrequencyUnit.Terahertz, terahertzQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Frequency hertz = Frequency.FromHertz(1); - AssertEx.EqualTolerance(1, Frequency.FromCyclesPerHour(hertz.CyclesPerHour).Hertz, CyclesPerHourTolerance); - AssertEx.EqualTolerance(1, Frequency.FromCyclesPerMinute(hertz.CyclesPerMinute).Hertz, CyclesPerMinuteTolerance); - AssertEx.EqualTolerance(1, Frequency.FromGigahertz(hertz.Gigahertz).Hertz, GigahertzTolerance); - AssertEx.EqualTolerance(1, Frequency.FromHertz(hertz.Hertz).Hertz, HertzTolerance); - AssertEx.EqualTolerance(1, Frequency.FromKilohertz(hertz.Kilohertz).Hertz, KilohertzTolerance); - AssertEx.EqualTolerance(1, Frequency.FromMegahertz(hertz.Megahertz).Hertz, MegahertzTolerance); - AssertEx.EqualTolerance(1, Frequency.FromRadiansPerSecond(hertz.RadiansPerSecond).Hertz, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(1, Frequency.FromTerahertz(hertz.Terahertz).Hertz, TerahertzTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Frequency v = Frequency.FromHertz(1); - AssertEx.EqualTolerance(-1, -v.Hertz, HertzTolerance); - AssertEx.EqualTolerance(2, (Frequency.FromHertz(3)-v).Hertz, HertzTolerance); - AssertEx.EqualTolerance(2, (v + v).Hertz, HertzTolerance); - AssertEx.EqualTolerance(10, (v*10).Hertz, HertzTolerance); - AssertEx.EqualTolerance(10, (10*v).Hertz, HertzTolerance); - AssertEx.EqualTolerance(2, (Frequency.FromHertz(10)/5).Hertz, HertzTolerance); - AssertEx.EqualTolerance(2, Frequency.FromHertz(10)/Frequency.FromHertz(5), HertzTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Frequency oneHertz = Frequency.FromHertz(1); - Frequency twoHertz = Frequency.FromHertz(2); - - Assert.True(oneHertz < twoHertz); - Assert.True(oneHertz <= twoHertz); - Assert.True(twoHertz > oneHertz); - Assert.True(twoHertz >= oneHertz); - - Assert.False(oneHertz > twoHertz); - Assert.False(oneHertz >= twoHertz); - Assert.False(twoHertz < oneHertz); - Assert.False(twoHertz <= oneHertz); - } - - [Fact] - public void CompareToIsImplemented() - { - Frequency hertz = Frequency.FromHertz(1); - Assert.Equal(0, hertz.CompareTo(hertz)); - Assert.True(hertz.CompareTo(Frequency.Zero) > 0); - Assert.True(Frequency.Zero.CompareTo(hertz) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Frequency hertz = Frequency.FromHertz(1); - Assert.Throws(() => hertz.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Frequency hertz = Frequency.FromHertz(1); - Assert.Throws(() => hertz.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Frequency v = Frequency.FromHertz(1); - Assert.True(v.Equals(Frequency.FromHertz(1), HertzTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Frequency.Zero, HertzTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Frequency hertz = Frequency.FromHertz(1); - Assert.False(hertz.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Frequency hertz = Frequency.FromHertz(1); - Assert.False(hertz.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(FrequencyUnit.Undefined, Frequency.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(FrequencyUnit)).Cast(); - foreach(var unit in units) - { - if(unit == FrequencyUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/HeatFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/HeatFluxTestsBase.g.cs deleted file mode 100644 index 08ad882829..0000000000 --- a/UnitsNet.Tests/GeneratedCode/HeatFluxTestsBase.g.cs +++ /dev/null @@ -1,374 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of HeatFlux. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class HeatFluxTestsBase - { - protected abstract double BtusPerHourSquareFootInOneWattPerSquareMeter { get; } - protected abstract double BtusPerMinuteSquareFootInOneWattPerSquareMeter { get; } - protected abstract double BtusPerSecondSquareFootInOneWattPerSquareMeter { get; } - protected abstract double BtusPerSecondSquareInchInOneWattPerSquareMeter { get; } - protected abstract double CaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter { get; } - protected abstract double CentiwattsPerSquareMeterInOneWattPerSquareMeter { get; } - protected abstract double DeciwattsPerSquareMeterInOneWattPerSquareMeter { get; } - protected abstract double KilocaloriesPerHourSquareMeterInOneWattPerSquareMeter { get; } - protected abstract double KilocaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter { get; } - protected abstract double KilowattsPerSquareMeterInOneWattPerSquareMeter { get; } - protected abstract double MicrowattsPerSquareMeterInOneWattPerSquareMeter { get; } - protected abstract double MilliwattsPerSquareMeterInOneWattPerSquareMeter { get; } - protected abstract double NanowattsPerSquareMeterInOneWattPerSquareMeter { get; } - protected abstract double WattsPerSquareFootInOneWattPerSquareMeter { get; } - protected abstract double WattsPerSquareInchInOneWattPerSquareMeter { get; } - protected abstract double WattsPerSquareMeterInOneWattPerSquareMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double BtusPerHourSquareFootTolerance { get { return 1e-5; } } - protected virtual double BtusPerMinuteSquareFootTolerance { get { return 1e-5; } } - protected virtual double BtusPerSecondSquareFootTolerance { get { return 1e-5; } } - protected virtual double BtusPerSecondSquareInchTolerance { get { return 1e-5; } } - protected virtual double CaloriesPerSecondSquareCentimeterTolerance { get { return 1e-5; } } - protected virtual double CentiwattsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double DeciwattsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double KilocaloriesPerHourSquareMeterTolerance { get { return 1e-5; } } - protected virtual double KilocaloriesPerSecondSquareCentimeterTolerance { get { return 1e-5; } } - protected virtual double KilowattsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double MicrowattsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double MilliwattsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double NanowattsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double WattsPerSquareFootTolerance { get { return 1e-5; } } - protected virtual double WattsPerSquareInchTolerance { get { return 1e-5; } } - protected virtual double WattsPerSquareMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new HeatFlux((double)0.0, HeatFluxUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new HeatFlux(double.PositiveInfinity, HeatFluxUnit.WattPerSquareMeter)); - Assert.Throws(() => new HeatFlux(double.NegativeInfinity, HeatFluxUnit.WattPerSquareMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new HeatFlux(double.NaN, HeatFluxUnit.WattPerSquareMeter)); - } - - [Fact] - public void WattPerSquareMeterToHeatFluxUnits() - { - HeatFlux wattpersquaremeter = HeatFlux.FromWattsPerSquareMeter(1); - AssertEx.EqualTolerance(BtusPerHourSquareFootInOneWattPerSquareMeter, wattpersquaremeter.BtusPerHourSquareFoot, BtusPerHourSquareFootTolerance); - AssertEx.EqualTolerance(BtusPerMinuteSquareFootInOneWattPerSquareMeter, wattpersquaremeter.BtusPerMinuteSquareFoot, BtusPerMinuteSquareFootTolerance); - AssertEx.EqualTolerance(BtusPerSecondSquareFootInOneWattPerSquareMeter, wattpersquaremeter.BtusPerSecondSquareFoot, BtusPerSecondSquareFootTolerance); - AssertEx.EqualTolerance(BtusPerSecondSquareInchInOneWattPerSquareMeter, wattpersquaremeter.BtusPerSecondSquareInch, BtusPerSecondSquareInchTolerance); - AssertEx.EqualTolerance(CaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter, wattpersquaremeter.CaloriesPerSecondSquareCentimeter, CaloriesPerSecondSquareCentimeterTolerance); - AssertEx.EqualTolerance(CentiwattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.CentiwattsPerSquareMeter, CentiwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(DeciwattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.DeciwattsPerSquareMeter, DeciwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(KilocaloriesPerHourSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.KilocaloriesPerHourSquareMeter, KilocaloriesPerHourSquareMeterTolerance); - AssertEx.EqualTolerance(KilocaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter, wattpersquaremeter.KilocaloriesPerSecondSquareCentimeter, KilocaloriesPerSecondSquareCentimeterTolerance); - AssertEx.EqualTolerance(KilowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(MicrowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.MicrowattsPerSquareMeter, MicrowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(MilliwattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.MilliwattsPerSquareMeter, MilliwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(NanowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.NanowattsPerSquareMeter, NanowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(WattsPerSquareFootInOneWattPerSquareMeter, wattpersquaremeter.WattsPerSquareFoot, WattsPerSquareFootTolerance); - AssertEx.EqualTolerance(WattsPerSquareInchInOneWattPerSquareMeter, wattpersquaremeter.WattsPerSquareInch, WattsPerSquareInchTolerance); - AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.WattsPerSquareMeter, WattsPerSquareMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.BtuPerHourSquareFoot).BtusPerHourSquareFoot, BtusPerHourSquareFootTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.BtuPerMinuteSquareFoot).BtusPerMinuteSquareFoot, BtusPerMinuteSquareFootTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.BtuPerSecondSquareFoot).BtusPerSecondSquareFoot, BtusPerSecondSquareFootTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.BtuPerSecondSquareInch).BtusPerSecondSquareInch, BtusPerSecondSquareInchTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.CaloriePerSecondSquareCentimeter).CaloriesPerSecondSquareCentimeter, CaloriesPerSecondSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.CentiwattPerSquareMeter).CentiwattsPerSquareMeter, CentiwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.DeciwattPerSquareMeter).DeciwattsPerSquareMeter, DeciwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.KilocaloriePerHourSquareMeter).KilocaloriesPerHourSquareMeter, KilocaloriesPerHourSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.KilocaloriePerSecondSquareCentimeter).KilocaloriesPerSecondSquareCentimeter, KilocaloriesPerSecondSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.KilowattPerSquareMeter).KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.MicrowattPerSquareMeter).MicrowattsPerSquareMeter, MicrowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.MilliwattPerSquareMeter).MilliwattsPerSquareMeter, MilliwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.NanowattPerSquareMeter).NanowattsPerSquareMeter, NanowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.WattPerSquareFoot).WattsPerSquareFoot, WattsPerSquareFootTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.WattPerSquareInch).WattsPerSquareInch, WattsPerSquareInchTolerance); - AssertEx.EqualTolerance(1, HeatFlux.From(1, HeatFluxUnit.WattPerSquareMeter).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - } - - [Fact] - public void FromWattsPerSquareMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => HeatFlux.FromWattsPerSquareMeter(double.PositiveInfinity)); - Assert.Throws(() => HeatFlux.FromWattsPerSquareMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromWattsPerSquareMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => HeatFlux.FromWattsPerSquareMeter(double.NaN)); - } - - [Fact] - public void As() - { - var wattpersquaremeter = HeatFlux.FromWattsPerSquareMeter(1); - AssertEx.EqualTolerance(BtusPerHourSquareFootInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.BtuPerHourSquareFoot), BtusPerHourSquareFootTolerance); - AssertEx.EqualTolerance(BtusPerMinuteSquareFootInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.BtuPerMinuteSquareFoot), BtusPerMinuteSquareFootTolerance); - AssertEx.EqualTolerance(BtusPerSecondSquareFootInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.BtuPerSecondSquareFoot), BtusPerSecondSquareFootTolerance); - AssertEx.EqualTolerance(BtusPerSecondSquareInchInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.BtuPerSecondSquareInch), BtusPerSecondSquareInchTolerance); - AssertEx.EqualTolerance(CaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.CaloriePerSecondSquareCentimeter), CaloriesPerSecondSquareCentimeterTolerance); - AssertEx.EqualTolerance(CentiwattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.CentiwattPerSquareMeter), CentiwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(DeciwattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.DeciwattPerSquareMeter), DeciwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(KilocaloriesPerHourSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.KilocaloriePerHourSquareMeter), KilocaloriesPerHourSquareMeterTolerance); - AssertEx.EqualTolerance(KilocaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.KilocaloriePerSecondSquareCentimeter), KilocaloriesPerSecondSquareCentimeterTolerance); - AssertEx.EqualTolerance(KilowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.KilowattPerSquareMeter), KilowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(MicrowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.MicrowattPerSquareMeter), MicrowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(MilliwattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.MilliwattPerSquareMeter), MilliwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(NanowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.NanowattPerSquareMeter), NanowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(WattsPerSquareFootInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.WattPerSquareFoot), WattsPerSquareFootTolerance); - AssertEx.EqualTolerance(WattsPerSquareInchInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.WattPerSquareInch), WattsPerSquareInchTolerance); - AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.WattPerSquareMeter), WattsPerSquareMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var wattpersquaremeter = HeatFlux.FromWattsPerSquareMeter(1); - - var btuperhoursquarefootQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.BtuPerHourSquareFoot); - AssertEx.EqualTolerance(BtusPerHourSquareFootInOneWattPerSquareMeter, (double)btuperhoursquarefootQuantity.Value, BtusPerHourSquareFootTolerance); - Assert.Equal(HeatFluxUnit.BtuPerHourSquareFoot, btuperhoursquarefootQuantity.Unit); - - var btuperminutesquarefootQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.BtuPerMinuteSquareFoot); - AssertEx.EqualTolerance(BtusPerMinuteSquareFootInOneWattPerSquareMeter, (double)btuperminutesquarefootQuantity.Value, BtusPerMinuteSquareFootTolerance); - Assert.Equal(HeatFluxUnit.BtuPerMinuteSquareFoot, btuperminutesquarefootQuantity.Unit); - - var btupersecondsquarefootQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.BtuPerSecondSquareFoot); - AssertEx.EqualTolerance(BtusPerSecondSquareFootInOneWattPerSquareMeter, (double)btupersecondsquarefootQuantity.Value, BtusPerSecondSquareFootTolerance); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareFoot, btupersecondsquarefootQuantity.Unit); - - var btupersecondsquareinchQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.BtuPerSecondSquareInch); - AssertEx.EqualTolerance(BtusPerSecondSquareInchInOneWattPerSquareMeter, (double)btupersecondsquareinchQuantity.Value, BtusPerSecondSquareInchTolerance); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareInch, btupersecondsquareinchQuantity.Unit); - - var caloriepersecondsquarecentimeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.CaloriePerSecondSquareCentimeter); - AssertEx.EqualTolerance(CaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter, (double)caloriepersecondsquarecentimeterQuantity.Value, CaloriesPerSecondSquareCentimeterTolerance); - Assert.Equal(HeatFluxUnit.CaloriePerSecondSquareCentimeter, caloriepersecondsquarecentimeterQuantity.Unit); - - var centiwattpersquaremeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.CentiwattPerSquareMeter); - AssertEx.EqualTolerance(CentiwattsPerSquareMeterInOneWattPerSquareMeter, (double)centiwattpersquaremeterQuantity.Value, CentiwattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.CentiwattPerSquareMeter, centiwattpersquaremeterQuantity.Unit); - - var deciwattpersquaremeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.DeciwattPerSquareMeter); - AssertEx.EqualTolerance(DeciwattsPerSquareMeterInOneWattPerSquareMeter, (double)deciwattpersquaremeterQuantity.Value, DeciwattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.DeciwattPerSquareMeter, deciwattpersquaremeterQuantity.Unit); - - var kilocalorieperhoursquaremeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.KilocaloriePerHourSquareMeter); - AssertEx.EqualTolerance(KilocaloriesPerHourSquareMeterInOneWattPerSquareMeter, (double)kilocalorieperhoursquaremeterQuantity.Value, KilocaloriesPerHourSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.KilocaloriePerHourSquareMeter, kilocalorieperhoursquaremeterQuantity.Unit); - - var kilocaloriepersecondsquarecentimeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.KilocaloriePerSecondSquareCentimeter); - AssertEx.EqualTolerance(KilocaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter, (double)kilocaloriepersecondsquarecentimeterQuantity.Value, KilocaloriesPerSecondSquareCentimeterTolerance); - Assert.Equal(HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, kilocaloriepersecondsquarecentimeterQuantity.Unit); - - var kilowattpersquaremeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.KilowattPerSquareMeter); - AssertEx.EqualTolerance(KilowattsPerSquareMeterInOneWattPerSquareMeter, (double)kilowattpersquaremeterQuantity.Value, KilowattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.KilowattPerSquareMeter, kilowattpersquaremeterQuantity.Unit); - - var microwattpersquaremeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.MicrowattPerSquareMeter); - AssertEx.EqualTolerance(MicrowattsPerSquareMeterInOneWattPerSquareMeter, (double)microwattpersquaremeterQuantity.Value, MicrowattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.MicrowattPerSquareMeter, microwattpersquaremeterQuantity.Unit); - - var milliwattpersquaremeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.MilliwattPerSquareMeter); - AssertEx.EqualTolerance(MilliwattsPerSquareMeterInOneWattPerSquareMeter, (double)milliwattpersquaremeterQuantity.Value, MilliwattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.MilliwattPerSquareMeter, milliwattpersquaremeterQuantity.Unit); - - var nanowattpersquaremeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.NanowattPerSquareMeter); - AssertEx.EqualTolerance(NanowattsPerSquareMeterInOneWattPerSquareMeter, (double)nanowattpersquaremeterQuantity.Value, NanowattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.NanowattPerSquareMeter, nanowattpersquaremeterQuantity.Unit); - - var wattpersquarefootQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.WattPerSquareFoot); - AssertEx.EqualTolerance(WattsPerSquareFootInOneWattPerSquareMeter, (double)wattpersquarefootQuantity.Value, WattsPerSquareFootTolerance); - Assert.Equal(HeatFluxUnit.WattPerSquareFoot, wattpersquarefootQuantity.Unit); - - var wattpersquareinchQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.WattPerSquareInch); - AssertEx.EqualTolerance(WattsPerSquareInchInOneWattPerSquareMeter, (double)wattpersquareinchQuantity.Value, WattsPerSquareInchTolerance); - Assert.Equal(HeatFluxUnit.WattPerSquareInch, wattpersquareinchQuantity.Unit); - - var wattpersquaremeterQuantity = wattpersquaremeter.ToUnit(HeatFluxUnit.WattPerSquareMeter); - AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, (double)wattpersquaremeterQuantity.Value, WattsPerSquareMeterTolerance); - Assert.Equal(HeatFluxUnit.WattPerSquareMeter, wattpersquaremeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - HeatFlux wattpersquaremeter = HeatFlux.FromWattsPerSquareMeter(1); - AssertEx.EqualTolerance(1, HeatFlux.FromBtusPerHourSquareFoot(wattpersquaremeter.BtusPerHourSquareFoot).WattsPerSquareMeter, BtusPerHourSquareFootTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromBtusPerMinuteSquareFoot(wattpersquaremeter.BtusPerMinuteSquareFoot).WattsPerSquareMeter, BtusPerMinuteSquareFootTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromBtusPerSecondSquareFoot(wattpersquaremeter.BtusPerSecondSquareFoot).WattsPerSquareMeter, BtusPerSecondSquareFootTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromBtusPerSecondSquareInch(wattpersquaremeter.BtusPerSecondSquareInch).WattsPerSquareMeter, BtusPerSecondSquareInchTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromCaloriesPerSecondSquareCentimeter(wattpersquaremeter.CaloriesPerSecondSquareCentimeter).WattsPerSquareMeter, CaloriesPerSecondSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromCentiwattsPerSquareMeter(wattpersquaremeter.CentiwattsPerSquareMeter).WattsPerSquareMeter, CentiwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromDeciwattsPerSquareMeter(wattpersquaremeter.DeciwattsPerSquareMeter).WattsPerSquareMeter, DeciwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromKilocaloriesPerHourSquareMeter(wattpersquaremeter.KilocaloriesPerHourSquareMeter).WattsPerSquareMeter, KilocaloriesPerHourSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromKilocaloriesPerSecondSquareCentimeter(wattpersquaremeter.KilocaloriesPerSecondSquareCentimeter).WattsPerSquareMeter, KilocaloriesPerSecondSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromKilowattsPerSquareMeter(wattpersquaremeter.KilowattsPerSquareMeter).WattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromMicrowattsPerSquareMeter(wattpersquaremeter.MicrowattsPerSquareMeter).WattsPerSquareMeter, MicrowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromMilliwattsPerSquareMeter(wattpersquaremeter.MilliwattsPerSquareMeter).WattsPerSquareMeter, MilliwattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromNanowattsPerSquareMeter(wattpersquaremeter.NanowattsPerSquareMeter).WattsPerSquareMeter, NanowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromWattsPerSquareFoot(wattpersquaremeter.WattsPerSquareFoot).WattsPerSquareMeter, WattsPerSquareFootTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromWattsPerSquareInch(wattpersquaremeter.WattsPerSquareInch).WattsPerSquareMeter, WattsPerSquareInchTolerance); - AssertEx.EqualTolerance(1, HeatFlux.FromWattsPerSquareMeter(wattpersquaremeter.WattsPerSquareMeter).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - HeatFlux v = HeatFlux.FromWattsPerSquareMeter(1); - AssertEx.EqualTolerance(-1, -v.WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (HeatFlux.FromWattsPerSquareMeter(3)-v).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (HeatFlux.FromWattsPerSquareMeter(10)/5).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, HeatFlux.FromWattsPerSquareMeter(10)/HeatFlux.FromWattsPerSquareMeter(5), WattsPerSquareMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - HeatFlux oneWattPerSquareMeter = HeatFlux.FromWattsPerSquareMeter(1); - HeatFlux twoWattsPerSquareMeter = HeatFlux.FromWattsPerSquareMeter(2); - - Assert.True(oneWattPerSquareMeter < twoWattsPerSquareMeter); - Assert.True(oneWattPerSquareMeter <= twoWattsPerSquareMeter); - Assert.True(twoWattsPerSquareMeter > oneWattPerSquareMeter); - Assert.True(twoWattsPerSquareMeter >= oneWattPerSquareMeter); - - Assert.False(oneWattPerSquareMeter > twoWattsPerSquareMeter); - Assert.False(oneWattPerSquareMeter >= twoWattsPerSquareMeter); - Assert.False(twoWattsPerSquareMeter < oneWattPerSquareMeter); - Assert.False(twoWattsPerSquareMeter <= oneWattPerSquareMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - HeatFlux wattpersquaremeter = HeatFlux.FromWattsPerSquareMeter(1); - Assert.Equal(0, wattpersquaremeter.CompareTo(wattpersquaremeter)); - Assert.True(wattpersquaremeter.CompareTo(HeatFlux.Zero) > 0); - Assert.True(HeatFlux.Zero.CompareTo(wattpersquaremeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - HeatFlux wattpersquaremeter = HeatFlux.FromWattsPerSquareMeter(1); - Assert.Throws(() => wattpersquaremeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - HeatFlux wattpersquaremeter = HeatFlux.FromWattsPerSquareMeter(1); - Assert.Throws(() => wattpersquaremeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - HeatFlux v = HeatFlux.FromWattsPerSquareMeter(1); - Assert.True(v.Equals(HeatFlux.FromWattsPerSquareMeter(1), WattsPerSquareMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(HeatFlux.Zero, WattsPerSquareMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - HeatFlux wattpersquaremeter = HeatFlux.FromWattsPerSquareMeter(1); - Assert.False(wattpersquaremeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - HeatFlux wattpersquaremeter = HeatFlux.FromWattsPerSquareMeter(1); - Assert.False(wattpersquaremeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(HeatFluxUnit.Undefined, HeatFlux.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(HeatFluxUnit)).Cast(); - foreach(var unit in units) - { - if(unit == HeatFluxUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/HeatTransferCoefficientTestsBase.g.cs deleted file mode 100644 index a4d21f5b50..0000000000 --- a/UnitsNet.Tests/GeneratedCode/HeatTransferCoefficientTestsBase.g.cs +++ /dev/null @@ -1,234 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of HeatTransferCoefficient. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class HeatTransferCoefficientTestsBase - { - protected abstract double WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin { get; } - protected abstract double WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double WattsPerSquareMeterCelsiusTolerance { get { return 1e-5; } } - protected virtual double WattsPerSquareMeterKelvinTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new HeatTransferCoefficient((double)0.0, HeatTransferCoefficientUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new HeatTransferCoefficient(double.PositiveInfinity, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); - Assert.Throws(() => new HeatTransferCoefficient(double.NegativeInfinity, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new HeatTransferCoefficient(double.NaN, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)); - } - - [Fact] - public void WattPerSquareMeterKelvinToHeatTransferCoefficientUnits() - { - HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - AssertEx.EqualTolerance(WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); - AssertEx.EqualTolerance(WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius).WattsPerSquareMeterCelsius, WattsPerSquareMeterCelsiusTolerance); - AssertEx.EqualTolerance(1, HeatTransferCoefficient.From(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin).WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - } - - [Fact] - public void FromWattsPerSquareMeterKelvin_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(double.PositiveInfinity)); - Assert.Throws(() => HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(double.NegativeInfinity)); - } - - [Fact] - public void FromWattsPerSquareMeterKelvin_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(double.NaN)); - } - - [Fact] - public void As() - { - var wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - AssertEx.EqualTolerance(WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius), WattsPerSquareMeterCelsiusTolerance); - AssertEx.EqualTolerance(WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), WattsPerSquareMeterKelvinTolerance); - } - - [Fact] - public void ToUnit() - { - var wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - - var wattpersquaremetercelsiusQuantity = wattpersquaremeterkelvin.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius); - AssertEx.EqualTolerance(WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin, (double)wattpersquaremetercelsiusQuantity.Value, WattsPerSquareMeterCelsiusTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, wattpersquaremetercelsiusQuantity.Unit); - - var wattpersquaremeterkelvinQuantity = wattpersquaremeterkelvin.ToUnit(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin); - AssertEx.EqualTolerance(WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, (double)wattpersquaremeterkelvinQuantity.Value, WattsPerSquareMeterKelvinTolerance); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, wattpersquaremeterkelvinQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromWattsPerSquareMeterCelsius(wattpersquaremeterkelvin.WattsPerSquareMeterCelsius).WattsPerSquareMeterKelvin, WattsPerSquareMeterCelsiusTolerance); - AssertEx.EqualTolerance(1, HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(wattpersquaremeterkelvin.WattsPerSquareMeterKelvin).WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - HeatTransferCoefficient v = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - AssertEx.EqualTolerance(-1, -v.WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - AssertEx.EqualTolerance(2, (HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(3)-v).WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - AssertEx.EqualTolerance(2, (v + v).WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - AssertEx.EqualTolerance(10, (v*10).WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - AssertEx.EqualTolerance(10, (10*v).WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - AssertEx.EqualTolerance(2, (HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(10)/5).WattsPerSquareMeterKelvin, WattsPerSquareMeterKelvinTolerance); - AssertEx.EqualTolerance(2, HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(10)/HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(5), WattsPerSquareMeterKelvinTolerance); - } - - [Fact] - public void ComparisonOperators() - { - HeatTransferCoefficient oneWattPerSquareMeterKelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - HeatTransferCoefficient twoWattsPerSquareMeterKelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(2); - - Assert.True(oneWattPerSquareMeterKelvin < twoWattsPerSquareMeterKelvin); - Assert.True(oneWattPerSquareMeterKelvin <= twoWattsPerSquareMeterKelvin); - Assert.True(twoWattsPerSquareMeterKelvin > oneWattPerSquareMeterKelvin); - Assert.True(twoWattsPerSquareMeterKelvin >= oneWattPerSquareMeterKelvin); - - Assert.False(oneWattPerSquareMeterKelvin > twoWattsPerSquareMeterKelvin); - Assert.False(oneWattPerSquareMeterKelvin >= twoWattsPerSquareMeterKelvin); - Assert.False(twoWattsPerSquareMeterKelvin < oneWattPerSquareMeterKelvin); - Assert.False(twoWattsPerSquareMeterKelvin <= oneWattPerSquareMeterKelvin); - } - - [Fact] - public void CompareToIsImplemented() - { - HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - Assert.Equal(0, wattpersquaremeterkelvin.CompareTo(wattpersquaremeterkelvin)); - Assert.True(wattpersquaremeterkelvin.CompareTo(HeatTransferCoefficient.Zero) > 0); - Assert.True(HeatTransferCoefficient.Zero.CompareTo(wattpersquaremeterkelvin) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - Assert.Throws(() => wattpersquaremeterkelvin.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - Assert.Throws(() => wattpersquaremeterkelvin.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - HeatTransferCoefficient v = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - Assert.True(v.Equals(HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1), WattsPerSquareMeterKelvinTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(HeatTransferCoefficient.Zero, WattsPerSquareMeterKelvinTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - Assert.False(wattpersquaremeterkelvin.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - HeatTransferCoefficient wattpersquaremeterkelvin = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1); - Assert.False(wattpersquaremeterkelvin.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(HeatTransferCoefficientUnit.Undefined, HeatTransferCoefficient.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(HeatTransferCoefficientUnit)).Cast(); - foreach(var unit in units) - { - if(unit == HeatTransferCoefficientUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/IlluminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/IlluminanceTestsBase.g.cs deleted file mode 100644 index 25c2b1a2cf..0000000000 --- a/UnitsNet.Tests/GeneratedCode/IlluminanceTestsBase.g.cs +++ /dev/null @@ -1,254 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Illuminance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class IlluminanceTestsBase - { - protected abstract double KiloluxInOneLux { get; } - protected abstract double LuxInOneLux { get; } - protected abstract double MegaluxInOneLux { get; } - protected abstract double MilliluxInOneLux { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KiloluxTolerance { get { return 1e-5; } } - protected virtual double LuxTolerance { get { return 1e-5; } } - protected virtual double MegaluxTolerance { get { return 1e-5; } } - protected virtual double MilliluxTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Illuminance((double)0.0, IlluminanceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Illuminance(double.PositiveInfinity, IlluminanceUnit.Lux)); - Assert.Throws(() => new Illuminance(double.NegativeInfinity, IlluminanceUnit.Lux)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Illuminance(double.NaN, IlluminanceUnit.Lux)); - } - - [Fact] - public void LuxToIlluminanceUnits() - { - Illuminance lux = Illuminance.FromLux(1); - AssertEx.EqualTolerance(KiloluxInOneLux, lux.Kilolux, KiloluxTolerance); - AssertEx.EqualTolerance(LuxInOneLux, lux.Lux, LuxTolerance); - AssertEx.EqualTolerance(MegaluxInOneLux, lux.Megalux, MegaluxTolerance); - AssertEx.EqualTolerance(MilliluxInOneLux, lux.Millilux, MilliluxTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Illuminance.From(1, IlluminanceUnit.Kilolux).Kilolux, KiloluxTolerance); - AssertEx.EqualTolerance(1, Illuminance.From(1, IlluminanceUnit.Lux).Lux, LuxTolerance); - AssertEx.EqualTolerance(1, Illuminance.From(1, IlluminanceUnit.Megalux).Megalux, MegaluxTolerance); - AssertEx.EqualTolerance(1, Illuminance.From(1, IlluminanceUnit.Millilux).Millilux, MilliluxTolerance); - } - - [Fact] - public void FromLux_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Illuminance.FromLux(double.PositiveInfinity)); - Assert.Throws(() => Illuminance.FromLux(double.NegativeInfinity)); - } - - [Fact] - public void FromLux_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Illuminance.FromLux(double.NaN)); - } - - [Fact] - public void As() - { - var lux = Illuminance.FromLux(1); - AssertEx.EqualTolerance(KiloluxInOneLux, lux.As(IlluminanceUnit.Kilolux), KiloluxTolerance); - AssertEx.EqualTolerance(LuxInOneLux, lux.As(IlluminanceUnit.Lux), LuxTolerance); - AssertEx.EqualTolerance(MegaluxInOneLux, lux.As(IlluminanceUnit.Megalux), MegaluxTolerance); - AssertEx.EqualTolerance(MilliluxInOneLux, lux.As(IlluminanceUnit.Millilux), MilliluxTolerance); - } - - [Fact] - public void ToUnit() - { - var lux = Illuminance.FromLux(1); - - var kiloluxQuantity = lux.ToUnit(IlluminanceUnit.Kilolux); - AssertEx.EqualTolerance(KiloluxInOneLux, (double)kiloluxQuantity.Value, KiloluxTolerance); - Assert.Equal(IlluminanceUnit.Kilolux, kiloluxQuantity.Unit); - - var luxQuantity = lux.ToUnit(IlluminanceUnit.Lux); - AssertEx.EqualTolerance(LuxInOneLux, (double)luxQuantity.Value, LuxTolerance); - Assert.Equal(IlluminanceUnit.Lux, luxQuantity.Unit); - - var megaluxQuantity = lux.ToUnit(IlluminanceUnit.Megalux); - AssertEx.EqualTolerance(MegaluxInOneLux, (double)megaluxQuantity.Value, MegaluxTolerance); - Assert.Equal(IlluminanceUnit.Megalux, megaluxQuantity.Unit); - - var milliluxQuantity = lux.ToUnit(IlluminanceUnit.Millilux); - AssertEx.EqualTolerance(MilliluxInOneLux, (double)milliluxQuantity.Value, MilliluxTolerance); - Assert.Equal(IlluminanceUnit.Millilux, milliluxQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Illuminance lux = Illuminance.FromLux(1); - AssertEx.EqualTolerance(1, Illuminance.FromKilolux(lux.Kilolux).Lux, KiloluxTolerance); - AssertEx.EqualTolerance(1, Illuminance.FromLux(lux.Lux).Lux, LuxTolerance); - AssertEx.EqualTolerance(1, Illuminance.FromMegalux(lux.Megalux).Lux, MegaluxTolerance); - AssertEx.EqualTolerance(1, Illuminance.FromMillilux(lux.Millilux).Lux, MilliluxTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Illuminance v = Illuminance.FromLux(1); - AssertEx.EqualTolerance(-1, -v.Lux, LuxTolerance); - AssertEx.EqualTolerance(2, (Illuminance.FromLux(3)-v).Lux, LuxTolerance); - AssertEx.EqualTolerance(2, (v + v).Lux, LuxTolerance); - AssertEx.EqualTolerance(10, (v*10).Lux, LuxTolerance); - AssertEx.EqualTolerance(10, (10*v).Lux, LuxTolerance); - AssertEx.EqualTolerance(2, (Illuminance.FromLux(10)/5).Lux, LuxTolerance); - AssertEx.EqualTolerance(2, Illuminance.FromLux(10)/Illuminance.FromLux(5), LuxTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Illuminance oneLux = Illuminance.FromLux(1); - Illuminance twoLux = Illuminance.FromLux(2); - - Assert.True(oneLux < twoLux); - Assert.True(oneLux <= twoLux); - Assert.True(twoLux > oneLux); - Assert.True(twoLux >= oneLux); - - Assert.False(oneLux > twoLux); - Assert.False(oneLux >= twoLux); - Assert.False(twoLux < oneLux); - Assert.False(twoLux <= oneLux); - } - - [Fact] - public void CompareToIsImplemented() - { - Illuminance lux = Illuminance.FromLux(1); - Assert.Equal(0, lux.CompareTo(lux)); - Assert.True(lux.CompareTo(Illuminance.Zero) > 0); - Assert.True(Illuminance.Zero.CompareTo(lux) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Illuminance lux = Illuminance.FromLux(1); - Assert.Throws(() => lux.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Illuminance lux = Illuminance.FromLux(1); - Assert.Throws(() => lux.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Illuminance v = Illuminance.FromLux(1); - Assert.True(v.Equals(Illuminance.FromLux(1), LuxTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Illuminance.Zero, LuxTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Illuminance lux = Illuminance.FromLux(1); - Assert.False(lux.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Illuminance lux = Illuminance.FromLux(1); - Assert.False(lux.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(IlluminanceUnit.Undefined, Illuminance.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(IlluminanceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == IlluminanceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/IrradianceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/IrradianceTestsBase.g.cs deleted file mode 100644 index 2268311347..0000000000 --- a/UnitsNet.Tests/GeneratedCode/IrradianceTestsBase.g.cs +++ /dev/null @@ -1,234 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Irradiance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class IrradianceTestsBase - { - protected abstract double KilowattsPerSquareMeterInOneWattPerSquareMeter { get; } - protected abstract double WattsPerSquareMeterInOneWattPerSquareMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilowattsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double WattsPerSquareMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Irradiance((double)0.0, IrradianceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Irradiance(double.PositiveInfinity, IrradianceUnit.WattPerSquareMeter)); - Assert.Throws(() => new Irradiance(double.NegativeInfinity, IrradianceUnit.WattPerSquareMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Irradiance(double.NaN, IrradianceUnit.WattPerSquareMeter)); - } - - [Fact] - public void WattPerSquareMeterToIrradianceUnits() - { - Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1); - AssertEx.EqualTolerance(KilowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.WattsPerSquareMeter, WattsPerSquareMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Irradiance.From(1, IrradianceUnit.KilowattPerSquareMeter).KilowattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Irradiance.From(1, IrradianceUnit.WattPerSquareMeter).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - } - - [Fact] - public void FromWattsPerSquareMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Irradiance.FromWattsPerSquareMeter(double.PositiveInfinity)); - Assert.Throws(() => Irradiance.FromWattsPerSquareMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromWattsPerSquareMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Irradiance.FromWattsPerSquareMeter(double.NaN)); - } - - [Fact] - public void As() - { - var wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1); - AssertEx.EqualTolerance(KilowattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(IrradianceUnit.KilowattPerSquareMeter), KilowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(IrradianceUnit.WattPerSquareMeter), WattsPerSquareMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1); - - var kilowattpersquaremeterQuantity = wattpersquaremeter.ToUnit(IrradianceUnit.KilowattPerSquareMeter); - AssertEx.EqualTolerance(KilowattsPerSquareMeterInOneWattPerSquareMeter, (double)kilowattpersquaremeterQuantity.Value, KilowattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.KilowattPerSquareMeter, kilowattpersquaremeterQuantity.Unit); - - var wattpersquaremeterQuantity = wattpersquaremeter.ToUnit(IrradianceUnit.WattPerSquareMeter); - AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, (double)wattpersquaremeterQuantity.Value, WattsPerSquareMeterTolerance); - Assert.Equal(IrradianceUnit.WattPerSquareMeter, wattpersquaremeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1); - AssertEx.EqualTolerance(1, Irradiance.FromKilowattsPerSquareMeter(wattpersquaremeter.KilowattsPerSquareMeter).WattsPerSquareMeter, KilowattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Irradiance.FromWattsPerSquareMeter(wattpersquaremeter.WattsPerSquareMeter).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Irradiance v = Irradiance.FromWattsPerSquareMeter(1); - AssertEx.EqualTolerance(-1, -v.WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (Irradiance.FromWattsPerSquareMeter(3)-v).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (Irradiance.FromWattsPerSquareMeter(10)/5).WattsPerSquareMeter, WattsPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, Irradiance.FromWattsPerSquareMeter(10)/Irradiance.FromWattsPerSquareMeter(5), WattsPerSquareMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Irradiance oneWattPerSquareMeter = Irradiance.FromWattsPerSquareMeter(1); - Irradiance twoWattsPerSquareMeter = Irradiance.FromWattsPerSquareMeter(2); - - Assert.True(oneWattPerSquareMeter < twoWattsPerSquareMeter); - Assert.True(oneWattPerSquareMeter <= twoWattsPerSquareMeter); - Assert.True(twoWattsPerSquareMeter > oneWattPerSquareMeter); - Assert.True(twoWattsPerSquareMeter >= oneWattPerSquareMeter); - - Assert.False(oneWattPerSquareMeter > twoWattsPerSquareMeter); - Assert.False(oneWattPerSquareMeter >= twoWattsPerSquareMeter); - Assert.False(twoWattsPerSquareMeter < oneWattPerSquareMeter); - Assert.False(twoWattsPerSquareMeter <= oneWattPerSquareMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1); - Assert.Equal(0, wattpersquaremeter.CompareTo(wattpersquaremeter)); - Assert.True(wattpersquaremeter.CompareTo(Irradiance.Zero) > 0); - Assert.True(Irradiance.Zero.CompareTo(wattpersquaremeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1); - Assert.Throws(() => wattpersquaremeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1); - Assert.Throws(() => wattpersquaremeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Irradiance v = Irradiance.FromWattsPerSquareMeter(1); - Assert.True(v.Equals(Irradiance.FromWattsPerSquareMeter(1), WattsPerSquareMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Irradiance.Zero, WattsPerSquareMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1); - Assert.False(wattpersquaremeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Irradiance wattpersquaremeter = Irradiance.FromWattsPerSquareMeter(1); - Assert.False(wattpersquaremeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(IrradianceUnit.Undefined, Irradiance.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(IrradianceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == IrradianceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/IrradiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/IrradiationTestsBase.g.cs deleted file mode 100644 index 43d552bb87..0000000000 --- a/UnitsNet.Tests/GeneratedCode/IrradiationTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Irradiation. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class IrradiationTestsBase - { - protected abstract double JoulesPerSquareMeterInOneJoulePerSquareMeter { get; } - protected abstract double KilowattHoursPerSquareMeterInOneJoulePerSquareMeter { get; } - protected abstract double WattHoursPerSquareMeterInOneJoulePerSquareMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double JoulesPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double KilowattHoursPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double WattHoursPerSquareMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Irradiation((double)0.0, IrradiationUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Irradiation(double.PositiveInfinity, IrradiationUnit.JoulePerSquareMeter)); - Assert.Throws(() => new Irradiation(double.NegativeInfinity, IrradiationUnit.JoulePerSquareMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Irradiation(double.NaN, IrradiationUnit.JoulePerSquareMeter)); - } - - [Fact] - public void JoulePerSquareMeterToIrradiationUnits() - { - Irradiation joulepersquaremeter = Irradiation.FromJoulesPerSquareMeter(1); - AssertEx.EqualTolerance(JoulesPerSquareMeterInOneJoulePerSquareMeter, joulepersquaremeter.JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(KilowattHoursPerSquareMeterInOneJoulePerSquareMeter, joulepersquaremeter.KilowattHoursPerSquareMeter, KilowattHoursPerSquareMeterTolerance); - AssertEx.EqualTolerance(WattHoursPerSquareMeterInOneJoulePerSquareMeter, joulepersquaremeter.WattHoursPerSquareMeter, WattHoursPerSquareMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Irradiation.From(1, IrradiationUnit.JoulePerSquareMeter).JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Irradiation.From(1, IrradiationUnit.KilowattHourPerSquareMeter).KilowattHoursPerSquareMeter, KilowattHoursPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Irradiation.From(1, IrradiationUnit.WattHourPerSquareMeter).WattHoursPerSquareMeter, WattHoursPerSquareMeterTolerance); - } - - [Fact] - public void FromJoulesPerSquareMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Irradiation.FromJoulesPerSquareMeter(double.PositiveInfinity)); - Assert.Throws(() => Irradiation.FromJoulesPerSquareMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromJoulesPerSquareMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Irradiation.FromJoulesPerSquareMeter(double.NaN)); - } - - [Fact] - public void As() - { - var joulepersquaremeter = Irradiation.FromJoulesPerSquareMeter(1); - AssertEx.EqualTolerance(JoulesPerSquareMeterInOneJoulePerSquareMeter, joulepersquaremeter.As(IrradiationUnit.JoulePerSquareMeter), JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(KilowattHoursPerSquareMeterInOneJoulePerSquareMeter, joulepersquaremeter.As(IrradiationUnit.KilowattHourPerSquareMeter), KilowattHoursPerSquareMeterTolerance); - AssertEx.EqualTolerance(WattHoursPerSquareMeterInOneJoulePerSquareMeter, joulepersquaremeter.As(IrradiationUnit.WattHourPerSquareMeter), WattHoursPerSquareMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var joulepersquaremeter = Irradiation.FromJoulesPerSquareMeter(1); - - var joulepersquaremeterQuantity = joulepersquaremeter.ToUnit(IrradiationUnit.JoulePerSquareMeter); - AssertEx.EqualTolerance(JoulesPerSquareMeterInOneJoulePerSquareMeter, (double)joulepersquaremeterQuantity.Value, JoulesPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.JoulePerSquareMeter, joulepersquaremeterQuantity.Unit); - - var kilowatthourpersquaremeterQuantity = joulepersquaremeter.ToUnit(IrradiationUnit.KilowattHourPerSquareMeter); - AssertEx.EqualTolerance(KilowattHoursPerSquareMeterInOneJoulePerSquareMeter, (double)kilowatthourpersquaremeterQuantity.Value, KilowattHoursPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.KilowattHourPerSquareMeter, kilowatthourpersquaremeterQuantity.Unit); - - var watthourpersquaremeterQuantity = joulepersquaremeter.ToUnit(IrradiationUnit.WattHourPerSquareMeter); - AssertEx.EqualTolerance(WattHoursPerSquareMeterInOneJoulePerSquareMeter, (double)watthourpersquaremeterQuantity.Value, WattHoursPerSquareMeterTolerance); - Assert.Equal(IrradiationUnit.WattHourPerSquareMeter, watthourpersquaremeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Irradiation joulepersquaremeter = Irradiation.FromJoulesPerSquareMeter(1); - AssertEx.EqualTolerance(1, Irradiation.FromJoulesPerSquareMeter(joulepersquaremeter.JoulesPerSquareMeter).JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Irradiation.FromKilowattHoursPerSquareMeter(joulepersquaremeter.KilowattHoursPerSquareMeter).JoulesPerSquareMeter, KilowattHoursPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Irradiation.FromWattHoursPerSquareMeter(joulepersquaremeter.WattHoursPerSquareMeter).JoulesPerSquareMeter, WattHoursPerSquareMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Irradiation v = Irradiation.FromJoulesPerSquareMeter(1); - AssertEx.EqualTolerance(-1, -v.JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (Irradiation.FromJoulesPerSquareMeter(3)-v).JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (Irradiation.FromJoulesPerSquareMeter(10)/5).JoulesPerSquareMeter, JoulesPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, Irradiation.FromJoulesPerSquareMeter(10)/Irradiation.FromJoulesPerSquareMeter(5), JoulesPerSquareMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Irradiation oneJoulePerSquareMeter = Irradiation.FromJoulesPerSquareMeter(1); - Irradiation twoJoulesPerSquareMeter = Irradiation.FromJoulesPerSquareMeter(2); - - Assert.True(oneJoulePerSquareMeter < twoJoulesPerSquareMeter); - Assert.True(oneJoulePerSquareMeter <= twoJoulesPerSquareMeter); - Assert.True(twoJoulesPerSquareMeter > oneJoulePerSquareMeter); - Assert.True(twoJoulesPerSquareMeter >= oneJoulePerSquareMeter); - - Assert.False(oneJoulePerSquareMeter > twoJoulesPerSquareMeter); - Assert.False(oneJoulePerSquareMeter >= twoJoulesPerSquareMeter); - Assert.False(twoJoulesPerSquareMeter < oneJoulePerSquareMeter); - Assert.False(twoJoulesPerSquareMeter <= oneJoulePerSquareMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Irradiation joulepersquaremeter = Irradiation.FromJoulesPerSquareMeter(1); - Assert.Equal(0, joulepersquaremeter.CompareTo(joulepersquaremeter)); - Assert.True(joulepersquaremeter.CompareTo(Irradiation.Zero) > 0); - Assert.True(Irradiation.Zero.CompareTo(joulepersquaremeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Irradiation joulepersquaremeter = Irradiation.FromJoulesPerSquareMeter(1); - Assert.Throws(() => joulepersquaremeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Irradiation joulepersquaremeter = Irradiation.FromJoulesPerSquareMeter(1); - Assert.Throws(() => joulepersquaremeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Irradiation v = Irradiation.FromJoulesPerSquareMeter(1); - Assert.True(v.Equals(Irradiation.FromJoulesPerSquareMeter(1), JoulesPerSquareMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Irradiation.Zero, JoulesPerSquareMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Irradiation joulepersquaremeter = Irradiation.FromJoulesPerSquareMeter(1); - Assert.False(joulepersquaremeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Irradiation joulepersquaremeter = Irradiation.FromJoulesPerSquareMeter(1); - Assert.False(joulepersquaremeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(IrradiationUnit.Undefined, Irradiation.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(IrradiationUnit)).Cast(); - foreach(var unit in units) - { - if(unit == IrradiationUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/KinematicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/KinematicViscosityTestsBase.g.cs deleted file mode 100644 index d33d786534..0000000000 --- a/UnitsNet.Tests/GeneratedCode/KinematicViscosityTestsBase.g.cs +++ /dev/null @@ -1,294 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of KinematicViscosity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class KinematicViscosityTestsBase - { - protected abstract double CentistokesInOneSquareMeterPerSecond { get; } - protected abstract double DecistokesInOneSquareMeterPerSecond { get; } - protected abstract double KilostokesInOneSquareMeterPerSecond { get; } - protected abstract double MicrostokesInOneSquareMeterPerSecond { get; } - protected abstract double MillistokesInOneSquareMeterPerSecond { get; } - protected abstract double NanostokesInOneSquareMeterPerSecond { get; } - protected abstract double SquareMetersPerSecondInOneSquareMeterPerSecond { get; } - protected abstract double StokesInOneSquareMeterPerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentistokesTolerance { get { return 1e-5; } } - protected virtual double DecistokesTolerance { get { return 1e-5; } } - protected virtual double KilostokesTolerance { get { return 1e-5; } } - protected virtual double MicrostokesTolerance { get { return 1e-5; } } - protected virtual double MillistokesTolerance { get { return 1e-5; } } - protected virtual double NanostokesTolerance { get { return 1e-5; } } - protected virtual double SquareMetersPerSecondTolerance { get { return 1e-5; } } - protected virtual double StokesTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new KinematicViscosity((double)0.0, KinematicViscosityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new KinematicViscosity(double.PositiveInfinity, KinematicViscosityUnit.SquareMeterPerSecond)); - Assert.Throws(() => new KinematicViscosity(double.NegativeInfinity, KinematicViscosityUnit.SquareMeterPerSecond)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new KinematicViscosity(double.NaN, KinematicViscosityUnit.SquareMeterPerSecond)); - } - - [Fact] - public void SquareMeterPerSecondToKinematicViscosityUnits() - { - KinematicViscosity squaremeterpersecond = KinematicViscosity.FromSquareMetersPerSecond(1); - AssertEx.EqualTolerance(CentistokesInOneSquareMeterPerSecond, squaremeterpersecond.Centistokes, CentistokesTolerance); - AssertEx.EqualTolerance(DecistokesInOneSquareMeterPerSecond, squaremeterpersecond.Decistokes, DecistokesTolerance); - AssertEx.EqualTolerance(KilostokesInOneSquareMeterPerSecond, squaremeterpersecond.Kilostokes, KilostokesTolerance); - AssertEx.EqualTolerance(MicrostokesInOneSquareMeterPerSecond, squaremeterpersecond.Microstokes, MicrostokesTolerance); - AssertEx.EqualTolerance(MillistokesInOneSquareMeterPerSecond, squaremeterpersecond.Millistokes, MillistokesTolerance); - AssertEx.EqualTolerance(NanostokesInOneSquareMeterPerSecond, squaremeterpersecond.Nanostokes, NanostokesTolerance); - AssertEx.EqualTolerance(SquareMetersPerSecondInOneSquareMeterPerSecond, squaremeterpersecond.SquareMetersPerSecond, SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(StokesInOneSquareMeterPerSecond, squaremeterpersecond.Stokes, StokesTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, KinematicViscosity.From(1, KinematicViscosityUnit.Centistokes).Centistokes, CentistokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.From(1, KinematicViscosityUnit.Decistokes).Decistokes, DecistokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.From(1, KinematicViscosityUnit.Kilostokes).Kilostokes, KilostokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.From(1, KinematicViscosityUnit.Microstokes).Microstokes, MicrostokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.From(1, KinematicViscosityUnit.Millistokes).Millistokes, MillistokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.From(1, KinematicViscosityUnit.Nanostokes).Nanostokes, NanostokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.From(1, KinematicViscosityUnit.SquareMeterPerSecond).SquareMetersPerSecond, SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.From(1, KinematicViscosityUnit.Stokes).Stokes, StokesTolerance); - } - - [Fact] - public void FromSquareMetersPerSecond_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => KinematicViscosity.FromSquareMetersPerSecond(double.PositiveInfinity)); - Assert.Throws(() => KinematicViscosity.FromSquareMetersPerSecond(double.NegativeInfinity)); - } - - [Fact] - public void FromSquareMetersPerSecond_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => KinematicViscosity.FromSquareMetersPerSecond(double.NaN)); - } - - [Fact] - public void As() - { - var squaremeterpersecond = KinematicViscosity.FromSquareMetersPerSecond(1); - AssertEx.EqualTolerance(CentistokesInOneSquareMeterPerSecond, squaremeterpersecond.As(KinematicViscosityUnit.Centistokes), CentistokesTolerance); - AssertEx.EqualTolerance(DecistokesInOneSquareMeterPerSecond, squaremeterpersecond.As(KinematicViscosityUnit.Decistokes), DecistokesTolerance); - AssertEx.EqualTolerance(KilostokesInOneSquareMeterPerSecond, squaremeterpersecond.As(KinematicViscosityUnit.Kilostokes), KilostokesTolerance); - AssertEx.EqualTolerance(MicrostokesInOneSquareMeterPerSecond, squaremeterpersecond.As(KinematicViscosityUnit.Microstokes), MicrostokesTolerance); - AssertEx.EqualTolerance(MillistokesInOneSquareMeterPerSecond, squaremeterpersecond.As(KinematicViscosityUnit.Millistokes), MillistokesTolerance); - AssertEx.EqualTolerance(NanostokesInOneSquareMeterPerSecond, squaremeterpersecond.As(KinematicViscosityUnit.Nanostokes), NanostokesTolerance); - AssertEx.EqualTolerance(SquareMetersPerSecondInOneSquareMeterPerSecond, squaremeterpersecond.As(KinematicViscosityUnit.SquareMeterPerSecond), SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(StokesInOneSquareMeterPerSecond, squaremeterpersecond.As(KinematicViscosityUnit.Stokes), StokesTolerance); - } - - [Fact] - public void ToUnit() - { - var squaremeterpersecond = KinematicViscosity.FromSquareMetersPerSecond(1); - - var centistokesQuantity = squaremeterpersecond.ToUnit(KinematicViscosityUnit.Centistokes); - AssertEx.EqualTolerance(CentistokesInOneSquareMeterPerSecond, (double)centistokesQuantity.Value, CentistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Centistokes, centistokesQuantity.Unit); - - var decistokesQuantity = squaremeterpersecond.ToUnit(KinematicViscosityUnit.Decistokes); - AssertEx.EqualTolerance(DecistokesInOneSquareMeterPerSecond, (double)decistokesQuantity.Value, DecistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Decistokes, decistokesQuantity.Unit); - - var kilostokesQuantity = squaremeterpersecond.ToUnit(KinematicViscosityUnit.Kilostokes); - AssertEx.EqualTolerance(KilostokesInOneSquareMeterPerSecond, (double)kilostokesQuantity.Value, KilostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Kilostokes, kilostokesQuantity.Unit); - - var microstokesQuantity = squaremeterpersecond.ToUnit(KinematicViscosityUnit.Microstokes); - AssertEx.EqualTolerance(MicrostokesInOneSquareMeterPerSecond, (double)microstokesQuantity.Value, MicrostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Microstokes, microstokesQuantity.Unit); - - var millistokesQuantity = squaremeterpersecond.ToUnit(KinematicViscosityUnit.Millistokes); - AssertEx.EqualTolerance(MillistokesInOneSquareMeterPerSecond, (double)millistokesQuantity.Value, MillistokesTolerance); - Assert.Equal(KinematicViscosityUnit.Millistokes, millistokesQuantity.Unit); - - var nanostokesQuantity = squaremeterpersecond.ToUnit(KinematicViscosityUnit.Nanostokes); - AssertEx.EqualTolerance(NanostokesInOneSquareMeterPerSecond, (double)nanostokesQuantity.Value, NanostokesTolerance); - Assert.Equal(KinematicViscosityUnit.Nanostokes, nanostokesQuantity.Unit); - - var squaremeterpersecondQuantity = squaremeterpersecond.ToUnit(KinematicViscosityUnit.SquareMeterPerSecond); - AssertEx.EqualTolerance(SquareMetersPerSecondInOneSquareMeterPerSecond, (double)squaremeterpersecondQuantity.Value, SquareMetersPerSecondTolerance); - Assert.Equal(KinematicViscosityUnit.SquareMeterPerSecond, squaremeterpersecondQuantity.Unit); - - var stokesQuantity = squaremeterpersecond.ToUnit(KinematicViscosityUnit.Stokes); - AssertEx.EqualTolerance(StokesInOneSquareMeterPerSecond, (double)stokesQuantity.Value, StokesTolerance); - Assert.Equal(KinematicViscosityUnit.Stokes, stokesQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - KinematicViscosity squaremeterpersecond = KinematicViscosity.FromSquareMetersPerSecond(1); - AssertEx.EqualTolerance(1, KinematicViscosity.FromCentistokes(squaremeterpersecond.Centistokes).SquareMetersPerSecond, CentistokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.FromDecistokes(squaremeterpersecond.Decistokes).SquareMetersPerSecond, DecistokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.FromKilostokes(squaremeterpersecond.Kilostokes).SquareMetersPerSecond, KilostokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.FromMicrostokes(squaremeterpersecond.Microstokes).SquareMetersPerSecond, MicrostokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.FromMillistokes(squaremeterpersecond.Millistokes).SquareMetersPerSecond, MillistokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.FromNanostokes(squaremeterpersecond.Nanostokes).SquareMetersPerSecond, NanostokesTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.FromSquareMetersPerSecond(squaremeterpersecond.SquareMetersPerSecond).SquareMetersPerSecond, SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(1, KinematicViscosity.FromStokes(squaremeterpersecond.Stokes).SquareMetersPerSecond, StokesTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - KinematicViscosity v = KinematicViscosity.FromSquareMetersPerSecond(1); - AssertEx.EqualTolerance(-1, -v.SquareMetersPerSecond, SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(2, (KinematicViscosity.FromSquareMetersPerSecond(3)-v).SquareMetersPerSecond, SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).SquareMetersPerSecond, SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).SquareMetersPerSecond, SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).SquareMetersPerSecond, SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(2, (KinematicViscosity.FromSquareMetersPerSecond(10)/5).SquareMetersPerSecond, SquareMetersPerSecondTolerance); - AssertEx.EqualTolerance(2, KinematicViscosity.FromSquareMetersPerSecond(10)/KinematicViscosity.FromSquareMetersPerSecond(5), SquareMetersPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - KinematicViscosity oneSquareMeterPerSecond = KinematicViscosity.FromSquareMetersPerSecond(1); - KinematicViscosity twoSquareMetersPerSecond = KinematicViscosity.FromSquareMetersPerSecond(2); - - Assert.True(oneSquareMeterPerSecond < twoSquareMetersPerSecond); - Assert.True(oneSquareMeterPerSecond <= twoSquareMetersPerSecond); - Assert.True(twoSquareMetersPerSecond > oneSquareMeterPerSecond); - Assert.True(twoSquareMetersPerSecond >= oneSquareMeterPerSecond); - - Assert.False(oneSquareMeterPerSecond > twoSquareMetersPerSecond); - Assert.False(oneSquareMeterPerSecond >= twoSquareMetersPerSecond); - Assert.False(twoSquareMetersPerSecond < oneSquareMeterPerSecond); - Assert.False(twoSquareMetersPerSecond <= oneSquareMeterPerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - KinematicViscosity squaremeterpersecond = KinematicViscosity.FromSquareMetersPerSecond(1); - Assert.Equal(0, squaremeterpersecond.CompareTo(squaremeterpersecond)); - Assert.True(squaremeterpersecond.CompareTo(KinematicViscosity.Zero) > 0); - Assert.True(KinematicViscosity.Zero.CompareTo(squaremeterpersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - KinematicViscosity squaremeterpersecond = KinematicViscosity.FromSquareMetersPerSecond(1); - Assert.Throws(() => squaremeterpersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - KinematicViscosity squaremeterpersecond = KinematicViscosity.FromSquareMetersPerSecond(1); - Assert.Throws(() => squaremeterpersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - KinematicViscosity v = KinematicViscosity.FromSquareMetersPerSecond(1); - Assert.True(v.Equals(KinematicViscosity.FromSquareMetersPerSecond(1), SquareMetersPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(KinematicViscosity.Zero, SquareMetersPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - KinematicViscosity squaremeterpersecond = KinematicViscosity.FromSquareMetersPerSecond(1); - Assert.False(squaremeterpersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - KinematicViscosity squaremeterpersecond = KinematicViscosity.FromSquareMetersPerSecond(1); - Assert.False(squaremeterpersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(KinematicViscosityUnit.Undefined, KinematicViscosity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(KinematicViscosityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == KinematicViscosityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/LapseRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/LapseRateTestsBase.g.cs deleted file mode 100644 index 58b372765f..0000000000 --- a/UnitsNet.Tests/GeneratedCode/LapseRateTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of LapseRate. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LapseRateTestsBase - { - protected abstract double DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DegreesCelciusPerKilometerTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new LapseRate((double)0.0, LapseRateUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new LapseRate(double.PositiveInfinity, LapseRateUnit.DegreeCelsiusPerKilometer)); - Assert.Throws(() => new LapseRate(double.NegativeInfinity, LapseRateUnit.DegreeCelsiusPerKilometer)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new LapseRate(double.NaN, LapseRateUnit.DegreeCelsiusPerKilometer)); - } - - [Fact] - public void DegreeCelsiusPerKilometerToLapseRateUnits() - { - LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - AssertEx.EqualTolerance(DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer, degreecelsiusperkilometer.DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, LapseRate.From(1, LapseRateUnit.DegreeCelsiusPerKilometer).DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance); - } - - [Fact] - public void FromDegreesCelciusPerKilometer_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => LapseRate.FromDegreesCelciusPerKilometer(double.PositiveInfinity)); - Assert.Throws(() => LapseRate.FromDegreesCelciusPerKilometer(double.NegativeInfinity)); - } - - [Fact] - public void FromDegreesCelciusPerKilometer_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => LapseRate.FromDegreesCelciusPerKilometer(double.NaN)); - } - - [Fact] - public void As() - { - var degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - AssertEx.EqualTolerance(DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer, degreecelsiusperkilometer.As(LapseRateUnit.DegreeCelsiusPerKilometer), DegreesCelciusPerKilometerTolerance); - } - - [Fact] - public void ToUnit() - { - var degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - - var degreecelsiusperkilometerQuantity = degreecelsiusperkilometer.ToUnit(LapseRateUnit.DegreeCelsiusPerKilometer); - AssertEx.EqualTolerance(DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer, (double)degreecelsiusperkilometerQuantity.Value, DegreesCelciusPerKilometerTolerance); - Assert.Equal(LapseRateUnit.DegreeCelsiusPerKilometer, degreecelsiusperkilometerQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - AssertEx.EqualTolerance(1, LapseRate.FromDegreesCelciusPerKilometer(degreecelsiusperkilometer.DegreesCelciusPerKilometer).DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - LapseRate v = LapseRate.FromDegreesCelciusPerKilometer(1); - AssertEx.EqualTolerance(-1, -v.DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance); - AssertEx.EqualTolerance(2, (LapseRate.FromDegreesCelciusPerKilometer(3)-v).DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance); - AssertEx.EqualTolerance(2, (v + v).DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance); - AssertEx.EqualTolerance(10, (v*10).DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance); - AssertEx.EqualTolerance(10, (10*v).DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance); - AssertEx.EqualTolerance(2, (LapseRate.FromDegreesCelciusPerKilometer(10)/5).DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance); - AssertEx.EqualTolerance(2, LapseRate.FromDegreesCelciusPerKilometer(10)/LapseRate.FromDegreesCelciusPerKilometer(5), DegreesCelciusPerKilometerTolerance); - } - - [Fact] - public void ComparisonOperators() - { - LapseRate oneDegreeCelsiusPerKilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - LapseRate twoDegreesCelciusPerKilometer = LapseRate.FromDegreesCelciusPerKilometer(2); - - Assert.True(oneDegreeCelsiusPerKilometer < twoDegreesCelciusPerKilometer); - Assert.True(oneDegreeCelsiusPerKilometer <= twoDegreesCelciusPerKilometer); - Assert.True(twoDegreesCelciusPerKilometer > oneDegreeCelsiusPerKilometer); - Assert.True(twoDegreesCelciusPerKilometer >= oneDegreeCelsiusPerKilometer); - - Assert.False(oneDegreeCelsiusPerKilometer > twoDegreesCelciusPerKilometer); - Assert.False(oneDegreeCelsiusPerKilometer >= twoDegreesCelciusPerKilometer); - Assert.False(twoDegreesCelciusPerKilometer < oneDegreeCelsiusPerKilometer); - Assert.False(twoDegreesCelciusPerKilometer <= oneDegreeCelsiusPerKilometer); - } - - [Fact] - public void CompareToIsImplemented() - { - LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - Assert.Equal(0, degreecelsiusperkilometer.CompareTo(degreecelsiusperkilometer)); - Assert.True(degreecelsiusperkilometer.CompareTo(LapseRate.Zero) > 0); - Assert.True(LapseRate.Zero.CompareTo(degreecelsiusperkilometer) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - Assert.Throws(() => degreecelsiusperkilometer.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - Assert.Throws(() => degreecelsiusperkilometer.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - LapseRate v = LapseRate.FromDegreesCelciusPerKilometer(1); - Assert.True(v.Equals(LapseRate.FromDegreesCelciusPerKilometer(1), DegreesCelciusPerKilometerTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(LapseRate.Zero, DegreesCelciusPerKilometerTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - Assert.False(degreecelsiusperkilometer.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1); - Assert.False(degreecelsiusperkilometer.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(LapseRateUnit.Undefined, LapseRate.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(LapseRateUnit)).Cast(); - foreach(var unit in units) - { - if(unit == LapseRateUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/LinearDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/LinearDensityTestsBase.g.cs deleted file mode 100644 index dc840ffffa..0000000000 --- a/UnitsNet.Tests/GeneratedCode/LinearDensityTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of LinearDensity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LinearDensityTestsBase - { - protected abstract double GramsPerMeterInOneKilogramPerMeter { get; } - protected abstract double KilogramsPerMeterInOneKilogramPerMeter { get; } - protected abstract double PoundsPerFootInOneKilogramPerMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double GramsPerMeterTolerance { get { return 1e-5; } } - protected virtual double KilogramsPerMeterTolerance { get { return 1e-5; } } - protected virtual double PoundsPerFootTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new LinearDensity((double)0.0, LinearDensityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new LinearDensity(double.PositiveInfinity, LinearDensityUnit.KilogramPerMeter)); - Assert.Throws(() => new LinearDensity(double.NegativeInfinity, LinearDensityUnit.KilogramPerMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new LinearDensity(double.NaN, LinearDensityUnit.KilogramPerMeter)); - } - - [Fact] - public void KilogramPerMeterToLinearDensityUnits() - { - LinearDensity kilogrampermeter = LinearDensity.FromKilogramsPerMeter(1); - AssertEx.EqualTolerance(GramsPerMeterInOneKilogramPerMeter, kilogrampermeter.GramsPerMeter, GramsPerMeterTolerance); - AssertEx.EqualTolerance(KilogramsPerMeterInOneKilogramPerMeter, kilogrampermeter.KilogramsPerMeter, KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(PoundsPerFootInOneKilogramPerMeter, kilogrampermeter.PoundsPerFoot, PoundsPerFootTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, LinearDensity.From(1, LinearDensityUnit.GramPerMeter).GramsPerMeter, GramsPerMeterTolerance); - AssertEx.EqualTolerance(1, LinearDensity.From(1, LinearDensityUnit.KilogramPerMeter).KilogramsPerMeter, KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(1, LinearDensity.From(1, LinearDensityUnit.PoundPerFoot).PoundsPerFoot, PoundsPerFootTolerance); - } - - [Fact] - public void FromKilogramsPerMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => LinearDensity.FromKilogramsPerMeter(double.PositiveInfinity)); - Assert.Throws(() => LinearDensity.FromKilogramsPerMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromKilogramsPerMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => LinearDensity.FromKilogramsPerMeter(double.NaN)); - } - - [Fact] - public void As() - { - var kilogrampermeter = LinearDensity.FromKilogramsPerMeter(1); - AssertEx.EqualTolerance(GramsPerMeterInOneKilogramPerMeter, kilogrampermeter.As(LinearDensityUnit.GramPerMeter), GramsPerMeterTolerance); - AssertEx.EqualTolerance(KilogramsPerMeterInOneKilogramPerMeter, kilogrampermeter.As(LinearDensityUnit.KilogramPerMeter), KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(PoundsPerFootInOneKilogramPerMeter, kilogrampermeter.As(LinearDensityUnit.PoundPerFoot), PoundsPerFootTolerance); - } - - [Fact] - public void ToUnit() - { - var kilogrampermeter = LinearDensity.FromKilogramsPerMeter(1); - - var grampermeterQuantity = kilogrampermeter.ToUnit(LinearDensityUnit.GramPerMeter); - AssertEx.EqualTolerance(GramsPerMeterInOneKilogramPerMeter, (double)grampermeterQuantity.Value, GramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.GramPerMeter, grampermeterQuantity.Unit); - - var kilogrampermeterQuantity = kilogrampermeter.ToUnit(LinearDensityUnit.KilogramPerMeter); - AssertEx.EqualTolerance(KilogramsPerMeterInOneKilogramPerMeter, (double)kilogrampermeterQuantity.Value, KilogramsPerMeterTolerance); - Assert.Equal(LinearDensityUnit.KilogramPerMeter, kilogrampermeterQuantity.Unit); - - var poundperfootQuantity = kilogrampermeter.ToUnit(LinearDensityUnit.PoundPerFoot); - AssertEx.EqualTolerance(PoundsPerFootInOneKilogramPerMeter, (double)poundperfootQuantity.Value, PoundsPerFootTolerance); - Assert.Equal(LinearDensityUnit.PoundPerFoot, poundperfootQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - LinearDensity kilogrampermeter = LinearDensity.FromKilogramsPerMeter(1); - AssertEx.EqualTolerance(1, LinearDensity.FromGramsPerMeter(kilogrampermeter.GramsPerMeter).KilogramsPerMeter, GramsPerMeterTolerance); - AssertEx.EqualTolerance(1, LinearDensity.FromKilogramsPerMeter(kilogrampermeter.KilogramsPerMeter).KilogramsPerMeter, KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(1, LinearDensity.FromPoundsPerFoot(kilogrampermeter.PoundsPerFoot).KilogramsPerMeter, PoundsPerFootTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - LinearDensity v = LinearDensity.FromKilogramsPerMeter(1); - AssertEx.EqualTolerance(-1, -v.KilogramsPerMeter, KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(2, (LinearDensity.FromKilogramsPerMeter(3)-v).KilogramsPerMeter, KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).KilogramsPerMeter, KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).KilogramsPerMeter, KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).KilogramsPerMeter, KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(2, (LinearDensity.FromKilogramsPerMeter(10)/5).KilogramsPerMeter, KilogramsPerMeterTolerance); - AssertEx.EqualTolerance(2, LinearDensity.FromKilogramsPerMeter(10)/LinearDensity.FromKilogramsPerMeter(5), KilogramsPerMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - LinearDensity oneKilogramPerMeter = LinearDensity.FromKilogramsPerMeter(1); - LinearDensity twoKilogramsPerMeter = LinearDensity.FromKilogramsPerMeter(2); - - Assert.True(oneKilogramPerMeter < twoKilogramsPerMeter); - Assert.True(oneKilogramPerMeter <= twoKilogramsPerMeter); - Assert.True(twoKilogramsPerMeter > oneKilogramPerMeter); - Assert.True(twoKilogramsPerMeter >= oneKilogramPerMeter); - - Assert.False(oneKilogramPerMeter > twoKilogramsPerMeter); - Assert.False(oneKilogramPerMeter >= twoKilogramsPerMeter); - Assert.False(twoKilogramsPerMeter < oneKilogramPerMeter); - Assert.False(twoKilogramsPerMeter <= oneKilogramPerMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - LinearDensity kilogrampermeter = LinearDensity.FromKilogramsPerMeter(1); - Assert.Equal(0, kilogrampermeter.CompareTo(kilogrampermeter)); - Assert.True(kilogrampermeter.CompareTo(LinearDensity.Zero) > 0); - Assert.True(LinearDensity.Zero.CompareTo(kilogrampermeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - LinearDensity kilogrampermeter = LinearDensity.FromKilogramsPerMeter(1); - Assert.Throws(() => kilogrampermeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - LinearDensity kilogrampermeter = LinearDensity.FromKilogramsPerMeter(1); - Assert.Throws(() => kilogrampermeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - LinearDensity v = LinearDensity.FromKilogramsPerMeter(1); - Assert.True(v.Equals(LinearDensity.FromKilogramsPerMeter(1), KilogramsPerMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(LinearDensity.Zero, KilogramsPerMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - LinearDensity kilogrampermeter = LinearDensity.FromKilogramsPerMeter(1); - Assert.False(kilogrampermeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - LinearDensity kilogrampermeter = LinearDensity.FromKilogramsPerMeter(1); - Assert.False(kilogrampermeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(LinearDensityUnit.Undefined, LinearDensity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(LinearDensityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == LinearDensityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/LuminousFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/LuminousFluxTestsBase.g.cs deleted file mode 100644 index dbda252867..0000000000 --- a/UnitsNet.Tests/GeneratedCode/LuminousFluxTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of LuminousFlux. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LuminousFluxTestsBase - { - protected abstract double LumensInOneLumen { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double LumensTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new LuminousFlux((double)0.0, LuminousFluxUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new LuminousFlux(double.PositiveInfinity, LuminousFluxUnit.Lumen)); - Assert.Throws(() => new LuminousFlux(double.NegativeInfinity, LuminousFluxUnit.Lumen)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new LuminousFlux(double.NaN, LuminousFluxUnit.Lumen)); - } - - [Fact] - public void LumenToLuminousFluxUnits() - { - LuminousFlux lumen = LuminousFlux.FromLumens(1); - AssertEx.EqualTolerance(LumensInOneLumen, lumen.Lumens, LumensTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, LuminousFlux.From(1, LuminousFluxUnit.Lumen).Lumens, LumensTolerance); - } - - [Fact] - public void FromLumens_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => LuminousFlux.FromLumens(double.PositiveInfinity)); - Assert.Throws(() => LuminousFlux.FromLumens(double.NegativeInfinity)); - } - - [Fact] - public void FromLumens_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => LuminousFlux.FromLumens(double.NaN)); - } - - [Fact] - public void As() - { - var lumen = LuminousFlux.FromLumens(1); - AssertEx.EqualTolerance(LumensInOneLumen, lumen.As(LuminousFluxUnit.Lumen), LumensTolerance); - } - - [Fact] - public void ToUnit() - { - var lumen = LuminousFlux.FromLumens(1); - - var lumenQuantity = lumen.ToUnit(LuminousFluxUnit.Lumen); - AssertEx.EqualTolerance(LumensInOneLumen, (double)lumenQuantity.Value, LumensTolerance); - Assert.Equal(LuminousFluxUnit.Lumen, lumenQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - LuminousFlux lumen = LuminousFlux.FromLumens(1); - AssertEx.EqualTolerance(1, LuminousFlux.FromLumens(lumen.Lumens).Lumens, LumensTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - LuminousFlux v = LuminousFlux.FromLumens(1); - AssertEx.EqualTolerance(-1, -v.Lumens, LumensTolerance); - AssertEx.EqualTolerance(2, (LuminousFlux.FromLumens(3)-v).Lumens, LumensTolerance); - AssertEx.EqualTolerance(2, (v + v).Lumens, LumensTolerance); - AssertEx.EqualTolerance(10, (v*10).Lumens, LumensTolerance); - AssertEx.EqualTolerance(10, (10*v).Lumens, LumensTolerance); - AssertEx.EqualTolerance(2, (LuminousFlux.FromLumens(10)/5).Lumens, LumensTolerance); - AssertEx.EqualTolerance(2, LuminousFlux.FromLumens(10)/LuminousFlux.FromLumens(5), LumensTolerance); - } - - [Fact] - public void ComparisonOperators() - { - LuminousFlux oneLumen = LuminousFlux.FromLumens(1); - LuminousFlux twoLumens = LuminousFlux.FromLumens(2); - - Assert.True(oneLumen < twoLumens); - Assert.True(oneLumen <= twoLumens); - Assert.True(twoLumens > oneLumen); - Assert.True(twoLumens >= oneLumen); - - Assert.False(oneLumen > twoLumens); - Assert.False(oneLumen >= twoLumens); - Assert.False(twoLumens < oneLumen); - Assert.False(twoLumens <= oneLumen); - } - - [Fact] - public void CompareToIsImplemented() - { - LuminousFlux lumen = LuminousFlux.FromLumens(1); - Assert.Equal(0, lumen.CompareTo(lumen)); - Assert.True(lumen.CompareTo(LuminousFlux.Zero) > 0); - Assert.True(LuminousFlux.Zero.CompareTo(lumen) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - LuminousFlux lumen = LuminousFlux.FromLumens(1); - Assert.Throws(() => lumen.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - LuminousFlux lumen = LuminousFlux.FromLumens(1); - Assert.Throws(() => lumen.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - LuminousFlux v = LuminousFlux.FromLumens(1); - Assert.True(v.Equals(LuminousFlux.FromLumens(1), LumensTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(LuminousFlux.Zero, LumensTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - LuminousFlux lumen = LuminousFlux.FromLumens(1); - Assert.False(lumen.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - LuminousFlux lumen = LuminousFlux.FromLumens(1); - Assert.False(lumen.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(LuminousFluxUnit.Undefined, LuminousFlux.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(LuminousFluxUnit)).Cast(); - foreach(var unit in units) - { - if(unit == LuminousFluxUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/LuminousIntensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/LuminousIntensityTestsBase.g.cs deleted file mode 100644 index c2148222b4..0000000000 --- a/UnitsNet.Tests/GeneratedCode/LuminousIntensityTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of LuminousIntensity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LuminousIntensityTestsBase - { - protected abstract double CandelaInOneCandela { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CandelaTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new LuminousIntensity((double)0.0, LuminousIntensityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new LuminousIntensity(double.PositiveInfinity, LuminousIntensityUnit.Candela)); - Assert.Throws(() => new LuminousIntensity(double.NegativeInfinity, LuminousIntensityUnit.Candela)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new LuminousIntensity(double.NaN, LuminousIntensityUnit.Candela)); - } - - [Fact] - public void CandelaToLuminousIntensityUnits() - { - LuminousIntensity candela = LuminousIntensity.FromCandela(1); - AssertEx.EqualTolerance(CandelaInOneCandela, candela.Candela, CandelaTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, LuminousIntensity.From(1, LuminousIntensityUnit.Candela).Candela, CandelaTolerance); - } - - [Fact] - public void FromCandela_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => LuminousIntensity.FromCandela(double.PositiveInfinity)); - Assert.Throws(() => LuminousIntensity.FromCandela(double.NegativeInfinity)); - } - - [Fact] - public void FromCandela_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => LuminousIntensity.FromCandela(double.NaN)); - } - - [Fact] - public void As() - { - var candela = LuminousIntensity.FromCandela(1); - AssertEx.EqualTolerance(CandelaInOneCandela, candela.As(LuminousIntensityUnit.Candela), CandelaTolerance); - } - - [Fact] - public void ToUnit() - { - var candela = LuminousIntensity.FromCandela(1); - - var candelaQuantity = candela.ToUnit(LuminousIntensityUnit.Candela); - AssertEx.EqualTolerance(CandelaInOneCandela, (double)candelaQuantity.Value, CandelaTolerance); - Assert.Equal(LuminousIntensityUnit.Candela, candelaQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - LuminousIntensity candela = LuminousIntensity.FromCandela(1); - AssertEx.EqualTolerance(1, LuminousIntensity.FromCandela(candela.Candela).Candela, CandelaTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - LuminousIntensity v = LuminousIntensity.FromCandela(1); - AssertEx.EqualTolerance(-1, -v.Candela, CandelaTolerance); - AssertEx.EqualTolerance(2, (LuminousIntensity.FromCandela(3)-v).Candela, CandelaTolerance); - AssertEx.EqualTolerance(2, (v + v).Candela, CandelaTolerance); - AssertEx.EqualTolerance(10, (v*10).Candela, CandelaTolerance); - AssertEx.EqualTolerance(10, (10*v).Candela, CandelaTolerance); - AssertEx.EqualTolerance(2, (LuminousIntensity.FromCandela(10)/5).Candela, CandelaTolerance); - AssertEx.EqualTolerance(2, LuminousIntensity.FromCandela(10)/LuminousIntensity.FromCandela(5), CandelaTolerance); - } - - [Fact] - public void ComparisonOperators() - { - LuminousIntensity oneCandela = LuminousIntensity.FromCandela(1); - LuminousIntensity twoCandela = LuminousIntensity.FromCandela(2); - - Assert.True(oneCandela < twoCandela); - Assert.True(oneCandela <= twoCandela); - Assert.True(twoCandela > oneCandela); - Assert.True(twoCandela >= oneCandela); - - Assert.False(oneCandela > twoCandela); - Assert.False(oneCandela >= twoCandela); - Assert.False(twoCandela < oneCandela); - Assert.False(twoCandela <= oneCandela); - } - - [Fact] - public void CompareToIsImplemented() - { - LuminousIntensity candela = LuminousIntensity.FromCandela(1); - Assert.Equal(0, candela.CompareTo(candela)); - Assert.True(candela.CompareTo(LuminousIntensity.Zero) > 0); - Assert.True(LuminousIntensity.Zero.CompareTo(candela) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - LuminousIntensity candela = LuminousIntensity.FromCandela(1); - Assert.Throws(() => candela.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - LuminousIntensity candela = LuminousIntensity.FromCandela(1); - Assert.Throws(() => candela.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - LuminousIntensity v = LuminousIntensity.FromCandela(1); - Assert.True(v.Equals(LuminousIntensity.FromCandela(1), CandelaTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(LuminousIntensity.Zero, CandelaTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - LuminousIntensity candela = LuminousIntensity.FromCandela(1); - Assert.False(candela.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - LuminousIntensity candela = LuminousIntensity.FromCandela(1); - Assert.False(candela.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(LuminousIntensityUnit.Undefined, LuminousIntensity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(LuminousIntensityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == LuminousIntensityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MagneticFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MagneticFieldTestsBase.g.cs deleted file mode 100644 index 583899910f..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MagneticFieldTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of MagneticField. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MagneticFieldTestsBase - { - protected abstract double TeslasInOneTesla { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double TeslasTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new MagneticField((double)0.0, MagneticFieldUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new MagneticField(double.PositiveInfinity, MagneticFieldUnit.Tesla)); - Assert.Throws(() => new MagneticField(double.NegativeInfinity, MagneticFieldUnit.Tesla)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new MagneticField(double.NaN, MagneticFieldUnit.Tesla)); - } - - [Fact] - public void TeslaToMagneticFieldUnits() - { - MagneticField tesla = MagneticField.FromTeslas(1); - AssertEx.EqualTolerance(TeslasInOneTesla, tesla.Teslas, TeslasTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, MagneticField.From(1, MagneticFieldUnit.Tesla).Teslas, TeslasTolerance); - } - - [Fact] - public void FromTeslas_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => MagneticField.FromTeslas(double.PositiveInfinity)); - Assert.Throws(() => MagneticField.FromTeslas(double.NegativeInfinity)); - } - - [Fact] - public void FromTeslas_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => MagneticField.FromTeslas(double.NaN)); - } - - [Fact] - public void As() - { - var tesla = MagneticField.FromTeslas(1); - AssertEx.EqualTolerance(TeslasInOneTesla, tesla.As(MagneticFieldUnit.Tesla), TeslasTolerance); - } - - [Fact] - public void ToUnit() - { - var tesla = MagneticField.FromTeslas(1); - - var teslaQuantity = tesla.ToUnit(MagneticFieldUnit.Tesla); - AssertEx.EqualTolerance(TeslasInOneTesla, (double)teslaQuantity.Value, TeslasTolerance); - Assert.Equal(MagneticFieldUnit.Tesla, teslaQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - MagneticField tesla = MagneticField.FromTeslas(1); - AssertEx.EqualTolerance(1, MagneticField.FromTeslas(tesla.Teslas).Teslas, TeslasTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - MagneticField v = MagneticField.FromTeslas(1); - AssertEx.EqualTolerance(-1, -v.Teslas, TeslasTolerance); - AssertEx.EqualTolerance(2, (MagneticField.FromTeslas(3)-v).Teslas, TeslasTolerance); - AssertEx.EqualTolerance(2, (v + v).Teslas, TeslasTolerance); - AssertEx.EqualTolerance(10, (v*10).Teslas, TeslasTolerance); - AssertEx.EqualTolerance(10, (10*v).Teslas, TeslasTolerance); - AssertEx.EqualTolerance(2, (MagneticField.FromTeslas(10)/5).Teslas, TeslasTolerance); - AssertEx.EqualTolerance(2, MagneticField.FromTeslas(10)/MagneticField.FromTeslas(5), TeslasTolerance); - } - - [Fact] - public void ComparisonOperators() - { - MagneticField oneTesla = MagneticField.FromTeslas(1); - MagneticField twoTeslas = MagneticField.FromTeslas(2); - - Assert.True(oneTesla < twoTeslas); - Assert.True(oneTesla <= twoTeslas); - Assert.True(twoTeslas > oneTesla); - Assert.True(twoTeslas >= oneTesla); - - Assert.False(oneTesla > twoTeslas); - Assert.False(oneTesla >= twoTeslas); - Assert.False(twoTeslas < oneTesla); - Assert.False(twoTeslas <= oneTesla); - } - - [Fact] - public void CompareToIsImplemented() - { - MagneticField tesla = MagneticField.FromTeslas(1); - Assert.Equal(0, tesla.CompareTo(tesla)); - Assert.True(tesla.CompareTo(MagneticField.Zero) > 0); - Assert.True(MagneticField.Zero.CompareTo(tesla) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - MagneticField tesla = MagneticField.FromTeslas(1); - Assert.Throws(() => tesla.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - MagneticField tesla = MagneticField.FromTeslas(1); - Assert.Throws(() => tesla.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - MagneticField v = MagneticField.FromTeslas(1); - Assert.True(v.Equals(MagneticField.FromTeslas(1), TeslasTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(MagneticField.Zero, TeslasTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - MagneticField tesla = MagneticField.FromTeslas(1); - Assert.False(tesla.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - MagneticField tesla = MagneticField.FromTeslas(1); - Assert.False(tesla.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MagneticFieldUnit.Undefined, MagneticField.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MagneticFieldUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MagneticFieldUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MagneticFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MagneticFluxTestsBase.g.cs deleted file mode 100644 index ccdfe5ce08..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MagneticFluxTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of MagneticFlux. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MagneticFluxTestsBase - { - protected abstract double WebersInOneWeber { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double WebersTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new MagneticFlux((double)0.0, MagneticFluxUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new MagneticFlux(double.PositiveInfinity, MagneticFluxUnit.Weber)); - Assert.Throws(() => new MagneticFlux(double.NegativeInfinity, MagneticFluxUnit.Weber)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new MagneticFlux(double.NaN, MagneticFluxUnit.Weber)); - } - - [Fact] - public void WeberToMagneticFluxUnits() - { - MagneticFlux weber = MagneticFlux.FromWebers(1); - AssertEx.EqualTolerance(WebersInOneWeber, weber.Webers, WebersTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, MagneticFlux.From(1, MagneticFluxUnit.Weber).Webers, WebersTolerance); - } - - [Fact] - public void FromWebers_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => MagneticFlux.FromWebers(double.PositiveInfinity)); - Assert.Throws(() => MagneticFlux.FromWebers(double.NegativeInfinity)); - } - - [Fact] - public void FromWebers_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => MagneticFlux.FromWebers(double.NaN)); - } - - [Fact] - public void As() - { - var weber = MagneticFlux.FromWebers(1); - AssertEx.EqualTolerance(WebersInOneWeber, weber.As(MagneticFluxUnit.Weber), WebersTolerance); - } - - [Fact] - public void ToUnit() - { - var weber = MagneticFlux.FromWebers(1); - - var weberQuantity = weber.ToUnit(MagneticFluxUnit.Weber); - AssertEx.EqualTolerance(WebersInOneWeber, (double)weberQuantity.Value, WebersTolerance); - Assert.Equal(MagneticFluxUnit.Weber, weberQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - MagneticFlux weber = MagneticFlux.FromWebers(1); - AssertEx.EqualTolerance(1, MagneticFlux.FromWebers(weber.Webers).Webers, WebersTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - MagneticFlux v = MagneticFlux.FromWebers(1); - AssertEx.EqualTolerance(-1, -v.Webers, WebersTolerance); - AssertEx.EqualTolerance(2, (MagneticFlux.FromWebers(3)-v).Webers, WebersTolerance); - AssertEx.EqualTolerance(2, (v + v).Webers, WebersTolerance); - AssertEx.EqualTolerance(10, (v*10).Webers, WebersTolerance); - AssertEx.EqualTolerance(10, (10*v).Webers, WebersTolerance); - AssertEx.EqualTolerance(2, (MagneticFlux.FromWebers(10)/5).Webers, WebersTolerance); - AssertEx.EqualTolerance(2, MagneticFlux.FromWebers(10)/MagneticFlux.FromWebers(5), WebersTolerance); - } - - [Fact] - public void ComparisonOperators() - { - MagneticFlux oneWeber = MagneticFlux.FromWebers(1); - MagneticFlux twoWebers = MagneticFlux.FromWebers(2); - - Assert.True(oneWeber < twoWebers); - Assert.True(oneWeber <= twoWebers); - Assert.True(twoWebers > oneWeber); - Assert.True(twoWebers >= oneWeber); - - Assert.False(oneWeber > twoWebers); - Assert.False(oneWeber >= twoWebers); - Assert.False(twoWebers < oneWeber); - Assert.False(twoWebers <= oneWeber); - } - - [Fact] - public void CompareToIsImplemented() - { - MagneticFlux weber = MagneticFlux.FromWebers(1); - Assert.Equal(0, weber.CompareTo(weber)); - Assert.True(weber.CompareTo(MagneticFlux.Zero) > 0); - Assert.True(MagneticFlux.Zero.CompareTo(weber) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - MagneticFlux weber = MagneticFlux.FromWebers(1); - Assert.Throws(() => weber.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - MagneticFlux weber = MagneticFlux.FromWebers(1); - Assert.Throws(() => weber.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - MagneticFlux v = MagneticFlux.FromWebers(1); - Assert.True(v.Equals(MagneticFlux.FromWebers(1), WebersTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(MagneticFlux.Zero, WebersTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - MagneticFlux weber = MagneticFlux.FromWebers(1); - Assert.False(weber.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - MagneticFlux weber = MagneticFlux.FromWebers(1); - Assert.False(weber.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MagneticFluxUnit.Undefined, MagneticFlux.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MagneticFluxUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MagneticFluxUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MagnetizationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MagnetizationTestsBase.g.cs deleted file mode 100644 index f6c59a23fd..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MagnetizationTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Magnetization. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MagnetizationTestsBase - { - protected abstract double AmperesPerMeterInOneAmperePerMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double AmperesPerMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Magnetization((double)0.0, MagnetizationUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Magnetization(double.PositiveInfinity, MagnetizationUnit.AmperePerMeter)); - Assert.Throws(() => new Magnetization(double.NegativeInfinity, MagnetizationUnit.AmperePerMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Magnetization(double.NaN, MagnetizationUnit.AmperePerMeter)); - } - - [Fact] - public void AmperePerMeterToMagnetizationUnits() - { - Magnetization amperepermeter = Magnetization.FromAmperesPerMeter(1); - AssertEx.EqualTolerance(AmperesPerMeterInOneAmperePerMeter, amperepermeter.AmperesPerMeter, AmperesPerMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Magnetization.From(1, MagnetizationUnit.AmperePerMeter).AmperesPerMeter, AmperesPerMeterTolerance); - } - - [Fact] - public void FromAmperesPerMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Magnetization.FromAmperesPerMeter(double.PositiveInfinity)); - Assert.Throws(() => Magnetization.FromAmperesPerMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromAmperesPerMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Magnetization.FromAmperesPerMeter(double.NaN)); - } - - [Fact] - public void As() - { - var amperepermeter = Magnetization.FromAmperesPerMeter(1); - AssertEx.EqualTolerance(AmperesPerMeterInOneAmperePerMeter, amperepermeter.As(MagnetizationUnit.AmperePerMeter), AmperesPerMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var amperepermeter = Magnetization.FromAmperesPerMeter(1); - - var amperepermeterQuantity = amperepermeter.ToUnit(MagnetizationUnit.AmperePerMeter); - AssertEx.EqualTolerance(AmperesPerMeterInOneAmperePerMeter, (double)amperepermeterQuantity.Value, AmperesPerMeterTolerance); - Assert.Equal(MagnetizationUnit.AmperePerMeter, amperepermeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Magnetization amperepermeter = Magnetization.FromAmperesPerMeter(1); - AssertEx.EqualTolerance(1, Magnetization.FromAmperesPerMeter(amperepermeter.AmperesPerMeter).AmperesPerMeter, AmperesPerMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Magnetization v = Magnetization.FromAmperesPerMeter(1); - AssertEx.EqualTolerance(-1, -v.AmperesPerMeter, AmperesPerMeterTolerance); - AssertEx.EqualTolerance(2, (Magnetization.FromAmperesPerMeter(3)-v).AmperesPerMeter, AmperesPerMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).AmperesPerMeter, AmperesPerMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).AmperesPerMeter, AmperesPerMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).AmperesPerMeter, AmperesPerMeterTolerance); - AssertEx.EqualTolerance(2, (Magnetization.FromAmperesPerMeter(10)/5).AmperesPerMeter, AmperesPerMeterTolerance); - AssertEx.EqualTolerance(2, Magnetization.FromAmperesPerMeter(10)/Magnetization.FromAmperesPerMeter(5), AmperesPerMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Magnetization oneAmperePerMeter = Magnetization.FromAmperesPerMeter(1); - Magnetization twoAmperesPerMeter = Magnetization.FromAmperesPerMeter(2); - - Assert.True(oneAmperePerMeter < twoAmperesPerMeter); - Assert.True(oneAmperePerMeter <= twoAmperesPerMeter); - Assert.True(twoAmperesPerMeter > oneAmperePerMeter); - Assert.True(twoAmperesPerMeter >= oneAmperePerMeter); - - Assert.False(oneAmperePerMeter > twoAmperesPerMeter); - Assert.False(oneAmperePerMeter >= twoAmperesPerMeter); - Assert.False(twoAmperesPerMeter < oneAmperePerMeter); - Assert.False(twoAmperesPerMeter <= oneAmperePerMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Magnetization amperepermeter = Magnetization.FromAmperesPerMeter(1); - Assert.Equal(0, amperepermeter.CompareTo(amperepermeter)); - Assert.True(amperepermeter.CompareTo(Magnetization.Zero) > 0); - Assert.True(Magnetization.Zero.CompareTo(amperepermeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Magnetization amperepermeter = Magnetization.FromAmperesPerMeter(1); - Assert.Throws(() => amperepermeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Magnetization amperepermeter = Magnetization.FromAmperesPerMeter(1); - Assert.Throws(() => amperepermeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Magnetization v = Magnetization.FromAmperesPerMeter(1); - Assert.True(v.Equals(Magnetization.FromAmperesPerMeter(1), AmperesPerMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Magnetization.Zero, AmperesPerMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Magnetization amperepermeter = Magnetization.FromAmperesPerMeter(1); - Assert.False(amperepermeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Magnetization amperepermeter = Magnetization.FromAmperesPerMeter(1); - Assert.False(amperepermeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MagnetizationUnit.Undefined, Magnetization.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MagnetizationUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MagnetizationUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MassFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MassFlowTestsBase.g.cs deleted file mode 100644 index 5cc46b5239..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MassFlowTestsBase.g.cs +++ /dev/null @@ -1,364 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of MassFlow. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassFlowTestsBase - { - protected abstract double CentigramsPerSecondInOneGramPerSecond { get; } - protected abstract double DecagramsPerSecondInOneGramPerSecond { get; } - protected abstract double DecigramsPerSecondInOneGramPerSecond { get; } - protected abstract double GramsPerSecondInOneGramPerSecond { get; } - protected abstract double HectogramsPerSecondInOneGramPerSecond { get; } - protected abstract double KilogramsPerHourInOneGramPerSecond { get; } - protected abstract double KilogramsPerSecondInOneGramPerSecond { get; } - protected abstract double MegapoundsPerHourInOneGramPerSecond { get; } - protected abstract double MicrogramsPerSecondInOneGramPerSecond { get; } - protected abstract double MilligramsPerSecondInOneGramPerSecond { get; } - protected abstract double NanogramsPerSecondInOneGramPerSecond { get; } - protected abstract double PoundsPerHourInOneGramPerSecond { get; } - protected abstract double ShortTonsPerHourInOneGramPerSecond { get; } - protected abstract double TonnesPerDayInOneGramPerSecond { get; } - protected abstract double TonnesPerHourInOneGramPerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentigramsPerSecondTolerance { get { return 1e-5; } } - protected virtual double DecagramsPerSecondTolerance { get { return 1e-5; } } - protected virtual double DecigramsPerSecondTolerance { get { return 1e-5; } } - protected virtual double GramsPerSecondTolerance { get { return 1e-5; } } - protected virtual double HectogramsPerSecondTolerance { get { return 1e-5; } } - protected virtual double KilogramsPerHourTolerance { get { return 1e-5; } } - protected virtual double KilogramsPerSecondTolerance { get { return 1e-5; } } - protected virtual double MegapoundsPerHourTolerance { get { return 1e-5; } } - protected virtual double MicrogramsPerSecondTolerance { get { return 1e-5; } } - protected virtual double MilligramsPerSecondTolerance { get { return 1e-5; } } - protected virtual double NanogramsPerSecondTolerance { get { return 1e-5; } } - protected virtual double PoundsPerHourTolerance { get { return 1e-5; } } - protected virtual double ShortTonsPerHourTolerance { get { return 1e-5; } } - protected virtual double TonnesPerDayTolerance { get { return 1e-5; } } - protected virtual double TonnesPerHourTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new MassFlow((double)0.0, MassFlowUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new MassFlow(double.PositiveInfinity, MassFlowUnit.GramPerSecond)); - Assert.Throws(() => new MassFlow(double.NegativeInfinity, MassFlowUnit.GramPerSecond)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new MassFlow(double.NaN, MassFlowUnit.GramPerSecond)); - } - - [Fact] - public void GramPerSecondToMassFlowUnits() - { - MassFlow grampersecond = MassFlow.FromGramsPerSecond(1); - AssertEx.EqualTolerance(CentigramsPerSecondInOneGramPerSecond, grampersecond.CentigramsPerSecond, CentigramsPerSecondTolerance); - AssertEx.EqualTolerance(DecagramsPerSecondInOneGramPerSecond, grampersecond.DecagramsPerSecond, DecagramsPerSecondTolerance); - AssertEx.EqualTolerance(DecigramsPerSecondInOneGramPerSecond, grampersecond.DecigramsPerSecond, DecigramsPerSecondTolerance); - AssertEx.EqualTolerance(GramsPerSecondInOneGramPerSecond, grampersecond.GramsPerSecond, GramsPerSecondTolerance); - AssertEx.EqualTolerance(HectogramsPerSecondInOneGramPerSecond, grampersecond.HectogramsPerSecond, HectogramsPerSecondTolerance); - AssertEx.EqualTolerance(KilogramsPerHourInOneGramPerSecond, grampersecond.KilogramsPerHour, KilogramsPerHourTolerance); - AssertEx.EqualTolerance(KilogramsPerSecondInOneGramPerSecond, grampersecond.KilogramsPerSecond, KilogramsPerSecondTolerance); - AssertEx.EqualTolerance(MegapoundsPerHourInOneGramPerSecond, grampersecond.MegapoundsPerHour, MegapoundsPerHourTolerance); - AssertEx.EqualTolerance(MicrogramsPerSecondInOneGramPerSecond, grampersecond.MicrogramsPerSecond, MicrogramsPerSecondTolerance); - AssertEx.EqualTolerance(MilligramsPerSecondInOneGramPerSecond, grampersecond.MilligramsPerSecond, MilligramsPerSecondTolerance); - AssertEx.EqualTolerance(NanogramsPerSecondInOneGramPerSecond, grampersecond.NanogramsPerSecond, NanogramsPerSecondTolerance); - AssertEx.EqualTolerance(PoundsPerHourInOneGramPerSecond, grampersecond.PoundsPerHour, PoundsPerHourTolerance); - AssertEx.EqualTolerance(ShortTonsPerHourInOneGramPerSecond, grampersecond.ShortTonsPerHour, ShortTonsPerHourTolerance); - AssertEx.EqualTolerance(TonnesPerDayInOneGramPerSecond, grampersecond.TonnesPerDay, TonnesPerDayTolerance); - AssertEx.EqualTolerance(TonnesPerHourInOneGramPerSecond, grampersecond.TonnesPerHour, TonnesPerHourTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.CentigramPerSecond).CentigramsPerSecond, CentigramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.DecagramPerSecond).DecagramsPerSecond, DecagramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.DecigramPerSecond).DecigramsPerSecond, DecigramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.GramPerSecond).GramsPerSecond, GramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.HectogramPerSecond).HectogramsPerSecond, HectogramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.KilogramPerHour).KilogramsPerHour, KilogramsPerHourTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.KilogramPerSecond).KilogramsPerSecond, KilogramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.MegapoundPerHour).MegapoundsPerHour, MegapoundsPerHourTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.MicrogramPerSecond).MicrogramsPerSecond, MicrogramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.MilligramPerSecond).MilligramsPerSecond, MilligramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.NanogramPerSecond).NanogramsPerSecond, NanogramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.PoundPerHour).PoundsPerHour, PoundsPerHourTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.ShortTonPerHour).ShortTonsPerHour, ShortTonsPerHourTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.TonnePerDay).TonnesPerDay, TonnesPerDayTolerance); - AssertEx.EqualTolerance(1, MassFlow.From(1, MassFlowUnit.TonnePerHour).TonnesPerHour, TonnesPerHourTolerance); - } - - [Fact] - public void FromGramsPerSecond_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => MassFlow.FromGramsPerSecond(double.PositiveInfinity)); - Assert.Throws(() => MassFlow.FromGramsPerSecond(double.NegativeInfinity)); - } - - [Fact] - public void FromGramsPerSecond_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => MassFlow.FromGramsPerSecond(double.NaN)); - } - - [Fact] - public void As() - { - var grampersecond = MassFlow.FromGramsPerSecond(1); - AssertEx.EqualTolerance(CentigramsPerSecondInOneGramPerSecond, grampersecond.As(MassFlowUnit.CentigramPerSecond), CentigramsPerSecondTolerance); - AssertEx.EqualTolerance(DecagramsPerSecondInOneGramPerSecond, grampersecond.As(MassFlowUnit.DecagramPerSecond), DecagramsPerSecondTolerance); - AssertEx.EqualTolerance(DecigramsPerSecondInOneGramPerSecond, grampersecond.As(MassFlowUnit.DecigramPerSecond), DecigramsPerSecondTolerance); - AssertEx.EqualTolerance(GramsPerSecondInOneGramPerSecond, grampersecond.As(MassFlowUnit.GramPerSecond), GramsPerSecondTolerance); - AssertEx.EqualTolerance(HectogramsPerSecondInOneGramPerSecond, grampersecond.As(MassFlowUnit.HectogramPerSecond), HectogramsPerSecondTolerance); - AssertEx.EqualTolerance(KilogramsPerHourInOneGramPerSecond, grampersecond.As(MassFlowUnit.KilogramPerHour), KilogramsPerHourTolerance); - AssertEx.EqualTolerance(KilogramsPerSecondInOneGramPerSecond, grampersecond.As(MassFlowUnit.KilogramPerSecond), KilogramsPerSecondTolerance); - AssertEx.EqualTolerance(MegapoundsPerHourInOneGramPerSecond, grampersecond.As(MassFlowUnit.MegapoundPerHour), MegapoundsPerHourTolerance); - AssertEx.EqualTolerance(MicrogramsPerSecondInOneGramPerSecond, grampersecond.As(MassFlowUnit.MicrogramPerSecond), MicrogramsPerSecondTolerance); - AssertEx.EqualTolerance(MilligramsPerSecondInOneGramPerSecond, grampersecond.As(MassFlowUnit.MilligramPerSecond), MilligramsPerSecondTolerance); - AssertEx.EqualTolerance(NanogramsPerSecondInOneGramPerSecond, grampersecond.As(MassFlowUnit.NanogramPerSecond), NanogramsPerSecondTolerance); - AssertEx.EqualTolerance(PoundsPerHourInOneGramPerSecond, grampersecond.As(MassFlowUnit.PoundPerHour), PoundsPerHourTolerance); - AssertEx.EqualTolerance(ShortTonsPerHourInOneGramPerSecond, grampersecond.As(MassFlowUnit.ShortTonPerHour), ShortTonsPerHourTolerance); - AssertEx.EqualTolerance(TonnesPerDayInOneGramPerSecond, grampersecond.As(MassFlowUnit.TonnePerDay), TonnesPerDayTolerance); - AssertEx.EqualTolerance(TonnesPerHourInOneGramPerSecond, grampersecond.As(MassFlowUnit.TonnePerHour), TonnesPerHourTolerance); - } - - [Fact] - public void ToUnit() - { - var grampersecond = MassFlow.FromGramsPerSecond(1); - - var centigrampersecondQuantity = grampersecond.ToUnit(MassFlowUnit.CentigramPerSecond); - AssertEx.EqualTolerance(CentigramsPerSecondInOneGramPerSecond, (double)centigrampersecondQuantity.Value, CentigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.CentigramPerSecond, centigrampersecondQuantity.Unit); - - var decagrampersecondQuantity = grampersecond.ToUnit(MassFlowUnit.DecagramPerSecond); - AssertEx.EqualTolerance(DecagramsPerSecondInOneGramPerSecond, (double)decagrampersecondQuantity.Value, DecagramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecagramPerSecond, decagrampersecondQuantity.Unit); - - var decigrampersecondQuantity = grampersecond.ToUnit(MassFlowUnit.DecigramPerSecond); - AssertEx.EqualTolerance(DecigramsPerSecondInOneGramPerSecond, (double)decigrampersecondQuantity.Value, DecigramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.DecigramPerSecond, decigrampersecondQuantity.Unit); - - var grampersecondQuantity = grampersecond.ToUnit(MassFlowUnit.GramPerSecond); - AssertEx.EqualTolerance(GramsPerSecondInOneGramPerSecond, (double)grampersecondQuantity.Value, GramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.GramPerSecond, grampersecondQuantity.Unit); - - var hectogrampersecondQuantity = grampersecond.ToUnit(MassFlowUnit.HectogramPerSecond); - AssertEx.EqualTolerance(HectogramsPerSecondInOneGramPerSecond, (double)hectogrampersecondQuantity.Value, HectogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.HectogramPerSecond, hectogrampersecondQuantity.Unit); - - var kilogramperhourQuantity = grampersecond.ToUnit(MassFlowUnit.KilogramPerHour); - AssertEx.EqualTolerance(KilogramsPerHourInOneGramPerSecond, (double)kilogramperhourQuantity.Value, KilogramsPerHourTolerance); - Assert.Equal(MassFlowUnit.KilogramPerHour, kilogramperhourQuantity.Unit); - - var kilogrampersecondQuantity = grampersecond.ToUnit(MassFlowUnit.KilogramPerSecond); - AssertEx.EqualTolerance(KilogramsPerSecondInOneGramPerSecond, (double)kilogrampersecondQuantity.Value, KilogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.KilogramPerSecond, kilogrampersecondQuantity.Unit); - - var megapoundperhourQuantity = grampersecond.ToUnit(MassFlowUnit.MegapoundPerHour); - AssertEx.EqualTolerance(MegapoundsPerHourInOneGramPerSecond, (double)megapoundperhourQuantity.Value, MegapoundsPerHourTolerance); - Assert.Equal(MassFlowUnit.MegapoundPerHour, megapoundperhourQuantity.Unit); - - var microgrampersecondQuantity = grampersecond.ToUnit(MassFlowUnit.MicrogramPerSecond); - AssertEx.EqualTolerance(MicrogramsPerSecondInOneGramPerSecond, (double)microgrampersecondQuantity.Value, MicrogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MicrogramPerSecond, microgrampersecondQuantity.Unit); - - var milligrampersecondQuantity = grampersecond.ToUnit(MassFlowUnit.MilligramPerSecond); - AssertEx.EqualTolerance(MilligramsPerSecondInOneGramPerSecond, (double)milligrampersecondQuantity.Value, MilligramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.MilligramPerSecond, milligrampersecondQuantity.Unit); - - var nanogrampersecondQuantity = grampersecond.ToUnit(MassFlowUnit.NanogramPerSecond); - AssertEx.EqualTolerance(NanogramsPerSecondInOneGramPerSecond, (double)nanogrampersecondQuantity.Value, NanogramsPerSecondTolerance); - Assert.Equal(MassFlowUnit.NanogramPerSecond, nanogrampersecondQuantity.Unit); - - var poundperhourQuantity = grampersecond.ToUnit(MassFlowUnit.PoundPerHour); - AssertEx.EqualTolerance(PoundsPerHourInOneGramPerSecond, (double)poundperhourQuantity.Value, PoundsPerHourTolerance); - Assert.Equal(MassFlowUnit.PoundPerHour, poundperhourQuantity.Unit); - - var shorttonperhourQuantity = grampersecond.ToUnit(MassFlowUnit.ShortTonPerHour); - AssertEx.EqualTolerance(ShortTonsPerHourInOneGramPerSecond, (double)shorttonperhourQuantity.Value, ShortTonsPerHourTolerance); - Assert.Equal(MassFlowUnit.ShortTonPerHour, shorttonperhourQuantity.Unit); - - var tonneperdayQuantity = grampersecond.ToUnit(MassFlowUnit.TonnePerDay); - AssertEx.EqualTolerance(TonnesPerDayInOneGramPerSecond, (double)tonneperdayQuantity.Value, TonnesPerDayTolerance); - Assert.Equal(MassFlowUnit.TonnePerDay, tonneperdayQuantity.Unit); - - var tonneperhourQuantity = grampersecond.ToUnit(MassFlowUnit.TonnePerHour); - AssertEx.EqualTolerance(TonnesPerHourInOneGramPerSecond, (double)tonneperhourQuantity.Value, TonnesPerHourTolerance); - Assert.Equal(MassFlowUnit.TonnePerHour, tonneperhourQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - MassFlow grampersecond = MassFlow.FromGramsPerSecond(1); - AssertEx.EqualTolerance(1, MassFlow.FromCentigramsPerSecond(grampersecond.CentigramsPerSecond).GramsPerSecond, CentigramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromDecagramsPerSecond(grampersecond.DecagramsPerSecond).GramsPerSecond, DecagramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromDecigramsPerSecond(grampersecond.DecigramsPerSecond).GramsPerSecond, DecigramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromGramsPerSecond(grampersecond.GramsPerSecond).GramsPerSecond, GramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromHectogramsPerSecond(grampersecond.HectogramsPerSecond).GramsPerSecond, HectogramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromKilogramsPerHour(grampersecond.KilogramsPerHour).GramsPerSecond, KilogramsPerHourTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromKilogramsPerSecond(grampersecond.KilogramsPerSecond).GramsPerSecond, KilogramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromMegapoundsPerHour(grampersecond.MegapoundsPerHour).GramsPerSecond, MegapoundsPerHourTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromMicrogramsPerSecond(grampersecond.MicrogramsPerSecond).GramsPerSecond, MicrogramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromMilligramsPerSecond(grampersecond.MilligramsPerSecond).GramsPerSecond, MilligramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromNanogramsPerSecond(grampersecond.NanogramsPerSecond).GramsPerSecond, NanogramsPerSecondTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromPoundsPerHour(grampersecond.PoundsPerHour).GramsPerSecond, PoundsPerHourTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromShortTonsPerHour(grampersecond.ShortTonsPerHour).GramsPerSecond, ShortTonsPerHourTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromTonnesPerDay(grampersecond.TonnesPerDay).GramsPerSecond, TonnesPerDayTolerance); - AssertEx.EqualTolerance(1, MassFlow.FromTonnesPerHour(grampersecond.TonnesPerHour).GramsPerSecond, TonnesPerHourTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - MassFlow v = MassFlow.FromGramsPerSecond(1); - AssertEx.EqualTolerance(-1, -v.GramsPerSecond, GramsPerSecondTolerance); - AssertEx.EqualTolerance(2, (MassFlow.FromGramsPerSecond(3)-v).GramsPerSecond, GramsPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).GramsPerSecond, GramsPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).GramsPerSecond, GramsPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).GramsPerSecond, GramsPerSecondTolerance); - AssertEx.EqualTolerance(2, (MassFlow.FromGramsPerSecond(10)/5).GramsPerSecond, GramsPerSecondTolerance); - AssertEx.EqualTolerance(2, MassFlow.FromGramsPerSecond(10)/MassFlow.FromGramsPerSecond(5), GramsPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - MassFlow oneGramPerSecond = MassFlow.FromGramsPerSecond(1); - MassFlow twoGramsPerSecond = MassFlow.FromGramsPerSecond(2); - - Assert.True(oneGramPerSecond < twoGramsPerSecond); - Assert.True(oneGramPerSecond <= twoGramsPerSecond); - Assert.True(twoGramsPerSecond > oneGramPerSecond); - Assert.True(twoGramsPerSecond >= oneGramPerSecond); - - Assert.False(oneGramPerSecond > twoGramsPerSecond); - Assert.False(oneGramPerSecond >= twoGramsPerSecond); - Assert.False(twoGramsPerSecond < oneGramPerSecond); - Assert.False(twoGramsPerSecond <= oneGramPerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - MassFlow grampersecond = MassFlow.FromGramsPerSecond(1); - Assert.Equal(0, grampersecond.CompareTo(grampersecond)); - Assert.True(grampersecond.CompareTo(MassFlow.Zero) > 0); - Assert.True(MassFlow.Zero.CompareTo(grampersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - MassFlow grampersecond = MassFlow.FromGramsPerSecond(1); - Assert.Throws(() => grampersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - MassFlow grampersecond = MassFlow.FromGramsPerSecond(1); - Assert.Throws(() => grampersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - MassFlow v = MassFlow.FromGramsPerSecond(1); - Assert.True(v.Equals(MassFlow.FromGramsPerSecond(1), GramsPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(MassFlow.Zero, GramsPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - MassFlow grampersecond = MassFlow.FromGramsPerSecond(1); - Assert.False(grampersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - MassFlow grampersecond = MassFlow.FromGramsPerSecond(1); - Assert.False(grampersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MassFlowUnit.Undefined, MassFlow.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MassFlowUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MassFlowUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MassFluxTestsBase.g.cs deleted file mode 100644 index c115b35589..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MassFluxTestsBase.g.cs +++ /dev/null @@ -1,234 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of MassFlux. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassFluxTestsBase - { - protected abstract double GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter { get; } - protected abstract double KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double GramsPerSecondPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double KilogramsPerSecondPerSquareMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new MassFlux((double)0.0, MassFluxUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new MassFlux(double.PositiveInfinity, MassFluxUnit.KilogramPerSecondPerSquareMeter)); - Assert.Throws(() => new MassFlux(double.NegativeInfinity, MassFluxUnit.KilogramPerSecondPerSquareMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new MassFlux(double.NaN, MassFluxUnit.KilogramPerSecondPerSquareMeter)); - } - - [Fact] - public void KilogramPerSecondPerSquareMeterToMassFluxUnits() - { - MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - AssertEx.EqualTolerance(GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.GramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, MassFlux.From(1, MassFluxUnit.GramPerSecondPerSquareMeter).GramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, MassFlux.From(1, MassFluxUnit.KilogramPerSecondPerSquareMeter).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - } - - [Fact] - public void FromKilogramsPerSecondPerSquareMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => MassFlux.FromKilogramsPerSecondPerSquareMeter(double.PositiveInfinity)); - Assert.Throws(() => MassFlux.FromKilogramsPerSecondPerSquareMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromKilogramsPerSecondPerSquareMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => MassFlux.FromKilogramsPerSecondPerSquareMeter(double.NaN)); - } - - [Fact] - public void As() - { - var kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - AssertEx.EqualTolerance(GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.GramPerSecondPerSquareMeter), GramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.KilogramPerSecondPerSquareMeter), KilogramsPerSecondPerSquareMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - - var grampersecondpersquaremeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.GramPerSecondPerSquareMeter); - AssertEx.EqualTolerance(GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, (double)grampersecondpersquaremeterQuantity.Value, GramsPerSecondPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMeter, grampersecondpersquaremeterQuantity.Unit); - - var kilogrampersecondpersquaremeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.KilogramPerSecondPerSquareMeter); - AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, (double)kilogrampersecondpersquaremeterQuantity.Value, KilogramsPerSecondPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - AssertEx.EqualTolerance(1, MassFlux.FromGramsPerSecondPerSquareMeter(kilogrampersecondpersquaremeter.GramsPerSecondPerSquareMeter).KilogramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, MassFlux.FromKilogramsPerSecondPerSquareMeter(kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareMeter).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - MassFlux v = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - AssertEx.EqualTolerance(-1, -v.KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (MassFlux.FromKilogramsPerSecondPerSquareMeter(3)-v).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, (MassFlux.FromKilogramsPerSecondPerSquareMeter(10)/5).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - AssertEx.EqualTolerance(2, MassFlux.FromKilogramsPerSecondPerSquareMeter(10)/MassFlux.FromKilogramsPerSecondPerSquareMeter(5), KilogramsPerSecondPerSquareMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - MassFlux oneKilogramPerSecondPerSquareMeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - MassFlux twoKilogramsPerSecondPerSquareMeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(2); - - Assert.True(oneKilogramPerSecondPerSquareMeter < twoKilogramsPerSecondPerSquareMeter); - Assert.True(oneKilogramPerSecondPerSquareMeter <= twoKilogramsPerSecondPerSquareMeter); - Assert.True(twoKilogramsPerSecondPerSquareMeter > oneKilogramPerSecondPerSquareMeter); - Assert.True(twoKilogramsPerSecondPerSquareMeter >= oneKilogramPerSecondPerSquareMeter); - - Assert.False(oneKilogramPerSecondPerSquareMeter > twoKilogramsPerSecondPerSquareMeter); - Assert.False(oneKilogramPerSecondPerSquareMeter >= twoKilogramsPerSecondPerSquareMeter); - Assert.False(twoKilogramsPerSecondPerSquareMeter < oneKilogramPerSecondPerSquareMeter); - Assert.False(twoKilogramsPerSecondPerSquareMeter <= oneKilogramPerSecondPerSquareMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - Assert.Equal(0, kilogrampersecondpersquaremeter.CompareTo(kilogrampersecondpersquaremeter)); - Assert.True(kilogrampersecondpersquaremeter.CompareTo(MassFlux.Zero) > 0); - Assert.True(MassFlux.Zero.CompareTo(kilogrampersecondpersquaremeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - Assert.Throws(() => kilogrampersecondpersquaremeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - Assert.Throws(() => kilogrampersecondpersquaremeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - MassFlux v = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - Assert.True(v.Equals(MassFlux.FromKilogramsPerSecondPerSquareMeter(1), KilogramsPerSecondPerSquareMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(MassFlux.Zero, KilogramsPerSecondPerSquareMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - Assert.False(kilogrampersecondpersquaremeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); - Assert.False(kilogrampersecondpersquaremeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MassFluxUnit.Undefined, MassFlux.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MassFluxUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MassFluxUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MassMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MassMomentOfInertiaTestsBase.g.cs deleted file mode 100644 index 72152d393a..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MassMomentOfInertiaTestsBase.g.cs +++ /dev/null @@ -1,494 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of MassMomentOfInertia. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassMomentOfInertiaTestsBase - { - protected abstract double GramSquareCentimetersInOneKilogramSquareMeter { get; } - protected abstract double GramSquareDecimetersInOneKilogramSquareMeter { get; } - protected abstract double GramSquareMetersInOneKilogramSquareMeter { get; } - protected abstract double GramSquareMillimetersInOneKilogramSquareMeter { get; } - protected abstract double KilogramSquareCentimetersInOneKilogramSquareMeter { get; } - protected abstract double KilogramSquareDecimetersInOneKilogramSquareMeter { get; } - protected abstract double KilogramSquareMetersInOneKilogramSquareMeter { get; } - protected abstract double KilogramSquareMillimetersInOneKilogramSquareMeter { get; } - protected abstract double KilotonneSquareCentimetersInOneKilogramSquareMeter { get; } - protected abstract double KilotonneSquareDecimetersInOneKilogramSquareMeter { get; } - protected abstract double KilotonneSquareMetersInOneKilogramSquareMeter { get; } - protected abstract double KilotonneSquareMilimetersInOneKilogramSquareMeter { get; } - protected abstract double MegatonneSquareCentimetersInOneKilogramSquareMeter { get; } - protected abstract double MegatonneSquareDecimetersInOneKilogramSquareMeter { get; } - protected abstract double MegatonneSquareMetersInOneKilogramSquareMeter { get; } - protected abstract double MegatonneSquareMilimetersInOneKilogramSquareMeter { get; } - protected abstract double MilligramSquareCentimetersInOneKilogramSquareMeter { get; } - protected abstract double MilligramSquareDecimetersInOneKilogramSquareMeter { get; } - protected abstract double MilligramSquareMetersInOneKilogramSquareMeter { get; } - protected abstract double MilligramSquareMillimetersInOneKilogramSquareMeter { get; } - protected abstract double PoundSquareFeetInOneKilogramSquareMeter { get; } - protected abstract double PoundSquareInchesInOneKilogramSquareMeter { get; } - protected abstract double SlugSquareFeetInOneKilogramSquareMeter { get; } - protected abstract double SlugSquareInchesInOneKilogramSquareMeter { get; } - protected abstract double TonneSquareCentimetersInOneKilogramSquareMeter { get; } - protected abstract double TonneSquareDecimetersInOneKilogramSquareMeter { get; } - protected abstract double TonneSquareMetersInOneKilogramSquareMeter { get; } - protected abstract double TonneSquareMilimetersInOneKilogramSquareMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double GramSquareCentimetersTolerance { get { return 1e-5; } } - protected virtual double GramSquareDecimetersTolerance { get { return 1e-5; } } - protected virtual double GramSquareMetersTolerance { get { return 1e-5; } } - protected virtual double GramSquareMillimetersTolerance { get { return 1e-5; } } - protected virtual double KilogramSquareCentimetersTolerance { get { return 1e-5; } } - protected virtual double KilogramSquareDecimetersTolerance { get { return 1e-5; } } - protected virtual double KilogramSquareMetersTolerance { get { return 1e-5; } } - protected virtual double KilogramSquareMillimetersTolerance { get { return 1e-5; } } - protected virtual double KilotonneSquareCentimetersTolerance { get { return 1e-5; } } - protected virtual double KilotonneSquareDecimetersTolerance { get { return 1e-5; } } - protected virtual double KilotonneSquareMetersTolerance { get { return 1e-5; } } - protected virtual double KilotonneSquareMilimetersTolerance { get { return 1e-5; } } - protected virtual double MegatonneSquareCentimetersTolerance { get { return 1e-5; } } - protected virtual double MegatonneSquareDecimetersTolerance { get { return 1e-5; } } - protected virtual double MegatonneSquareMetersTolerance { get { return 1e-5; } } - protected virtual double MegatonneSquareMilimetersTolerance { get { return 1e-5; } } - protected virtual double MilligramSquareCentimetersTolerance { get { return 1e-5; } } - protected virtual double MilligramSquareDecimetersTolerance { get { return 1e-5; } } - protected virtual double MilligramSquareMetersTolerance { get { return 1e-5; } } - protected virtual double MilligramSquareMillimetersTolerance { get { return 1e-5; } } - protected virtual double PoundSquareFeetTolerance { get { return 1e-5; } } - protected virtual double PoundSquareInchesTolerance { get { return 1e-5; } } - protected virtual double SlugSquareFeetTolerance { get { return 1e-5; } } - protected virtual double SlugSquareInchesTolerance { get { return 1e-5; } } - protected virtual double TonneSquareCentimetersTolerance { get { return 1e-5; } } - protected virtual double TonneSquareDecimetersTolerance { get { return 1e-5; } } - protected virtual double TonneSquareMetersTolerance { get { return 1e-5; } } - protected virtual double TonneSquareMilimetersTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new MassMomentOfInertia((double)0.0, MassMomentOfInertiaUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new MassMomentOfInertia(double.PositiveInfinity, MassMomentOfInertiaUnit.KilogramSquareMeter)); - Assert.Throws(() => new MassMomentOfInertia(double.NegativeInfinity, MassMomentOfInertiaUnit.KilogramSquareMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new MassMomentOfInertia(double.NaN, MassMomentOfInertiaUnit.KilogramSquareMeter)); - } - - [Fact] - public void KilogramSquareMeterToMassMomentOfInertiaUnits() - { - MassMomentOfInertia kilogramsquaremeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - AssertEx.EqualTolerance(GramSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.GramSquareCentimeters, GramSquareCentimetersTolerance); - AssertEx.EqualTolerance(GramSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.GramSquareDecimeters, GramSquareDecimetersTolerance); - AssertEx.EqualTolerance(GramSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.GramSquareMeters, GramSquareMetersTolerance); - AssertEx.EqualTolerance(GramSquareMillimetersInOneKilogramSquareMeter, kilogramsquaremeter.GramSquareMillimeters, GramSquareMillimetersTolerance); - AssertEx.EqualTolerance(KilogramSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.KilogramSquareCentimeters, KilogramSquareCentimetersTolerance); - AssertEx.EqualTolerance(KilogramSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.KilogramSquareDecimeters, KilogramSquareDecimetersTolerance); - AssertEx.EqualTolerance(KilogramSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.KilogramSquareMeters, KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(KilogramSquareMillimetersInOneKilogramSquareMeter, kilogramsquaremeter.KilogramSquareMillimeters, KilogramSquareMillimetersTolerance); - AssertEx.EqualTolerance(KilotonneSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.KilotonneSquareCentimeters, KilotonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(KilotonneSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.KilotonneSquareDecimeters, KilotonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(KilotonneSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.KilotonneSquareMeters, KilotonneSquareMetersTolerance); - AssertEx.EqualTolerance(KilotonneSquareMilimetersInOneKilogramSquareMeter, kilogramsquaremeter.KilotonneSquareMilimeters, KilotonneSquareMilimetersTolerance); - AssertEx.EqualTolerance(MegatonneSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.MegatonneSquareCentimeters, MegatonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(MegatonneSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.MegatonneSquareDecimeters, MegatonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(MegatonneSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.MegatonneSquareMeters, MegatonneSquareMetersTolerance); - AssertEx.EqualTolerance(MegatonneSquareMilimetersInOneKilogramSquareMeter, kilogramsquaremeter.MegatonneSquareMilimeters, MegatonneSquareMilimetersTolerance); - AssertEx.EqualTolerance(MilligramSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.MilligramSquareCentimeters, MilligramSquareCentimetersTolerance); - AssertEx.EqualTolerance(MilligramSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.MilligramSquareDecimeters, MilligramSquareDecimetersTolerance); - AssertEx.EqualTolerance(MilligramSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.MilligramSquareMeters, MilligramSquareMetersTolerance); - AssertEx.EqualTolerance(MilligramSquareMillimetersInOneKilogramSquareMeter, kilogramsquaremeter.MilligramSquareMillimeters, MilligramSquareMillimetersTolerance); - AssertEx.EqualTolerance(PoundSquareFeetInOneKilogramSquareMeter, kilogramsquaremeter.PoundSquareFeet, PoundSquareFeetTolerance); - AssertEx.EqualTolerance(PoundSquareInchesInOneKilogramSquareMeter, kilogramsquaremeter.PoundSquareInches, PoundSquareInchesTolerance); - AssertEx.EqualTolerance(SlugSquareFeetInOneKilogramSquareMeter, kilogramsquaremeter.SlugSquareFeet, SlugSquareFeetTolerance); - AssertEx.EqualTolerance(SlugSquareInchesInOneKilogramSquareMeter, kilogramsquaremeter.SlugSquareInches, SlugSquareInchesTolerance); - AssertEx.EqualTolerance(TonneSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.TonneSquareCentimeters, TonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(TonneSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.TonneSquareDecimeters, TonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(TonneSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.TonneSquareMeters, TonneSquareMetersTolerance); - AssertEx.EqualTolerance(TonneSquareMilimetersInOneKilogramSquareMeter, kilogramsquaremeter.TonneSquareMilimeters, TonneSquareMilimetersTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.GramSquareCentimeter).GramSquareCentimeters, GramSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.GramSquareDecimeter).GramSquareDecimeters, GramSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.GramSquareMeter).GramSquareMeters, GramSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.GramSquareMillimeter).GramSquareMillimeters, GramSquareMillimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.KilogramSquareCentimeter).KilogramSquareCentimeters, KilogramSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.KilogramSquareDecimeter).KilogramSquareDecimeters, KilogramSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.KilogramSquareMeter).KilogramSquareMeters, KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.KilogramSquareMillimeter).KilogramSquareMillimeters, KilogramSquareMillimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.KilotonneSquareCentimeter).KilotonneSquareCentimeters, KilotonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.KilotonneSquareDecimeter).KilotonneSquareDecimeters, KilotonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.KilotonneSquareMeter).KilotonneSquareMeters, KilotonneSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.KilotonneSquareMilimeter).KilotonneSquareMilimeters, KilotonneSquareMilimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.MegatonneSquareCentimeter).MegatonneSquareCentimeters, MegatonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.MegatonneSquareDecimeter).MegatonneSquareDecimeters, MegatonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.MegatonneSquareMeter).MegatonneSquareMeters, MegatonneSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.MegatonneSquareMilimeter).MegatonneSquareMilimeters, MegatonneSquareMilimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.MilligramSquareCentimeter).MilligramSquareCentimeters, MilligramSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.MilligramSquareDecimeter).MilligramSquareDecimeters, MilligramSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.MilligramSquareMeter).MilligramSquareMeters, MilligramSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.MilligramSquareMillimeter).MilligramSquareMillimeters, MilligramSquareMillimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.PoundSquareFoot).PoundSquareFeet, PoundSquareFeetTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.PoundSquareInch).PoundSquareInches, PoundSquareInchesTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.SlugSquareFoot).SlugSquareFeet, SlugSquareFeetTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.SlugSquareInch).SlugSquareInches, SlugSquareInchesTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.TonneSquareCentimeter).TonneSquareCentimeters, TonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.TonneSquareDecimeter).TonneSquareDecimeters, TonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.TonneSquareMeter).TonneSquareMeters, TonneSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.TonneSquareMilimeter).TonneSquareMilimeters, TonneSquareMilimetersTolerance); - } - - [Fact] - public void FromKilogramSquareMeters_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => MassMomentOfInertia.FromKilogramSquareMeters(double.PositiveInfinity)); - Assert.Throws(() => MassMomentOfInertia.FromKilogramSquareMeters(double.NegativeInfinity)); - } - - [Fact] - public void FromKilogramSquareMeters_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => MassMomentOfInertia.FromKilogramSquareMeters(double.NaN)); - } - - [Fact] - public void As() - { - var kilogramsquaremeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - AssertEx.EqualTolerance(GramSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.GramSquareCentimeter), GramSquareCentimetersTolerance); - AssertEx.EqualTolerance(GramSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.GramSquareDecimeter), GramSquareDecimetersTolerance); - AssertEx.EqualTolerance(GramSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.GramSquareMeter), GramSquareMetersTolerance); - AssertEx.EqualTolerance(GramSquareMillimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.GramSquareMillimeter), GramSquareMillimetersTolerance); - AssertEx.EqualTolerance(KilogramSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.KilogramSquareCentimeter), KilogramSquareCentimetersTolerance); - AssertEx.EqualTolerance(KilogramSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.KilogramSquareDecimeter), KilogramSquareDecimetersTolerance); - AssertEx.EqualTolerance(KilogramSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.KilogramSquareMeter), KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(KilogramSquareMillimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.KilogramSquareMillimeter), KilogramSquareMillimetersTolerance); - AssertEx.EqualTolerance(KilotonneSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.KilotonneSquareCentimeter), KilotonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(KilotonneSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.KilotonneSquareDecimeter), KilotonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(KilotonneSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.KilotonneSquareMeter), KilotonneSquareMetersTolerance); - AssertEx.EqualTolerance(KilotonneSquareMilimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.KilotonneSquareMilimeter), KilotonneSquareMilimetersTolerance); - AssertEx.EqualTolerance(MegatonneSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.MegatonneSquareCentimeter), MegatonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(MegatonneSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.MegatonneSquareDecimeter), MegatonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(MegatonneSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.MegatonneSquareMeter), MegatonneSquareMetersTolerance); - AssertEx.EqualTolerance(MegatonneSquareMilimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.MegatonneSquareMilimeter), MegatonneSquareMilimetersTolerance); - AssertEx.EqualTolerance(MilligramSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.MilligramSquareCentimeter), MilligramSquareCentimetersTolerance); - AssertEx.EqualTolerance(MilligramSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.MilligramSquareDecimeter), MilligramSquareDecimetersTolerance); - AssertEx.EqualTolerance(MilligramSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.MilligramSquareMeter), MilligramSquareMetersTolerance); - AssertEx.EqualTolerance(MilligramSquareMillimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.MilligramSquareMillimeter), MilligramSquareMillimetersTolerance); - AssertEx.EqualTolerance(PoundSquareFeetInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.PoundSquareFoot), PoundSquareFeetTolerance); - AssertEx.EqualTolerance(PoundSquareInchesInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.PoundSquareInch), PoundSquareInchesTolerance); - AssertEx.EqualTolerance(SlugSquareFeetInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.SlugSquareFoot), SlugSquareFeetTolerance); - AssertEx.EqualTolerance(SlugSquareInchesInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.SlugSquareInch), SlugSquareInchesTolerance); - AssertEx.EqualTolerance(TonneSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.TonneSquareCentimeter), TonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(TonneSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.TonneSquareDecimeter), TonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(TonneSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.TonneSquareMeter), TonneSquareMetersTolerance); - AssertEx.EqualTolerance(TonneSquareMilimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.TonneSquareMilimeter), TonneSquareMilimetersTolerance); - } - - [Fact] - public void ToUnit() - { - var kilogramsquaremeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - - var gramsquarecentimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.GramSquareCentimeter); - AssertEx.EqualTolerance(GramSquareCentimetersInOneKilogramSquareMeter, (double)gramsquarecentimeterQuantity.Value, GramSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareCentimeter, gramsquarecentimeterQuantity.Unit); - - var gramsquaredecimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.GramSquareDecimeter); - AssertEx.EqualTolerance(GramSquareDecimetersInOneKilogramSquareMeter, (double)gramsquaredecimeterQuantity.Value, GramSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareDecimeter, gramsquaredecimeterQuantity.Unit); - - var gramsquaremeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.GramSquareMeter); - AssertEx.EqualTolerance(GramSquareMetersInOneKilogramSquareMeter, (double)gramsquaremeterQuantity.Value, GramSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMeter, gramsquaremeterQuantity.Unit); - - var gramsquaremillimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.GramSquareMillimeter); - AssertEx.EqualTolerance(GramSquareMillimetersInOneKilogramSquareMeter, (double)gramsquaremillimeterQuantity.Value, GramSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMillimeter, gramsquaremillimeterQuantity.Unit); - - var kilogramsquarecentimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.KilogramSquareCentimeter); - AssertEx.EqualTolerance(KilogramSquareCentimetersInOneKilogramSquareMeter, (double)kilogramsquarecentimeterQuantity.Value, KilogramSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareCentimeter, kilogramsquarecentimeterQuantity.Unit); - - var kilogramsquaredecimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.KilogramSquareDecimeter); - AssertEx.EqualTolerance(KilogramSquareDecimetersInOneKilogramSquareMeter, (double)kilogramsquaredecimeterQuantity.Value, KilogramSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareDecimeter, kilogramsquaredecimeterQuantity.Unit); - - var kilogramsquaremeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.KilogramSquareMeter); - AssertEx.EqualTolerance(KilogramSquareMetersInOneKilogramSquareMeter, (double)kilogramsquaremeterQuantity.Value, KilogramSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMeter, kilogramsquaremeterQuantity.Unit); - - var kilogramsquaremillimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.KilogramSquareMillimeter); - AssertEx.EqualTolerance(KilogramSquareMillimetersInOneKilogramSquareMeter, (double)kilogramsquaremillimeterQuantity.Value, KilogramSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMillimeter, kilogramsquaremillimeterQuantity.Unit); - - var kilotonnesquarecentimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.KilotonneSquareCentimeter); - AssertEx.EqualTolerance(KilotonneSquareCentimetersInOneKilogramSquareMeter, (double)kilotonnesquarecentimeterQuantity.Value, KilotonneSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareCentimeter, kilotonnesquarecentimeterQuantity.Unit); - - var kilotonnesquaredecimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.KilotonneSquareDecimeter); - AssertEx.EqualTolerance(KilotonneSquareDecimetersInOneKilogramSquareMeter, (double)kilotonnesquaredecimeterQuantity.Value, KilotonneSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareDecimeter, kilotonnesquaredecimeterQuantity.Unit); - - var kilotonnesquaremeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.KilotonneSquareMeter); - AssertEx.EqualTolerance(KilotonneSquareMetersInOneKilogramSquareMeter, (double)kilotonnesquaremeterQuantity.Value, KilotonneSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMeter, kilotonnesquaremeterQuantity.Unit); - - var kilotonnesquaremilimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.KilotonneSquareMilimeter); - AssertEx.EqualTolerance(KilotonneSquareMilimetersInOneKilogramSquareMeter, (double)kilotonnesquaremilimeterQuantity.Value, KilotonneSquareMilimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMilimeter, kilotonnesquaremilimeterQuantity.Unit); - - var megatonnesquarecentimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.MegatonneSquareCentimeter); - AssertEx.EqualTolerance(MegatonneSquareCentimetersInOneKilogramSquareMeter, (double)megatonnesquarecentimeterQuantity.Value, MegatonneSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareCentimeter, megatonnesquarecentimeterQuantity.Unit); - - var megatonnesquaredecimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.MegatonneSquareDecimeter); - AssertEx.EqualTolerance(MegatonneSquareDecimetersInOneKilogramSquareMeter, (double)megatonnesquaredecimeterQuantity.Value, MegatonneSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareDecimeter, megatonnesquaredecimeterQuantity.Unit); - - var megatonnesquaremeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.MegatonneSquareMeter); - AssertEx.EqualTolerance(MegatonneSquareMetersInOneKilogramSquareMeter, (double)megatonnesquaremeterQuantity.Value, MegatonneSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMeter, megatonnesquaremeterQuantity.Unit); - - var megatonnesquaremilimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.MegatonneSquareMilimeter); - AssertEx.EqualTolerance(MegatonneSquareMilimetersInOneKilogramSquareMeter, (double)megatonnesquaremilimeterQuantity.Value, MegatonneSquareMilimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMilimeter, megatonnesquaremilimeterQuantity.Unit); - - var milligramsquarecentimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.MilligramSquareCentimeter); - AssertEx.EqualTolerance(MilligramSquareCentimetersInOneKilogramSquareMeter, (double)milligramsquarecentimeterQuantity.Value, MilligramSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareCentimeter, milligramsquarecentimeterQuantity.Unit); - - var milligramsquaredecimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.MilligramSquareDecimeter); - AssertEx.EqualTolerance(MilligramSquareDecimetersInOneKilogramSquareMeter, (double)milligramsquaredecimeterQuantity.Value, MilligramSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareDecimeter, milligramsquaredecimeterQuantity.Unit); - - var milligramsquaremeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.MilligramSquareMeter); - AssertEx.EqualTolerance(MilligramSquareMetersInOneKilogramSquareMeter, (double)milligramsquaremeterQuantity.Value, MilligramSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMeter, milligramsquaremeterQuantity.Unit); - - var milligramsquaremillimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.MilligramSquareMillimeter); - AssertEx.EqualTolerance(MilligramSquareMillimetersInOneKilogramSquareMeter, (double)milligramsquaremillimeterQuantity.Value, MilligramSquareMillimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMillimeter, milligramsquaremillimeterQuantity.Unit); - - var poundsquarefootQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.PoundSquareFoot); - AssertEx.EqualTolerance(PoundSquareFeetInOneKilogramSquareMeter, (double)poundsquarefootQuantity.Value, PoundSquareFeetTolerance); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareFoot, poundsquarefootQuantity.Unit); - - var poundsquareinchQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.PoundSquareInch); - AssertEx.EqualTolerance(PoundSquareInchesInOneKilogramSquareMeter, (double)poundsquareinchQuantity.Value, PoundSquareInchesTolerance); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareInch, poundsquareinchQuantity.Unit); - - var slugsquarefootQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.SlugSquareFoot); - AssertEx.EqualTolerance(SlugSquareFeetInOneKilogramSquareMeter, (double)slugsquarefootQuantity.Value, SlugSquareFeetTolerance); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareFoot, slugsquarefootQuantity.Unit); - - var slugsquareinchQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.SlugSquareInch); - AssertEx.EqualTolerance(SlugSquareInchesInOneKilogramSquareMeter, (double)slugsquareinchQuantity.Value, SlugSquareInchesTolerance); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareInch, slugsquareinchQuantity.Unit); - - var tonnesquarecentimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.TonneSquareCentimeter); - AssertEx.EqualTolerance(TonneSquareCentimetersInOneKilogramSquareMeter, (double)tonnesquarecentimeterQuantity.Value, TonneSquareCentimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareCentimeter, tonnesquarecentimeterQuantity.Unit); - - var tonnesquaredecimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.TonneSquareDecimeter); - AssertEx.EqualTolerance(TonneSquareDecimetersInOneKilogramSquareMeter, (double)tonnesquaredecimeterQuantity.Value, TonneSquareDecimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareDecimeter, tonnesquaredecimeterQuantity.Unit); - - var tonnesquaremeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.TonneSquareMeter); - AssertEx.EqualTolerance(TonneSquareMetersInOneKilogramSquareMeter, (double)tonnesquaremeterQuantity.Value, TonneSquareMetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMeter, tonnesquaremeterQuantity.Unit); - - var tonnesquaremilimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.TonneSquareMilimeter); - AssertEx.EqualTolerance(TonneSquareMilimetersInOneKilogramSquareMeter, (double)tonnesquaremilimeterQuantity.Value, TonneSquareMilimetersTolerance); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMilimeter, tonnesquaremilimeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - MassMomentOfInertia kilogramsquaremeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromGramSquareCentimeters(kilogramsquaremeter.GramSquareCentimeters).KilogramSquareMeters, GramSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromGramSquareDecimeters(kilogramsquaremeter.GramSquareDecimeters).KilogramSquareMeters, GramSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromGramSquareMeters(kilogramsquaremeter.GramSquareMeters).KilogramSquareMeters, GramSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromGramSquareMillimeters(kilogramsquaremeter.GramSquareMillimeters).KilogramSquareMeters, GramSquareMillimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromKilogramSquareCentimeters(kilogramsquaremeter.KilogramSquareCentimeters).KilogramSquareMeters, KilogramSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromKilogramSquareDecimeters(kilogramsquaremeter.KilogramSquareDecimeters).KilogramSquareMeters, KilogramSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromKilogramSquareMeters(kilogramsquaremeter.KilogramSquareMeters).KilogramSquareMeters, KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromKilogramSquareMillimeters(kilogramsquaremeter.KilogramSquareMillimeters).KilogramSquareMeters, KilogramSquareMillimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromKilotonneSquareCentimeters(kilogramsquaremeter.KilotonneSquareCentimeters).KilogramSquareMeters, KilotonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromKilotonneSquareDecimeters(kilogramsquaremeter.KilotonneSquareDecimeters).KilogramSquareMeters, KilotonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromKilotonneSquareMeters(kilogramsquaremeter.KilotonneSquareMeters).KilogramSquareMeters, KilotonneSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromKilotonneSquareMilimeters(kilogramsquaremeter.KilotonneSquareMilimeters).KilogramSquareMeters, KilotonneSquareMilimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromMegatonneSquareCentimeters(kilogramsquaremeter.MegatonneSquareCentimeters).KilogramSquareMeters, MegatonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromMegatonneSquareDecimeters(kilogramsquaremeter.MegatonneSquareDecimeters).KilogramSquareMeters, MegatonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromMegatonneSquareMeters(kilogramsquaremeter.MegatonneSquareMeters).KilogramSquareMeters, MegatonneSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromMegatonneSquareMilimeters(kilogramsquaremeter.MegatonneSquareMilimeters).KilogramSquareMeters, MegatonneSquareMilimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromMilligramSquareCentimeters(kilogramsquaremeter.MilligramSquareCentimeters).KilogramSquareMeters, MilligramSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromMilligramSquareDecimeters(kilogramsquaremeter.MilligramSquareDecimeters).KilogramSquareMeters, MilligramSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromMilligramSquareMeters(kilogramsquaremeter.MilligramSquareMeters).KilogramSquareMeters, MilligramSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromMilligramSquareMillimeters(kilogramsquaremeter.MilligramSquareMillimeters).KilogramSquareMeters, MilligramSquareMillimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromPoundSquareFeet(kilogramsquaremeter.PoundSquareFeet).KilogramSquareMeters, PoundSquareFeetTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromPoundSquareInches(kilogramsquaremeter.PoundSquareInches).KilogramSquareMeters, PoundSquareInchesTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromSlugSquareFeet(kilogramsquaremeter.SlugSquareFeet).KilogramSquareMeters, SlugSquareFeetTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromSlugSquareInches(kilogramsquaremeter.SlugSquareInches).KilogramSquareMeters, SlugSquareInchesTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromTonneSquareCentimeters(kilogramsquaremeter.TonneSquareCentimeters).KilogramSquareMeters, TonneSquareCentimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromTonneSquareDecimeters(kilogramsquaremeter.TonneSquareDecimeters).KilogramSquareMeters, TonneSquareDecimetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromTonneSquareMeters(kilogramsquaremeter.TonneSquareMeters).KilogramSquareMeters, TonneSquareMetersTolerance); - AssertEx.EqualTolerance(1, MassMomentOfInertia.FromTonneSquareMilimeters(kilogramsquaremeter.TonneSquareMilimeters).KilogramSquareMeters, TonneSquareMilimetersTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - MassMomentOfInertia v = MassMomentOfInertia.FromKilogramSquareMeters(1); - AssertEx.EqualTolerance(-1, -v.KilogramSquareMeters, KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(2, (MassMomentOfInertia.FromKilogramSquareMeters(3)-v).KilogramSquareMeters, KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(2, (v + v).KilogramSquareMeters, KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(10, (v*10).KilogramSquareMeters, KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(10, (10*v).KilogramSquareMeters, KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(2, (MassMomentOfInertia.FromKilogramSquareMeters(10)/5).KilogramSquareMeters, KilogramSquareMetersTolerance); - AssertEx.EqualTolerance(2, MassMomentOfInertia.FromKilogramSquareMeters(10)/MassMomentOfInertia.FromKilogramSquareMeters(5), KilogramSquareMetersTolerance); - } - - [Fact] - public void ComparisonOperators() - { - MassMomentOfInertia oneKilogramSquareMeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - MassMomentOfInertia twoKilogramSquareMeters = MassMomentOfInertia.FromKilogramSquareMeters(2); - - Assert.True(oneKilogramSquareMeter < twoKilogramSquareMeters); - Assert.True(oneKilogramSquareMeter <= twoKilogramSquareMeters); - Assert.True(twoKilogramSquareMeters > oneKilogramSquareMeter); - Assert.True(twoKilogramSquareMeters >= oneKilogramSquareMeter); - - Assert.False(oneKilogramSquareMeter > twoKilogramSquareMeters); - Assert.False(oneKilogramSquareMeter >= twoKilogramSquareMeters); - Assert.False(twoKilogramSquareMeters < oneKilogramSquareMeter); - Assert.False(twoKilogramSquareMeters <= oneKilogramSquareMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - MassMomentOfInertia kilogramsquaremeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - Assert.Equal(0, kilogramsquaremeter.CompareTo(kilogramsquaremeter)); - Assert.True(kilogramsquaremeter.CompareTo(MassMomentOfInertia.Zero) > 0); - Assert.True(MassMomentOfInertia.Zero.CompareTo(kilogramsquaremeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - MassMomentOfInertia kilogramsquaremeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - Assert.Throws(() => kilogramsquaremeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - MassMomentOfInertia kilogramsquaremeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - Assert.Throws(() => kilogramsquaremeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - MassMomentOfInertia v = MassMomentOfInertia.FromKilogramSquareMeters(1); - Assert.True(v.Equals(MassMomentOfInertia.FromKilogramSquareMeters(1), KilogramSquareMetersTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(MassMomentOfInertia.Zero, KilogramSquareMetersTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - MassMomentOfInertia kilogramsquaremeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - Assert.False(kilogramsquaremeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - MassMomentOfInertia kilogramsquaremeter = MassMomentOfInertia.FromKilogramSquareMeters(1); - Assert.False(kilogramsquaremeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MassMomentOfInertiaUnit.Undefined, MassMomentOfInertia.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MassMomentOfInertiaUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MassMomentOfInertiaUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs deleted file mode 100644 index 0f604d58fc..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs +++ /dev/null @@ -1,434 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Mass. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassTestsBase - { - protected abstract double CentigramsInOneKilogram { get; } - protected abstract double DecagramsInOneKilogram { get; } - protected abstract double DecigramsInOneKilogram { get; } - protected abstract double GramsInOneKilogram { get; } - protected abstract double HectogramsInOneKilogram { get; } - protected abstract double KilogramsInOneKilogram { get; } - protected abstract double KilopoundsInOneKilogram { get; } - protected abstract double KilotonnesInOneKilogram { get; } - protected abstract double LongHundredweightInOneKilogram { get; } - protected abstract double LongTonsInOneKilogram { get; } - protected abstract double MegapoundsInOneKilogram { get; } - protected abstract double MegatonnesInOneKilogram { get; } - protected abstract double MicrogramsInOneKilogram { get; } - protected abstract double MilligramsInOneKilogram { get; } - protected abstract double NanogramsInOneKilogram { get; } - protected abstract double OuncesInOneKilogram { get; } - protected abstract double PoundsInOneKilogram { get; } - protected abstract double ShortHundredweightInOneKilogram { get; } - protected abstract double ShortTonsInOneKilogram { get; } - protected abstract double SlugsInOneKilogram { get; } - protected abstract double StoneInOneKilogram { get; } - protected abstract double TonnesInOneKilogram { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentigramsTolerance { get { return 1e-5; } } - protected virtual double DecagramsTolerance { get { return 1e-5; } } - protected virtual double DecigramsTolerance { get { return 1e-5; } } - protected virtual double GramsTolerance { get { return 1e-5; } } - protected virtual double HectogramsTolerance { get { return 1e-5; } } - protected virtual double KilogramsTolerance { get { return 1e-5; } } - protected virtual double KilopoundsTolerance { get { return 1e-5; } } - protected virtual double KilotonnesTolerance { get { return 1e-5; } } - protected virtual double LongHundredweightTolerance { get { return 1e-5; } } - protected virtual double LongTonsTolerance { get { return 1e-5; } } - protected virtual double MegapoundsTolerance { get { return 1e-5; } } - protected virtual double MegatonnesTolerance { get { return 1e-5; } } - protected virtual double MicrogramsTolerance { get { return 1e-5; } } - protected virtual double MilligramsTolerance { get { return 1e-5; } } - protected virtual double NanogramsTolerance { get { return 1e-5; } } - protected virtual double OuncesTolerance { get { return 1e-5; } } - protected virtual double PoundsTolerance { get { return 1e-5; } } - protected virtual double ShortHundredweightTolerance { get { return 1e-5; } } - protected virtual double ShortTonsTolerance { get { return 1e-5; } } - protected virtual double SlugsTolerance { get { return 1e-5; } } - protected virtual double StoneTolerance { get { return 1e-5; } } - protected virtual double TonnesTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Mass((double)0.0, MassUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Mass(double.PositiveInfinity, MassUnit.Kilogram)); - Assert.Throws(() => new Mass(double.NegativeInfinity, MassUnit.Kilogram)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Mass(double.NaN, MassUnit.Kilogram)); - } - - [Fact] - public void KilogramToMassUnits() - { - Mass kilogram = Mass.FromKilograms(1); - AssertEx.EqualTolerance(CentigramsInOneKilogram, kilogram.Centigrams, CentigramsTolerance); - AssertEx.EqualTolerance(DecagramsInOneKilogram, kilogram.Decagrams, DecagramsTolerance); - AssertEx.EqualTolerance(DecigramsInOneKilogram, kilogram.Decigrams, DecigramsTolerance); - AssertEx.EqualTolerance(GramsInOneKilogram, kilogram.Grams, GramsTolerance); - AssertEx.EqualTolerance(HectogramsInOneKilogram, kilogram.Hectograms, HectogramsTolerance); - AssertEx.EqualTolerance(KilogramsInOneKilogram, kilogram.Kilograms, KilogramsTolerance); - AssertEx.EqualTolerance(KilopoundsInOneKilogram, kilogram.Kilopounds, KilopoundsTolerance); - AssertEx.EqualTolerance(KilotonnesInOneKilogram, kilogram.Kilotonnes, KilotonnesTolerance); - AssertEx.EqualTolerance(LongHundredweightInOneKilogram, kilogram.LongHundredweight, LongHundredweightTolerance); - AssertEx.EqualTolerance(LongTonsInOneKilogram, kilogram.LongTons, LongTonsTolerance); - AssertEx.EqualTolerance(MegapoundsInOneKilogram, kilogram.Megapounds, MegapoundsTolerance); - AssertEx.EqualTolerance(MegatonnesInOneKilogram, kilogram.Megatonnes, MegatonnesTolerance); - AssertEx.EqualTolerance(MicrogramsInOneKilogram, kilogram.Micrograms, MicrogramsTolerance); - AssertEx.EqualTolerance(MilligramsInOneKilogram, kilogram.Milligrams, MilligramsTolerance); - AssertEx.EqualTolerance(NanogramsInOneKilogram, kilogram.Nanograms, NanogramsTolerance); - AssertEx.EqualTolerance(OuncesInOneKilogram, kilogram.Ounces, OuncesTolerance); - AssertEx.EqualTolerance(PoundsInOneKilogram, kilogram.Pounds, PoundsTolerance); - AssertEx.EqualTolerance(ShortHundredweightInOneKilogram, kilogram.ShortHundredweight, ShortHundredweightTolerance); - AssertEx.EqualTolerance(ShortTonsInOneKilogram, kilogram.ShortTons, ShortTonsTolerance); - AssertEx.EqualTolerance(SlugsInOneKilogram, kilogram.Slugs, SlugsTolerance); - AssertEx.EqualTolerance(StoneInOneKilogram, kilogram.Stone, StoneTolerance); - AssertEx.EqualTolerance(TonnesInOneKilogram, kilogram.Tonnes, TonnesTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Centigram).Centigrams, CentigramsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Decagram).Decagrams, DecagramsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Decigram).Decigrams, DecigramsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Gram).Grams, GramsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Hectogram).Hectograms, HectogramsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Kilogram).Kilograms, KilogramsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Kilopound).Kilopounds, KilopoundsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Kilotonne).Kilotonnes, KilotonnesTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.LongHundredweight).LongHundredweight, LongHundredweightTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.LongTon).LongTons, LongTonsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Megapound).Megapounds, MegapoundsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Megatonne).Megatonnes, MegatonnesTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Microgram).Micrograms, MicrogramsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Milligram).Milligrams, MilligramsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Nanogram).Nanograms, NanogramsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Ounce).Ounces, OuncesTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Pound).Pounds, PoundsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.ShortHundredweight).ShortHundredweight, ShortHundredweightTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.ShortTon).ShortTons, ShortTonsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Slug).Slugs, SlugsTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Stone).Stone, StoneTolerance); - AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Tonne).Tonnes, TonnesTolerance); - } - - [Fact] - public void FromKilograms_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Mass.FromKilograms(double.PositiveInfinity)); - Assert.Throws(() => Mass.FromKilograms(double.NegativeInfinity)); - } - - [Fact] - public void FromKilograms_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Mass.FromKilograms(double.NaN)); - } - - [Fact] - public void As() - { - var kilogram = Mass.FromKilograms(1); - AssertEx.EqualTolerance(CentigramsInOneKilogram, kilogram.As(MassUnit.Centigram), CentigramsTolerance); - AssertEx.EqualTolerance(DecagramsInOneKilogram, kilogram.As(MassUnit.Decagram), DecagramsTolerance); - AssertEx.EqualTolerance(DecigramsInOneKilogram, kilogram.As(MassUnit.Decigram), DecigramsTolerance); - AssertEx.EqualTolerance(GramsInOneKilogram, kilogram.As(MassUnit.Gram), GramsTolerance); - AssertEx.EqualTolerance(HectogramsInOneKilogram, kilogram.As(MassUnit.Hectogram), HectogramsTolerance); - AssertEx.EqualTolerance(KilogramsInOneKilogram, kilogram.As(MassUnit.Kilogram), KilogramsTolerance); - AssertEx.EqualTolerance(KilopoundsInOneKilogram, kilogram.As(MassUnit.Kilopound), KilopoundsTolerance); - AssertEx.EqualTolerance(KilotonnesInOneKilogram, kilogram.As(MassUnit.Kilotonne), KilotonnesTolerance); - AssertEx.EqualTolerance(LongHundredweightInOneKilogram, kilogram.As(MassUnit.LongHundredweight), LongHundredweightTolerance); - AssertEx.EqualTolerance(LongTonsInOneKilogram, kilogram.As(MassUnit.LongTon), LongTonsTolerance); - AssertEx.EqualTolerance(MegapoundsInOneKilogram, kilogram.As(MassUnit.Megapound), MegapoundsTolerance); - AssertEx.EqualTolerance(MegatonnesInOneKilogram, kilogram.As(MassUnit.Megatonne), MegatonnesTolerance); - AssertEx.EqualTolerance(MicrogramsInOneKilogram, kilogram.As(MassUnit.Microgram), MicrogramsTolerance); - AssertEx.EqualTolerance(MilligramsInOneKilogram, kilogram.As(MassUnit.Milligram), MilligramsTolerance); - AssertEx.EqualTolerance(NanogramsInOneKilogram, kilogram.As(MassUnit.Nanogram), NanogramsTolerance); - AssertEx.EqualTolerance(OuncesInOneKilogram, kilogram.As(MassUnit.Ounce), OuncesTolerance); - AssertEx.EqualTolerance(PoundsInOneKilogram, kilogram.As(MassUnit.Pound), PoundsTolerance); - AssertEx.EqualTolerance(ShortHundredweightInOneKilogram, kilogram.As(MassUnit.ShortHundredweight), ShortHundredweightTolerance); - AssertEx.EqualTolerance(ShortTonsInOneKilogram, kilogram.As(MassUnit.ShortTon), ShortTonsTolerance); - AssertEx.EqualTolerance(SlugsInOneKilogram, kilogram.As(MassUnit.Slug), SlugsTolerance); - AssertEx.EqualTolerance(StoneInOneKilogram, kilogram.As(MassUnit.Stone), StoneTolerance); - AssertEx.EqualTolerance(TonnesInOneKilogram, kilogram.As(MassUnit.Tonne), TonnesTolerance); - } - - [Fact] - public void ToUnit() - { - var kilogram = Mass.FromKilograms(1); - - var centigramQuantity = kilogram.ToUnit(MassUnit.Centigram); - AssertEx.EqualTolerance(CentigramsInOneKilogram, (double)centigramQuantity.Value, CentigramsTolerance); - Assert.Equal(MassUnit.Centigram, centigramQuantity.Unit); - - var decagramQuantity = kilogram.ToUnit(MassUnit.Decagram); - AssertEx.EqualTolerance(DecagramsInOneKilogram, (double)decagramQuantity.Value, DecagramsTolerance); - Assert.Equal(MassUnit.Decagram, decagramQuantity.Unit); - - var decigramQuantity = kilogram.ToUnit(MassUnit.Decigram); - AssertEx.EqualTolerance(DecigramsInOneKilogram, (double)decigramQuantity.Value, DecigramsTolerance); - Assert.Equal(MassUnit.Decigram, decigramQuantity.Unit); - - var gramQuantity = kilogram.ToUnit(MassUnit.Gram); - AssertEx.EqualTolerance(GramsInOneKilogram, (double)gramQuantity.Value, GramsTolerance); - Assert.Equal(MassUnit.Gram, gramQuantity.Unit); - - var hectogramQuantity = kilogram.ToUnit(MassUnit.Hectogram); - AssertEx.EqualTolerance(HectogramsInOneKilogram, (double)hectogramQuantity.Value, HectogramsTolerance); - Assert.Equal(MassUnit.Hectogram, hectogramQuantity.Unit); - - var kilogramQuantity = kilogram.ToUnit(MassUnit.Kilogram); - AssertEx.EqualTolerance(KilogramsInOneKilogram, (double)kilogramQuantity.Value, KilogramsTolerance); - Assert.Equal(MassUnit.Kilogram, kilogramQuantity.Unit); - - var kilopoundQuantity = kilogram.ToUnit(MassUnit.Kilopound); - AssertEx.EqualTolerance(KilopoundsInOneKilogram, (double)kilopoundQuantity.Value, KilopoundsTolerance); - Assert.Equal(MassUnit.Kilopound, kilopoundQuantity.Unit); - - var kilotonneQuantity = kilogram.ToUnit(MassUnit.Kilotonne); - AssertEx.EqualTolerance(KilotonnesInOneKilogram, (double)kilotonneQuantity.Value, KilotonnesTolerance); - Assert.Equal(MassUnit.Kilotonne, kilotonneQuantity.Unit); - - var longhundredweightQuantity = kilogram.ToUnit(MassUnit.LongHundredweight); - AssertEx.EqualTolerance(LongHundredweightInOneKilogram, (double)longhundredweightQuantity.Value, LongHundredweightTolerance); - Assert.Equal(MassUnit.LongHundredweight, longhundredweightQuantity.Unit); - - var longtonQuantity = kilogram.ToUnit(MassUnit.LongTon); - AssertEx.EqualTolerance(LongTonsInOneKilogram, (double)longtonQuantity.Value, LongTonsTolerance); - Assert.Equal(MassUnit.LongTon, longtonQuantity.Unit); - - var megapoundQuantity = kilogram.ToUnit(MassUnit.Megapound); - AssertEx.EqualTolerance(MegapoundsInOneKilogram, (double)megapoundQuantity.Value, MegapoundsTolerance); - Assert.Equal(MassUnit.Megapound, megapoundQuantity.Unit); - - var megatonneQuantity = kilogram.ToUnit(MassUnit.Megatonne); - AssertEx.EqualTolerance(MegatonnesInOneKilogram, (double)megatonneQuantity.Value, MegatonnesTolerance); - Assert.Equal(MassUnit.Megatonne, megatonneQuantity.Unit); - - var microgramQuantity = kilogram.ToUnit(MassUnit.Microgram); - AssertEx.EqualTolerance(MicrogramsInOneKilogram, (double)microgramQuantity.Value, MicrogramsTolerance); - Assert.Equal(MassUnit.Microgram, microgramQuantity.Unit); - - var milligramQuantity = kilogram.ToUnit(MassUnit.Milligram); - AssertEx.EqualTolerance(MilligramsInOneKilogram, (double)milligramQuantity.Value, MilligramsTolerance); - Assert.Equal(MassUnit.Milligram, milligramQuantity.Unit); - - var nanogramQuantity = kilogram.ToUnit(MassUnit.Nanogram); - AssertEx.EqualTolerance(NanogramsInOneKilogram, (double)nanogramQuantity.Value, NanogramsTolerance); - Assert.Equal(MassUnit.Nanogram, nanogramQuantity.Unit); - - var ounceQuantity = kilogram.ToUnit(MassUnit.Ounce); - AssertEx.EqualTolerance(OuncesInOneKilogram, (double)ounceQuantity.Value, OuncesTolerance); - Assert.Equal(MassUnit.Ounce, ounceQuantity.Unit); - - var poundQuantity = kilogram.ToUnit(MassUnit.Pound); - AssertEx.EqualTolerance(PoundsInOneKilogram, (double)poundQuantity.Value, PoundsTolerance); - Assert.Equal(MassUnit.Pound, poundQuantity.Unit); - - var shorthundredweightQuantity = kilogram.ToUnit(MassUnit.ShortHundredweight); - AssertEx.EqualTolerance(ShortHundredweightInOneKilogram, (double)shorthundredweightQuantity.Value, ShortHundredweightTolerance); - Assert.Equal(MassUnit.ShortHundredweight, shorthundredweightQuantity.Unit); - - var shorttonQuantity = kilogram.ToUnit(MassUnit.ShortTon); - AssertEx.EqualTolerance(ShortTonsInOneKilogram, (double)shorttonQuantity.Value, ShortTonsTolerance); - Assert.Equal(MassUnit.ShortTon, shorttonQuantity.Unit); - - var slugQuantity = kilogram.ToUnit(MassUnit.Slug); - AssertEx.EqualTolerance(SlugsInOneKilogram, (double)slugQuantity.Value, SlugsTolerance); - Assert.Equal(MassUnit.Slug, slugQuantity.Unit); - - var stoneQuantity = kilogram.ToUnit(MassUnit.Stone); - AssertEx.EqualTolerance(StoneInOneKilogram, (double)stoneQuantity.Value, StoneTolerance); - Assert.Equal(MassUnit.Stone, stoneQuantity.Unit); - - var tonneQuantity = kilogram.ToUnit(MassUnit.Tonne); - AssertEx.EqualTolerance(TonnesInOneKilogram, (double)tonneQuantity.Value, TonnesTolerance); - Assert.Equal(MassUnit.Tonne, tonneQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Mass kilogram = Mass.FromKilograms(1); - AssertEx.EqualTolerance(1, Mass.FromCentigrams(kilogram.Centigrams).Kilograms, CentigramsTolerance); - AssertEx.EqualTolerance(1, Mass.FromDecagrams(kilogram.Decagrams).Kilograms, DecagramsTolerance); - AssertEx.EqualTolerance(1, Mass.FromDecigrams(kilogram.Decigrams).Kilograms, DecigramsTolerance); - AssertEx.EqualTolerance(1, Mass.FromGrams(kilogram.Grams).Kilograms, GramsTolerance); - AssertEx.EqualTolerance(1, Mass.FromHectograms(kilogram.Hectograms).Kilograms, HectogramsTolerance); - AssertEx.EqualTolerance(1, Mass.FromKilograms(kilogram.Kilograms).Kilograms, KilogramsTolerance); - AssertEx.EqualTolerance(1, Mass.FromKilopounds(kilogram.Kilopounds).Kilograms, KilopoundsTolerance); - AssertEx.EqualTolerance(1, Mass.FromKilotonnes(kilogram.Kilotonnes).Kilograms, KilotonnesTolerance); - AssertEx.EqualTolerance(1, Mass.FromLongHundredweight(kilogram.LongHundredweight).Kilograms, LongHundredweightTolerance); - AssertEx.EqualTolerance(1, Mass.FromLongTons(kilogram.LongTons).Kilograms, LongTonsTolerance); - AssertEx.EqualTolerance(1, Mass.FromMegapounds(kilogram.Megapounds).Kilograms, MegapoundsTolerance); - AssertEx.EqualTolerance(1, Mass.FromMegatonnes(kilogram.Megatonnes).Kilograms, MegatonnesTolerance); - AssertEx.EqualTolerance(1, Mass.FromMicrograms(kilogram.Micrograms).Kilograms, MicrogramsTolerance); - AssertEx.EqualTolerance(1, Mass.FromMilligrams(kilogram.Milligrams).Kilograms, MilligramsTolerance); - AssertEx.EqualTolerance(1, Mass.FromNanograms(kilogram.Nanograms).Kilograms, NanogramsTolerance); - AssertEx.EqualTolerance(1, Mass.FromOunces(kilogram.Ounces).Kilograms, OuncesTolerance); - AssertEx.EqualTolerance(1, Mass.FromPounds(kilogram.Pounds).Kilograms, PoundsTolerance); - AssertEx.EqualTolerance(1, Mass.FromShortHundredweight(kilogram.ShortHundredweight).Kilograms, ShortHundredweightTolerance); - AssertEx.EqualTolerance(1, Mass.FromShortTons(kilogram.ShortTons).Kilograms, ShortTonsTolerance); - AssertEx.EqualTolerance(1, Mass.FromSlugs(kilogram.Slugs).Kilograms, SlugsTolerance); - AssertEx.EqualTolerance(1, Mass.FromStone(kilogram.Stone).Kilograms, StoneTolerance); - AssertEx.EqualTolerance(1, Mass.FromTonnes(kilogram.Tonnes).Kilograms, TonnesTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Mass v = Mass.FromKilograms(1); - AssertEx.EqualTolerance(-1, -v.Kilograms, KilogramsTolerance); - AssertEx.EqualTolerance(2, (Mass.FromKilograms(3)-v).Kilograms, KilogramsTolerance); - AssertEx.EqualTolerance(2, (v + v).Kilograms, KilogramsTolerance); - AssertEx.EqualTolerance(10, (v*10).Kilograms, KilogramsTolerance); - AssertEx.EqualTolerance(10, (10*v).Kilograms, KilogramsTolerance); - AssertEx.EqualTolerance(2, (Mass.FromKilograms(10)/5).Kilograms, KilogramsTolerance); - AssertEx.EqualTolerance(2, Mass.FromKilograms(10)/Mass.FromKilograms(5), KilogramsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Mass oneKilogram = Mass.FromKilograms(1); - Mass twoKilograms = Mass.FromKilograms(2); - - Assert.True(oneKilogram < twoKilograms); - Assert.True(oneKilogram <= twoKilograms); - Assert.True(twoKilograms > oneKilogram); - Assert.True(twoKilograms >= oneKilogram); - - Assert.False(oneKilogram > twoKilograms); - Assert.False(oneKilogram >= twoKilograms); - Assert.False(twoKilograms < oneKilogram); - Assert.False(twoKilograms <= oneKilogram); - } - - [Fact] - public void CompareToIsImplemented() - { - Mass kilogram = Mass.FromKilograms(1); - Assert.Equal(0, kilogram.CompareTo(kilogram)); - Assert.True(kilogram.CompareTo(Mass.Zero) > 0); - Assert.True(Mass.Zero.CompareTo(kilogram) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Mass kilogram = Mass.FromKilograms(1); - Assert.Throws(() => kilogram.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Mass kilogram = Mass.FromKilograms(1); - Assert.Throws(() => kilogram.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Mass v = Mass.FromKilograms(1); - Assert.True(v.Equals(Mass.FromKilograms(1), KilogramsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Mass.Zero, KilogramsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Mass kilogram = Mass.FromKilograms(1); - Assert.False(kilogram.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Mass kilogram = Mass.FromKilograms(1); - Assert.False(kilogram.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MassUnit.Undefined, Mass.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MassUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MassUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MolarEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MolarEnergyTestsBase.g.cs deleted file mode 100644 index 96940b97aa..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MolarEnergyTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of MolarEnergy. - /// -// 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 Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new MolarEnergy((double)0.0, MolarEnergyUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new MolarEnergy(double.PositiveInfinity, MolarEnergyUnit.JoulePerMole)); - Assert.Throws(() => new MolarEnergy(double.NegativeInfinity, MolarEnergyUnit.JoulePerMole)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new MolarEnergy(double.NaN, MolarEnergyUnit.JoulePerMole)); - } - - [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 FromJoulesPerMole_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => MolarEnergy.FromJoulesPerMole(double.PositiveInfinity)); - Assert.Throws(() => MolarEnergy.FromJoulesPerMole(double.NegativeInfinity)); - } - - [Fact] - public void FromJoulesPerMole_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => MolarEnergy.FromJoulesPerMole(double.NaN)); - } - - [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 ToUnit() - { - var joulepermole = MolarEnergy.FromJoulesPerMole(1); - - var joulepermoleQuantity = joulepermole.ToUnit(MolarEnergyUnit.JoulePerMole); - AssertEx.EqualTolerance(JoulesPerMoleInOneJoulePerMole, (double)joulepermoleQuantity.Value, JoulesPerMoleTolerance); - Assert.Equal(MolarEnergyUnit.JoulePerMole, joulepermoleQuantity.Unit); - - var kilojoulepermoleQuantity = joulepermole.ToUnit(MolarEnergyUnit.KilojoulePerMole); - AssertEx.EqualTolerance(KilojoulesPerMoleInOneJoulePerMole, (double)kilojoulepermoleQuantity.Value, KilojoulesPerMoleTolerance); - Assert.Equal(MolarEnergyUnit.KilojoulePerMole, kilojoulepermoleQuantity.Unit); - - var megajoulepermoleQuantity = joulepermole.ToUnit(MolarEnergyUnit.MegajoulePerMole); - AssertEx.EqualTolerance(MegajoulesPerMoleInOneJoulePerMole, (double)megajoulepermoleQuantity.Value, MegajoulesPerMoleTolerance); - Assert.Equal(MolarEnergyUnit.MegajoulePerMole, megajoulepermoleQuantity.Unit); - } - - [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(() => joulepermole.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1); - Assert.Throws(() => joulepermole.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - MolarEnergy v = MolarEnergy.FromJoulesPerMole(1); - Assert.True(v.Equals(MolarEnergy.FromJoulesPerMole(1), JoulesPerMoleTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(MolarEnergy.Zero, JoulesPerMoleTolerance, ComparisonType.Relative)); - } - - [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)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MolarEnergyUnit.Undefined, MolarEnergy.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MolarEnergyUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MolarEnergyUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MolarEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MolarEntropyTestsBase.g.cs deleted file mode 100644 index c7ad28d7cd..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MolarEntropyTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of MolarEntropy. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MolarEntropyTestsBase - { - protected abstract double JoulesPerMoleKelvinInOneJoulePerMoleKelvin { get; } - protected abstract double KilojoulesPerMoleKelvinInOneJoulePerMoleKelvin { get; } - protected abstract double MegajoulesPerMoleKelvinInOneJoulePerMoleKelvin { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double JoulesPerMoleKelvinTolerance { get { return 1e-5; } } - protected virtual double KilojoulesPerMoleKelvinTolerance { get { return 1e-5; } } - protected virtual double MegajoulesPerMoleKelvinTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new MolarEntropy((double)0.0, MolarEntropyUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new MolarEntropy(double.PositiveInfinity, MolarEntropyUnit.JoulePerMoleKelvin)); - Assert.Throws(() => new MolarEntropy(double.NegativeInfinity, MolarEntropyUnit.JoulePerMoleKelvin)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new MolarEntropy(double.NaN, MolarEntropyUnit.JoulePerMoleKelvin)); - } - - [Fact] - public void JoulePerMoleKelvinToMolarEntropyUnits() - { - MolarEntropy joulepermolekelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - AssertEx.EqualTolerance(JoulesPerMoleKelvinInOneJoulePerMoleKelvin, joulepermolekelvin.JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(KilojoulesPerMoleKelvinInOneJoulePerMoleKelvin, joulepermolekelvin.KilojoulesPerMoleKelvin, KilojoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(MegajoulesPerMoleKelvinInOneJoulePerMoleKelvin, joulepermolekelvin.MegajoulesPerMoleKelvin, MegajoulesPerMoleKelvinTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, MolarEntropy.From(1, MolarEntropyUnit.JoulePerMoleKelvin).JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(1, MolarEntropy.From(1, MolarEntropyUnit.KilojoulePerMoleKelvin).KilojoulesPerMoleKelvin, KilojoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(1, MolarEntropy.From(1, MolarEntropyUnit.MegajoulePerMoleKelvin).MegajoulesPerMoleKelvin, MegajoulesPerMoleKelvinTolerance); - } - - [Fact] - public void FromJoulesPerMoleKelvin_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => MolarEntropy.FromJoulesPerMoleKelvin(double.PositiveInfinity)); - Assert.Throws(() => MolarEntropy.FromJoulesPerMoleKelvin(double.NegativeInfinity)); - } - - [Fact] - public void FromJoulesPerMoleKelvin_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => MolarEntropy.FromJoulesPerMoleKelvin(double.NaN)); - } - - [Fact] - public void As() - { - var joulepermolekelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - AssertEx.EqualTolerance(JoulesPerMoleKelvinInOneJoulePerMoleKelvin, joulepermolekelvin.As(MolarEntropyUnit.JoulePerMoleKelvin), JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(KilojoulesPerMoleKelvinInOneJoulePerMoleKelvin, joulepermolekelvin.As(MolarEntropyUnit.KilojoulePerMoleKelvin), KilojoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(MegajoulesPerMoleKelvinInOneJoulePerMoleKelvin, joulepermolekelvin.As(MolarEntropyUnit.MegajoulePerMoleKelvin), MegajoulesPerMoleKelvinTolerance); - } - - [Fact] - public void ToUnit() - { - var joulepermolekelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - - var joulepermolekelvinQuantity = joulepermolekelvin.ToUnit(MolarEntropyUnit.JoulePerMoleKelvin); - AssertEx.EqualTolerance(JoulesPerMoleKelvinInOneJoulePerMoleKelvin, (double)joulepermolekelvinQuantity.Value, JoulesPerMoleKelvinTolerance); - Assert.Equal(MolarEntropyUnit.JoulePerMoleKelvin, joulepermolekelvinQuantity.Unit); - - var kilojoulepermolekelvinQuantity = joulepermolekelvin.ToUnit(MolarEntropyUnit.KilojoulePerMoleKelvin); - AssertEx.EqualTolerance(KilojoulesPerMoleKelvinInOneJoulePerMoleKelvin, (double)kilojoulepermolekelvinQuantity.Value, KilojoulesPerMoleKelvinTolerance); - Assert.Equal(MolarEntropyUnit.KilojoulePerMoleKelvin, kilojoulepermolekelvinQuantity.Unit); - - var megajoulepermolekelvinQuantity = joulepermolekelvin.ToUnit(MolarEntropyUnit.MegajoulePerMoleKelvin); - AssertEx.EqualTolerance(MegajoulesPerMoleKelvinInOneJoulePerMoleKelvin, (double)megajoulepermolekelvinQuantity.Value, MegajoulesPerMoleKelvinTolerance); - Assert.Equal(MolarEntropyUnit.MegajoulePerMoleKelvin, megajoulepermolekelvinQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - MolarEntropy joulepermolekelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - AssertEx.EqualTolerance(1, MolarEntropy.FromJoulesPerMoleKelvin(joulepermolekelvin.JoulesPerMoleKelvin).JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(1, MolarEntropy.FromKilojoulesPerMoleKelvin(joulepermolekelvin.KilojoulesPerMoleKelvin).JoulesPerMoleKelvin, KilojoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(1, MolarEntropy.FromMegajoulesPerMoleKelvin(joulepermolekelvin.MegajoulesPerMoleKelvin).JoulesPerMoleKelvin, MegajoulesPerMoleKelvinTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - MolarEntropy v = MolarEntropy.FromJoulesPerMoleKelvin(1); - AssertEx.EqualTolerance(-1, -v.JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(2, (MolarEntropy.FromJoulesPerMoleKelvin(3)-v).JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(2, (v + v).JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(10, (v*10).JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(10, (10*v).JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(2, (MolarEntropy.FromJoulesPerMoleKelvin(10)/5).JoulesPerMoleKelvin, JoulesPerMoleKelvinTolerance); - AssertEx.EqualTolerance(2, MolarEntropy.FromJoulesPerMoleKelvin(10)/MolarEntropy.FromJoulesPerMoleKelvin(5), JoulesPerMoleKelvinTolerance); - } - - [Fact] - public void ComparisonOperators() - { - MolarEntropy oneJoulePerMoleKelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - MolarEntropy twoJoulesPerMoleKelvin = MolarEntropy.FromJoulesPerMoleKelvin(2); - - Assert.True(oneJoulePerMoleKelvin < twoJoulesPerMoleKelvin); - Assert.True(oneJoulePerMoleKelvin <= twoJoulesPerMoleKelvin); - Assert.True(twoJoulesPerMoleKelvin > oneJoulePerMoleKelvin); - Assert.True(twoJoulesPerMoleKelvin >= oneJoulePerMoleKelvin); - - Assert.False(oneJoulePerMoleKelvin > twoJoulesPerMoleKelvin); - Assert.False(oneJoulePerMoleKelvin >= twoJoulesPerMoleKelvin); - Assert.False(twoJoulesPerMoleKelvin < oneJoulePerMoleKelvin); - Assert.False(twoJoulesPerMoleKelvin <= oneJoulePerMoleKelvin); - } - - [Fact] - public void CompareToIsImplemented() - { - MolarEntropy joulepermolekelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - Assert.Equal(0, joulepermolekelvin.CompareTo(joulepermolekelvin)); - Assert.True(joulepermolekelvin.CompareTo(MolarEntropy.Zero) > 0); - Assert.True(MolarEntropy.Zero.CompareTo(joulepermolekelvin) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - MolarEntropy joulepermolekelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - Assert.Throws(() => joulepermolekelvin.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - MolarEntropy joulepermolekelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - Assert.Throws(() => joulepermolekelvin.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - MolarEntropy v = MolarEntropy.FromJoulesPerMoleKelvin(1); - Assert.True(v.Equals(MolarEntropy.FromJoulesPerMoleKelvin(1), JoulesPerMoleKelvinTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(MolarEntropy.Zero, JoulesPerMoleKelvinTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - MolarEntropy joulepermolekelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - Assert.False(joulepermolekelvin.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - MolarEntropy joulepermolekelvin = MolarEntropy.FromJoulesPerMoleKelvin(1); - Assert.False(joulepermolekelvin.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MolarEntropyUnit.Undefined, MolarEntropy.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MolarEntropyUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MolarEntropyUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MolarMassTestsBase.g.cs deleted file mode 100644 index b52831982c..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MolarMassTestsBase.g.cs +++ /dev/null @@ -1,334 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of MolarMass. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MolarMassTestsBase - { - protected abstract double CentigramsPerMoleInOneKilogramPerMole { get; } - protected abstract double DecagramsPerMoleInOneKilogramPerMole { get; } - protected abstract double DecigramsPerMoleInOneKilogramPerMole { get; } - protected abstract double GramsPerMoleInOneKilogramPerMole { get; } - protected abstract double HectogramsPerMoleInOneKilogramPerMole { get; } - protected abstract double KilogramsPerMoleInOneKilogramPerMole { get; } - protected abstract double KilopoundsPerMoleInOneKilogramPerMole { get; } - protected abstract double MegapoundsPerMoleInOneKilogramPerMole { get; } - protected abstract double MicrogramsPerMoleInOneKilogramPerMole { get; } - protected abstract double MilligramsPerMoleInOneKilogramPerMole { get; } - protected abstract double NanogramsPerMoleInOneKilogramPerMole { get; } - protected abstract double PoundsPerMoleInOneKilogramPerMole { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentigramsPerMoleTolerance { get { return 1e-5; } } - protected virtual double DecagramsPerMoleTolerance { get { return 1e-5; } } - protected virtual double DecigramsPerMoleTolerance { get { return 1e-5; } } - protected virtual double GramsPerMoleTolerance { get { return 1e-5; } } - protected virtual double HectogramsPerMoleTolerance { get { return 1e-5; } } - protected virtual double KilogramsPerMoleTolerance { get { return 1e-5; } } - protected virtual double KilopoundsPerMoleTolerance { get { return 1e-5; } } - protected virtual double MegapoundsPerMoleTolerance { get { return 1e-5; } } - protected virtual double MicrogramsPerMoleTolerance { get { return 1e-5; } } - protected virtual double MilligramsPerMoleTolerance { get { return 1e-5; } } - protected virtual double NanogramsPerMoleTolerance { get { return 1e-5; } } - protected virtual double PoundsPerMoleTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new MolarMass((double)0.0, MolarMassUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new MolarMass(double.PositiveInfinity, MolarMassUnit.KilogramPerMole)); - Assert.Throws(() => new MolarMass(double.NegativeInfinity, MolarMassUnit.KilogramPerMole)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new MolarMass(double.NaN, MolarMassUnit.KilogramPerMole)); - } - - [Fact] - public void KilogramPerMoleToMolarMassUnits() - { - MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1); - AssertEx.EqualTolerance(CentigramsPerMoleInOneKilogramPerMole, kilogrampermole.CentigramsPerMole, CentigramsPerMoleTolerance); - AssertEx.EqualTolerance(DecagramsPerMoleInOneKilogramPerMole, kilogrampermole.DecagramsPerMole, DecagramsPerMoleTolerance); - AssertEx.EqualTolerance(DecigramsPerMoleInOneKilogramPerMole, kilogrampermole.DecigramsPerMole, DecigramsPerMoleTolerance); - AssertEx.EqualTolerance(GramsPerMoleInOneKilogramPerMole, kilogrampermole.GramsPerMole, GramsPerMoleTolerance); - AssertEx.EqualTolerance(HectogramsPerMoleInOneKilogramPerMole, kilogrampermole.HectogramsPerMole, HectogramsPerMoleTolerance); - AssertEx.EqualTolerance(KilogramsPerMoleInOneKilogramPerMole, kilogrampermole.KilogramsPerMole, KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(KilopoundsPerMoleInOneKilogramPerMole, kilogrampermole.KilopoundsPerMole, KilopoundsPerMoleTolerance); - AssertEx.EqualTolerance(MegapoundsPerMoleInOneKilogramPerMole, kilogrampermole.MegapoundsPerMole, MegapoundsPerMoleTolerance); - AssertEx.EqualTolerance(MicrogramsPerMoleInOneKilogramPerMole, kilogrampermole.MicrogramsPerMole, MicrogramsPerMoleTolerance); - AssertEx.EqualTolerance(MilligramsPerMoleInOneKilogramPerMole, kilogrampermole.MilligramsPerMole, MilligramsPerMoleTolerance); - AssertEx.EqualTolerance(NanogramsPerMoleInOneKilogramPerMole, kilogrampermole.NanogramsPerMole, NanogramsPerMoleTolerance); - AssertEx.EqualTolerance(PoundsPerMoleInOneKilogramPerMole, kilogrampermole.PoundsPerMole, PoundsPerMoleTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.CentigramPerMole).CentigramsPerMole, CentigramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.DecagramPerMole).DecagramsPerMole, DecagramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.DecigramPerMole).DecigramsPerMole, DecigramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.GramPerMole).GramsPerMole, GramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.HectogramPerMole).HectogramsPerMole, HectogramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.KilogramPerMole).KilogramsPerMole, KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.KilopoundPerMole).KilopoundsPerMole, KilopoundsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.MegapoundPerMole).MegapoundsPerMole, MegapoundsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.MicrogramPerMole).MicrogramsPerMole, MicrogramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.MilligramPerMole).MilligramsPerMole, MilligramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.NanogramPerMole).NanogramsPerMole, NanogramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.PoundPerMole).PoundsPerMole, PoundsPerMoleTolerance); - } - - [Fact] - public void FromKilogramsPerMole_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => MolarMass.FromKilogramsPerMole(double.PositiveInfinity)); - Assert.Throws(() => MolarMass.FromKilogramsPerMole(double.NegativeInfinity)); - } - - [Fact] - public void FromKilogramsPerMole_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => MolarMass.FromKilogramsPerMole(double.NaN)); - } - - [Fact] - public void As() - { - var kilogrampermole = MolarMass.FromKilogramsPerMole(1); - AssertEx.EqualTolerance(CentigramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.CentigramPerMole), CentigramsPerMoleTolerance); - AssertEx.EqualTolerance(DecagramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.DecagramPerMole), DecagramsPerMoleTolerance); - AssertEx.EqualTolerance(DecigramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.DecigramPerMole), DecigramsPerMoleTolerance); - AssertEx.EqualTolerance(GramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.GramPerMole), GramsPerMoleTolerance); - AssertEx.EqualTolerance(HectogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.HectogramPerMole), HectogramsPerMoleTolerance); - AssertEx.EqualTolerance(KilogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.KilogramPerMole), KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(KilopoundsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.KilopoundPerMole), KilopoundsPerMoleTolerance); - AssertEx.EqualTolerance(MegapoundsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.MegapoundPerMole), MegapoundsPerMoleTolerance); - AssertEx.EqualTolerance(MicrogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.MicrogramPerMole), MicrogramsPerMoleTolerance); - AssertEx.EqualTolerance(MilligramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.MilligramPerMole), MilligramsPerMoleTolerance); - AssertEx.EqualTolerance(NanogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.NanogramPerMole), NanogramsPerMoleTolerance); - AssertEx.EqualTolerance(PoundsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.PoundPerMole), PoundsPerMoleTolerance); - } - - [Fact] - public void ToUnit() - { - var kilogrampermole = MolarMass.FromKilogramsPerMole(1); - - var centigrampermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.CentigramPerMole); - AssertEx.EqualTolerance(CentigramsPerMoleInOneKilogramPerMole, (double)centigrampermoleQuantity.Value, CentigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.CentigramPerMole, centigrampermoleQuantity.Unit); - - var decagrampermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.DecagramPerMole); - AssertEx.EqualTolerance(DecagramsPerMoleInOneKilogramPerMole, (double)decagrampermoleQuantity.Value, DecagramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecagramPerMole, decagrampermoleQuantity.Unit); - - var decigrampermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.DecigramPerMole); - AssertEx.EqualTolerance(DecigramsPerMoleInOneKilogramPerMole, (double)decigrampermoleQuantity.Value, DecigramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.DecigramPerMole, decigrampermoleQuantity.Unit); - - var grampermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.GramPerMole); - AssertEx.EqualTolerance(GramsPerMoleInOneKilogramPerMole, (double)grampermoleQuantity.Value, GramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.GramPerMole, grampermoleQuantity.Unit); - - var hectogrampermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.HectogramPerMole); - AssertEx.EqualTolerance(HectogramsPerMoleInOneKilogramPerMole, (double)hectogrampermoleQuantity.Value, HectogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.HectogramPerMole, hectogrampermoleQuantity.Unit); - - var kilogrampermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.KilogramPerMole); - AssertEx.EqualTolerance(KilogramsPerMoleInOneKilogramPerMole, (double)kilogrampermoleQuantity.Value, KilogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilogramPerMole, kilogrampermoleQuantity.Unit); - - var kilopoundpermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.KilopoundPerMole); - AssertEx.EqualTolerance(KilopoundsPerMoleInOneKilogramPerMole, (double)kilopoundpermoleQuantity.Value, KilopoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.KilopoundPerMole, kilopoundpermoleQuantity.Unit); - - var megapoundpermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.MegapoundPerMole); - AssertEx.EqualTolerance(MegapoundsPerMoleInOneKilogramPerMole, (double)megapoundpermoleQuantity.Value, MegapoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MegapoundPerMole, megapoundpermoleQuantity.Unit); - - var microgrampermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.MicrogramPerMole); - AssertEx.EqualTolerance(MicrogramsPerMoleInOneKilogramPerMole, (double)microgrampermoleQuantity.Value, MicrogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MicrogramPerMole, microgrampermoleQuantity.Unit); - - var milligrampermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.MilligramPerMole); - AssertEx.EqualTolerance(MilligramsPerMoleInOneKilogramPerMole, (double)milligrampermoleQuantity.Value, MilligramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.MilligramPerMole, milligrampermoleQuantity.Unit); - - var nanogrampermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.NanogramPerMole); - AssertEx.EqualTolerance(NanogramsPerMoleInOneKilogramPerMole, (double)nanogrampermoleQuantity.Value, NanogramsPerMoleTolerance); - Assert.Equal(MolarMassUnit.NanogramPerMole, nanogrampermoleQuantity.Unit); - - var poundpermoleQuantity = kilogrampermole.ToUnit(MolarMassUnit.PoundPerMole); - AssertEx.EqualTolerance(PoundsPerMoleInOneKilogramPerMole, (double)poundpermoleQuantity.Value, PoundsPerMoleTolerance); - Assert.Equal(MolarMassUnit.PoundPerMole, poundpermoleQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1); - AssertEx.EqualTolerance(1, MolarMass.FromCentigramsPerMole(kilogrampermole.CentigramsPerMole).KilogramsPerMole, CentigramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromDecagramsPerMole(kilogrampermole.DecagramsPerMole).KilogramsPerMole, DecagramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromDecigramsPerMole(kilogrampermole.DecigramsPerMole).KilogramsPerMole, DecigramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromGramsPerMole(kilogrampermole.GramsPerMole).KilogramsPerMole, GramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromHectogramsPerMole(kilogrampermole.HectogramsPerMole).KilogramsPerMole, HectogramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromKilogramsPerMole(kilogrampermole.KilogramsPerMole).KilogramsPerMole, KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromKilopoundsPerMole(kilogrampermole.KilopoundsPerMole).KilogramsPerMole, KilopoundsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromMegapoundsPerMole(kilogrampermole.MegapoundsPerMole).KilogramsPerMole, MegapoundsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromMicrogramsPerMole(kilogrampermole.MicrogramsPerMole).KilogramsPerMole, MicrogramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromMilligramsPerMole(kilogrampermole.MilligramsPerMole).KilogramsPerMole, MilligramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromNanogramsPerMole(kilogrampermole.NanogramsPerMole).KilogramsPerMole, NanogramsPerMoleTolerance); - AssertEx.EqualTolerance(1, MolarMass.FromPoundsPerMole(kilogrampermole.PoundsPerMole).KilogramsPerMole, PoundsPerMoleTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - MolarMass v = MolarMass.FromKilogramsPerMole(1); - AssertEx.EqualTolerance(-1, -v.KilogramsPerMole, KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(2, (MolarMass.FromKilogramsPerMole(3)-v).KilogramsPerMole, KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(2, (v + v).KilogramsPerMole, KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(10, (v*10).KilogramsPerMole, KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(10, (10*v).KilogramsPerMole, KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(2, (MolarMass.FromKilogramsPerMole(10)/5).KilogramsPerMole, KilogramsPerMoleTolerance); - AssertEx.EqualTolerance(2, MolarMass.FromKilogramsPerMole(10)/MolarMass.FromKilogramsPerMole(5), KilogramsPerMoleTolerance); - } - - [Fact] - public void ComparisonOperators() - { - MolarMass oneKilogramPerMole = MolarMass.FromKilogramsPerMole(1); - MolarMass twoKilogramsPerMole = MolarMass.FromKilogramsPerMole(2); - - Assert.True(oneKilogramPerMole < twoKilogramsPerMole); - Assert.True(oneKilogramPerMole <= twoKilogramsPerMole); - Assert.True(twoKilogramsPerMole > oneKilogramPerMole); - Assert.True(twoKilogramsPerMole >= oneKilogramPerMole); - - Assert.False(oneKilogramPerMole > twoKilogramsPerMole); - Assert.False(oneKilogramPerMole >= twoKilogramsPerMole); - Assert.False(twoKilogramsPerMole < oneKilogramPerMole); - Assert.False(twoKilogramsPerMole <= oneKilogramPerMole); - } - - [Fact] - public void CompareToIsImplemented() - { - MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1); - Assert.Equal(0, kilogrampermole.CompareTo(kilogrampermole)); - Assert.True(kilogrampermole.CompareTo(MolarMass.Zero) > 0); - Assert.True(MolarMass.Zero.CompareTo(kilogrampermole) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1); - Assert.Throws(() => kilogrampermole.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1); - Assert.Throws(() => kilogrampermole.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - MolarMass v = MolarMass.FromKilogramsPerMole(1); - Assert.True(v.Equals(MolarMass.FromKilogramsPerMole(1), KilogramsPerMoleTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(MolarMass.Zero, KilogramsPerMoleTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1); - Assert.False(kilogrampermole.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1); - Assert.False(kilogrampermole.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MolarMassUnit.Undefined, MolarMass.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MolarMassUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MolarMassUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/MolarityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MolarityTestsBase.g.cs deleted file mode 100644 index a8fe1eed37..0000000000 --- a/UnitsNet.Tests/GeneratedCode/MolarityTestsBase.g.cs +++ /dev/null @@ -1,294 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Molarity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MolarityTestsBase - { - protected abstract double CentimolesPerLiterInOneMolesPerCubicMeter { get; } - protected abstract double DecimolesPerLiterInOneMolesPerCubicMeter { get; } - protected abstract double MicromolesPerLiterInOneMolesPerCubicMeter { get; } - protected abstract double MillimolesPerLiterInOneMolesPerCubicMeter { get; } - protected abstract double MolesPerCubicMeterInOneMolesPerCubicMeter { get; } - protected abstract double MolesPerLiterInOneMolesPerCubicMeter { get; } - protected abstract double NanomolesPerLiterInOneMolesPerCubicMeter { get; } - protected abstract double PicomolesPerLiterInOneMolesPerCubicMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentimolesPerLiterTolerance { get { return 1e-5; } } - protected virtual double DecimolesPerLiterTolerance { get { return 1e-5; } } - protected virtual double MicromolesPerLiterTolerance { get { return 1e-5; } } - protected virtual double MillimolesPerLiterTolerance { get { return 1e-5; } } - protected virtual double MolesPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double MolesPerLiterTolerance { get { return 1e-5; } } - protected virtual double NanomolesPerLiterTolerance { get { return 1e-5; } } - protected virtual double PicomolesPerLiterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Molarity((double)0.0, MolarityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Molarity(double.PositiveInfinity, MolarityUnit.MolesPerCubicMeter)); - Assert.Throws(() => new Molarity(double.NegativeInfinity, MolarityUnit.MolesPerCubicMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Molarity(double.NaN, MolarityUnit.MolesPerCubicMeter)); - } - - [Fact] - public void MolesPerCubicMeterToMolarityUnits() - { - Molarity molespercubicmeter = Molarity.FromMolesPerCubicMeter(1); - AssertEx.EqualTolerance(CentimolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.CentimolesPerLiter, CentimolesPerLiterTolerance); - AssertEx.EqualTolerance(DecimolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.DecimolesPerLiter, DecimolesPerLiterTolerance); - AssertEx.EqualTolerance(MicromolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.MicromolesPerLiter, MicromolesPerLiterTolerance); - AssertEx.EqualTolerance(MillimolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.MillimolesPerLiter, MillimolesPerLiterTolerance); - AssertEx.EqualTolerance(MolesPerCubicMeterInOneMolesPerCubicMeter, molespercubicmeter.MolesPerCubicMeter, MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(MolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.MolesPerLiter, MolesPerLiterTolerance); - AssertEx.EqualTolerance(NanomolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.NanomolesPerLiter, NanomolesPerLiterTolerance); - AssertEx.EqualTolerance(PicomolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.PicomolesPerLiter, PicomolesPerLiterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Molarity.From(1, MolarityUnit.CentimolesPerLiter).CentimolesPerLiter, CentimolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.From(1, MolarityUnit.DecimolesPerLiter).DecimolesPerLiter, DecimolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.From(1, MolarityUnit.MicromolesPerLiter).MicromolesPerLiter, MicromolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.From(1, MolarityUnit.MillimolesPerLiter).MillimolesPerLiter, MillimolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.From(1, MolarityUnit.MolesPerCubicMeter).MolesPerCubicMeter, MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Molarity.From(1, MolarityUnit.MolesPerLiter).MolesPerLiter, MolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.From(1, MolarityUnit.NanomolesPerLiter).NanomolesPerLiter, NanomolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.From(1, MolarityUnit.PicomolesPerLiter).PicomolesPerLiter, PicomolesPerLiterTolerance); - } - - [Fact] - public void FromMolesPerCubicMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Molarity.FromMolesPerCubicMeter(double.PositiveInfinity)); - Assert.Throws(() => Molarity.FromMolesPerCubicMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromMolesPerCubicMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Molarity.FromMolesPerCubicMeter(double.NaN)); - } - - [Fact] - public void As() - { - var molespercubicmeter = Molarity.FromMolesPerCubicMeter(1); - AssertEx.EqualTolerance(CentimolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.As(MolarityUnit.CentimolesPerLiter), CentimolesPerLiterTolerance); - AssertEx.EqualTolerance(DecimolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.As(MolarityUnit.DecimolesPerLiter), DecimolesPerLiterTolerance); - AssertEx.EqualTolerance(MicromolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.As(MolarityUnit.MicromolesPerLiter), MicromolesPerLiterTolerance); - AssertEx.EqualTolerance(MillimolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.As(MolarityUnit.MillimolesPerLiter), MillimolesPerLiterTolerance); - AssertEx.EqualTolerance(MolesPerCubicMeterInOneMolesPerCubicMeter, molespercubicmeter.As(MolarityUnit.MolesPerCubicMeter), MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(MolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.As(MolarityUnit.MolesPerLiter), MolesPerLiterTolerance); - AssertEx.EqualTolerance(NanomolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.As(MolarityUnit.NanomolesPerLiter), NanomolesPerLiterTolerance); - AssertEx.EqualTolerance(PicomolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.As(MolarityUnit.PicomolesPerLiter), PicomolesPerLiterTolerance); - } - - [Fact] - public void ToUnit() - { - var molespercubicmeter = Molarity.FromMolesPerCubicMeter(1); - - var centimolesperliterQuantity = molespercubicmeter.ToUnit(MolarityUnit.CentimolesPerLiter); - AssertEx.EqualTolerance(CentimolesPerLiterInOneMolesPerCubicMeter, (double)centimolesperliterQuantity.Value, CentimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.CentimolesPerLiter, centimolesperliterQuantity.Unit); - - var decimolesperliterQuantity = molespercubicmeter.ToUnit(MolarityUnit.DecimolesPerLiter); - AssertEx.EqualTolerance(DecimolesPerLiterInOneMolesPerCubicMeter, (double)decimolesperliterQuantity.Value, DecimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.DecimolesPerLiter, decimolesperliterQuantity.Unit); - - var micromolesperliterQuantity = molespercubicmeter.ToUnit(MolarityUnit.MicromolesPerLiter); - AssertEx.EqualTolerance(MicromolesPerLiterInOneMolesPerCubicMeter, (double)micromolesperliterQuantity.Value, MicromolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MicromolesPerLiter, micromolesperliterQuantity.Unit); - - var millimolesperliterQuantity = molespercubicmeter.ToUnit(MolarityUnit.MillimolesPerLiter); - AssertEx.EqualTolerance(MillimolesPerLiterInOneMolesPerCubicMeter, (double)millimolesperliterQuantity.Value, MillimolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MillimolesPerLiter, millimolesperliterQuantity.Unit); - - var molespercubicmeterQuantity = molespercubicmeter.ToUnit(MolarityUnit.MolesPerCubicMeter); - AssertEx.EqualTolerance(MolesPerCubicMeterInOneMolesPerCubicMeter, (double)molespercubicmeterQuantity.Value, MolesPerCubicMeterTolerance); - Assert.Equal(MolarityUnit.MolesPerCubicMeter, molespercubicmeterQuantity.Unit); - - var molesperliterQuantity = molespercubicmeter.ToUnit(MolarityUnit.MolesPerLiter); - AssertEx.EqualTolerance(MolesPerLiterInOneMolesPerCubicMeter, (double)molesperliterQuantity.Value, MolesPerLiterTolerance); - Assert.Equal(MolarityUnit.MolesPerLiter, molesperliterQuantity.Unit); - - var nanomolesperliterQuantity = molespercubicmeter.ToUnit(MolarityUnit.NanomolesPerLiter); - AssertEx.EqualTolerance(NanomolesPerLiterInOneMolesPerCubicMeter, (double)nanomolesperliterQuantity.Value, NanomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.NanomolesPerLiter, nanomolesperliterQuantity.Unit); - - var picomolesperliterQuantity = molespercubicmeter.ToUnit(MolarityUnit.PicomolesPerLiter); - AssertEx.EqualTolerance(PicomolesPerLiterInOneMolesPerCubicMeter, (double)picomolesperliterQuantity.Value, PicomolesPerLiterTolerance); - Assert.Equal(MolarityUnit.PicomolesPerLiter, picomolesperliterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Molarity molespercubicmeter = Molarity.FromMolesPerCubicMeter(1); - AssertEx.EqualTolerance(1, Molarity.FromCentimolesPerLiter(molespercubicmeter.CentimolesPerLiter).MolesPerCubicMeter, CentimolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.FromDecimolesPerLiter(molespercubicmeter.DecimolesPerLiter).MolesPerCubicMeter, DecimolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.FromMicromolesPerLiter(molespercubicmeter.MicromolesPerLiter).MolesPerCubicMeter, MicromolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.FromMillimolesPerLiter(molespercubicmeter.MillimolesPerLiter).MolesPerCubicMeter, MillimolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.FromMolesPerCubicMeter(molespercubicmeter.MolesPerCubicMeter).MolesPerCubicMeter, MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, Molarity.FromMolesPerLiter(molespercubicmeter.MolesPerLiter).MolesPerCubicMeter, MolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.FromNanomolesPerLiter(molespercubicmeter.NanomolesPerLiter).MolesPerCubicMeter, NanomolesPerLiterTolerance); - AssertEx.EqualTolerance(1, Molarity.FromPicomolesPerLiter(molespercubicmeter.PicomolesPerLiter).MolesPerCubicMeter, PicomolesPerLiterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Molarity v = Molarity.FromMolesPerCubicMeter(1); - AssertEx.EqualTolerance(-1, -v.MolesPerCubicMeter, MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (Molarity.FromMolesPerCubicMeter(3)-v).MolesPerCubicMeter, MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).MolesPerCubicMeter, MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).MolesPerCubicMeter, MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).MolesPerCubicMeter, MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (Molarity.FromMolesPerCubicMeter(10)/5).MolesPerCubicMeter, MolesPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, Molarity.FromMolesPerCubicMeter(10)/Molarity.FromMolesPerCubicMeter(5), MolesPerCubicMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Molarity oneMolesPerCubicMeter = Molarity.FromMolesPerCubicMeter(1); - Molarity twoMolesPerCubicMeter = Molarity.FromMolesPerCubicMeter(2); - - Assert.True(oneMolesPerCubicMeter < twoMolesPerCubicMeter); - Assert.True(oneMolesPerCubicMeter <= twoMolesPerCubicMeter); - Assert.True(twoMolesPerCubicMeter > oneMolesPerCubicMeter); - Assert.True(twoMolesPerCubicMeter >= oneMolesPerCubicMeter); - - Assert.False(oneMolesPerCubicMeter > twoMolesPerCubicMeter); - Assert.False(oneMolesPerCubicMeter >= twoMolesPerCubicMeter); - Assert.False(twoMolesPerCubicMeter < oneMolesPerCubicMeter); - Assert.False(twoMolesPerCubicMeter <= oneMolesPerCubicMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Molarity molespercubicmeter = Molarity.FromMolesPerCubicMeter(1); - Assert.Equal(0, molespercubicmeter.CompareTo(molespercubicmeter)); - Assert.True(molespercubicmeter.CompareTo(Molarity.Zero) > 0); - Assert.True(Molarity.Zero.CompareTo(molespercubicmeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Molarity molespercubicmeter = Molarity.FromMolesPerCubicMeter(1); - Assert.Throws(() => molespercubicmeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Molarity molespercubicmeter = Molarity.FromMolesPerCubicMeter(1); - Assert.Throws(() => molespercubicmeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Molarity v = Molarity.FromMolesPerCubicMeter(1); - Assert.True(v.Equals(Molarity.FromMolesPerCubicMeter(1), MolesPerCubicMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Molarity.Zero, MolesPerCubicMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Molarity molespercubicmeter = Molarity.FromMolesPerCubicMeter(1); - Assert.False(molespercubicmeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Molarity molespercubicmeter = Molarity.FromMolesPerCubicMeter(1); - Assert.False(molespercubicmeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(MolarityUnit.Undefined, Molarity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(MolarityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == MolarityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/PermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/PermeabilityTestsBase.g.cs deleted file mode 100644 index 69aae1e7c0..0000000000 --- a/UnitsNet.Tests/GeneratedCode/PermeabilityTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Permeability. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PermeabilityTestsBase - { - protected abstract double HenriesPerMeterInOneHenryPerMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double HenriesPerMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Permeability((double)0.0, PermeabilityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Permeability(double.PositiveInfinity, PermeabilityUnit.HenryPerMeter)); - Assert.Throws(() => new Permeability(double.NegativeInfinity, PermeabilityUnit.HenryPerMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Permeability(double.NaN, PermeabilityUnit.HenryPerMeter)); - } - - [Fact] - public void HenryPerMeterToPermeabilityUnits() - { - Permeability henrypermeter = Permeability.FromHenriesPerMeter(1); - AssertEx.EqualTolerance(HenriesPerMeterInOneHenryPerMeter, henrypermeter.HenriesPerMeter, HenriesPerMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Permeability.From(1, PermeabilityUnit.HenryPerMeter).HenriesPerMeter, HenriesPerMeterTolerance); - } - - [Fact] - public void FromHenriesPerMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Permeability.FromHenriesPerMeter(double.PositiveInfinity)); - Assert.Throws(() => Permeability.FromHenriesPerMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromHenriesPerMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Permeability.FromHenriesPerMeter(double.NaN)); - } - - [Fact] - public void As() - { - var henrypermeter = Permeability.FromHenriesPerMeter(1); - AssertEx.EqualTolerance(HenriesPerMeterInOneHenryPerMeter, henrypermeter.As(PermeabilityUnit.HenryPerMeter), HenriesPerMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var henrypermeter = Permeability.FromHenriesPerMeter(1); - - var henrypermeterQuantity = henrypermeter.ToUnit(PermeabilityUnit.HenryPerMeter); - AssertEx.EqualTolerance(HenriesPerMeterInOneHenryPerMeter, (double)henrypermeterQuantity.Value, HenriesPerMeterTolerance); - Assert.Equal(PermeabilityUnit.HenryPerMeter, henrypermeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Permeability henrypermeter = Permeability.FromHenriesPerMeter(1); - AssertEx.EqualTolerance(1, Permeability.FromHenriesPerMeter(henrypermeter.HenriesPerMeter).HenriesPerMeter, HenriesPerMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Permeability v = Permeability.FromHenriesPerMeter(1); - AssertEx.EqualTolerance(-1, -v.HenriesPerMeter, HenriesPerMeterTolerance); - AssertEx.EqualTolerance(2, (Permeability.FromHenriesPerMeter(3)-v).HenriesPerMeter, HenriesPerMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).HenriesPerMeter, HenriesPerMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).HenriesPerMeter, HenriesPerMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).HenriesPerMeter, HenriesPerMeterTolerance); - AssertEx.EqualTolerance(2, (Permeability.FromHenriesPerMeter(10)/5).HenriesPerMeter, HenriesPerMeterTolerance); - AssertEx.EqualTolerance(2, Permeability.FromHenriesPerMeter(10)/Permeability.FromHenriesPerMeter(5), HenriesPerMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Permeability oneHenryPerMeter = Permeability.FromHenriesPerMeter(1); - Permeability twoHenriesPerMeter = Permeability.FromHenriesPerMeter(2); - - Assert.True(oneHenryPerMeter < twoHenriesPerMeter); - Assert.True(oneHenryPerMeter <= twoHenriesPerMeter); - Assert.True(twoHenriesPerMeter > oneHenryPerMeter); - Assert.True(twoHenriesPerMeter >= oneHenryPerMeter); - - Assert.False(oneHenryPerMeter > twoHenriesPerMeter); - Assert.False(oneHenryPerMeter >= twoHenriesPerMeter); - Assert.False(twoHenriesPerMeter < oneHenryPerMeter); - Assert.False(twoHenriesPerMeter <= oneHenryPerMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Permeability henrypermeter = Permeability.FromHenriesPerMeter(1); - Assert.Equal(0, henrypermeter.CompareTo(henrypermeter)); - Assert.True(henrypermeter.CompareTo(Permeability.Zero) > 0); - Assert.True(Permeability.Zero.CompareTo(henrypermeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Permeability henrypermeter = Permeability.FromHenriesPerMeter(1); - Assert.Throws(() => henrypermeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Permeability henrypermeter = Permeability.FromHenriesPerMeter(1); - Assert.Throws(() => henrypermeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Permeability v = Permeability.FromHenriesPerMeter(1); - Assert.True(v.Equals(Permeability.FromHenriesPerMeter(1), HenriesPerMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Permeability.Zero, HenriesPerMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Permeability henrypermeter = Permeability.FromHenriesPerMeter(1); - Assert.False(henrypermeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Permeability henrypermeter = Permeability.FromHenriesPerMeter(1); - Assert.False(henrypermeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(PermeabilityUnit.Undefined, Permeability.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(PermeabilityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == PermeabilityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/PermittivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/PermittivityTestsBase.g.cs deleted file mode 100644 index 8c183d36af..0000000000 --- a/UnitsNet.Tests/GeneratedCode/PermittivityTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Permittivity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PermittivityTestsBase - { - protected abstract double FaradsPerMeterInOneFaradPerMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double FaradsPerMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Permittivity((double)0.0, PermittivityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Permittivity(double.PositiveInfinity, PermittivityUnit.FaradPerMeter)); - Assert.Throws(() => new Permittivity(double.NegativeInfinity, PermittivityUnit.FaradPerMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Permittivity(double.NaN, PermittivityUnit.FaradPerMeter)); - } - - [Fact] - public void FaradPerMeterToPermittivityUnits() - { - Permittivity faradpermeter = Permittivity.FromFaradsPerMeter(1); - AssertEx.EqualTolerance(FaradsPerMeterInOneFaradPerMeter, faradpermeter.FaradsPerMeter, FaradsPerMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Permittivity.From(1, PermittivityUnit.FaradPerMeter).FaradsPerMeter, FaradsPerMeterTolerance); - } - - [Fact] - public void FromFaradsPerMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Permittivity.FromFaradsPerMeter(double.PositiveInfinity)); - Assert.Throws(() => Permittivity.FromFaradsPerMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromFaradsPerMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Permittivity.FromFaradsPerMeter(double.NaN)); - } - - [Fact] - public void As() - { - var faradpermeter = Permittivity.FromFaradsPerMeter(1); - AssertEx.EqualTolerance(FaradsPerMeterInOneFaradPerMeter, faradpermeter.As(PermittivityUnit.FaradPerMeter), FaradsPerMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var faradpermeter = Permittivity.FromFaradsPerMeter(1); - - var faradpermeterQuantity = faradpermeter.ToUnit(PermittivityUnit.FaradPerMeter); - AssertEx.EqualTolerance(FaradsPerMeterInOneFaradPerMeter, (double)faradpermeterQuantity.Value, FaradsPerMeterTolerance); - Assert.Equal(PermittivityUnit.FaradPerMeter, faradpermeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Permittivity faradpermeter = Permittivity.FromFaradsPerMeter(1); - AssertEx.EqualTolerance(1, Permittivity.FromFaradsPerMeter(faradpermeter.FaradsPerMeter).FaradsPerMeter, FaradsPerMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Permittivity v = Permittivity.FromFaradsPerMeter(1); - AssertEx.EqualTolerance(-1, -v.FaradsPerMeter, FaradsPerMeterTolerance); - AssertEx.EqualTolerance(2, (Permittivity.FromFaradsPerMeter(3)-v).FaradsPerMeter, FaradsPerMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).FaradsPerMeter, FaradsPerMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).FaradsPerMeter, FaradsPerMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).FaradsPerMeter, FaradsPerMeterTolerance); - AssertEx.EqualTolerance(2, (Permittivity.FromFaradsPerMeter(10)/5).FaradsPerMeter, FaradsPerMeterTolerance); - AssertEx.EqualTolerance(2, Permittivity.FromFaradsPerMeter(10)/Permittivity.FromFaradsPerMeter(5), FaradsPerMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Permittivity oneFaradPerMeter = Permittivity.FromFaradsPerMeter(1); - Permittivity twoFaradsPerMeter = Permittivity.FromFaradsPerMeter(2); - - Assert.True(oneFaradPerMeter < twoFaradsPerMeter); - Assert.True(oneFaradPerMeter <= twoFaradsPerMeter); - Assert.True(twoFaradsPerMeter > oneFaradPerMeter); - Assert.True(twoFaradsPerMeter >= oneFaradPerMeter); - - Assert.False(oneFaradPerMeter > twoFaradsPerMeter); - Assert.False(oneFaradPerMeter >= twoFaradsPerMeter); - Assert.False(twoFaradsPerMeter < oneFaradPerMeter); - Assert.False(twoFaradsPerMeter <= oneFaradPerMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Permittivity faradpermeter = Permittivity.FromFaradsPerMeter(1); - Assert.Equal(0, faradpermeter.CompareTo(faradpermeter)); - Assert.True(faradpermeter.CompareTo(Permittivity.Zero) > 0); - Assert.True(Permittivity.Zero.CompareTo(faradpermeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Permittivity faradpermeter = Permittivity.FromFaradsPerMeter(1); - Assert.Throws(() => faradpermeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Permittivity faradpermeter = Permittivity.FromFaradsPerMeter(1); - Assert.Throws(() => faradpermeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Permittivity v = Permittivity.FromFaradsPerMeter(1); - Assert.True(v.Equals(Permittivity.FromFaradsPerMeter(1), FaradsPerMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Permittivity.Zero, FaradsPerMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Permittivity faradpermeter = Permittivity.FromFaradsPerMeter(1); - Assert.False(faradpermeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Permittivity faradpermeter = Permittivity.FromFaradsPerMeter(1); - Assert.False(faradpermeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(PermittivityUnit.Undefined, Permittivity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(PermittivityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == PermittivityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/PowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/PowerDensityTestsBase.g.cs deleted file mode 100644 index f904dec7e3..0000000000 --- a/UnitsNet.Tests/GeneratedCode/PowerDensityTestsBase.g.cs +++ /dev/null @@ -1,654 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of PowerDensity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PowerDensityTestsBase - { - protected abstract double DecawattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double DecawattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double DecawattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double DecawattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double DeciwattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double DeciwattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double DeciwattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double DeciwattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double GigawattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double GigawattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double GigawattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double GigawattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double KilowattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double KilowattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double KilowattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double KilowattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double MegawattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double MegawattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double MegawattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double MegawattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double MicrowattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double MicrowattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double MicrowattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double MicrowattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double MilliwattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double MilliwattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double MilliwattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double MilliwattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double NanowattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double NanowattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double NanowattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double NanowattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double PicowattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double PicowattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double PicowattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double PicowattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double TerawattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double TerawattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double TerawattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double TerawattsPerLiterInOneWattPerCubicMeter { get; } - protected abstract double WattsPerCubicFootInOneWattPerCubicMeter { get; } - protected abstract double WattsPerCubicInchInOneWattPerCubicMeter { get; } - protected abstract double WattsPerCubicMeterInOneWattPerCubicMeter { get; } - protected abstract double WattsPerLiterInOneWattPerCubicMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DecawattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double DecawattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double DecawattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double DecawattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double DeciwattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double DeciwattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double DeciwattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double DeciwattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double GigawattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double GigawattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double GigawattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double GigawattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double KilowattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double KilowattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double KilowattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double KilowattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double MegawattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double MegawattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double MegawattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double MegawattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double MicrowattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double MicrowattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double MicrowattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double MicrowattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double MilliwattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double MilliwattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double MilliwattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double MilliwattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double NanowattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double NanowattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double NanowattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double NanowattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double PicowattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double PicowattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double PicowattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double PicowattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double TerawattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double TerawattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double TerawattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double TerawattsPerLiterTolerance { get { return 1e-5; } } - protected virtual double WattsPerCubicFootTolerance { get { return 1e-5; } } - protected virtual double WattsPerCubicInchTolerance { get { return 1e-5; } } - protected virtual double WattsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double WattsPerLiterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new PowerDensity((double)0.0, PowerDensityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new PowerDensity(double.PositiveInfinity, PowerDensityUnit.WattPerCubicMeter)); - Assert.Throws(() => new PowerDensity(double.NegativeInfinity, PowerDensityUnit.WattPerCubicMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new PowerDensity(double.NaN, PowerDensityUnit.WattPerCubicMeter)); - } - - [Fact] - public void WattPerCubicMeterToPowerDensityUnits() - { - PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1); - AssertEx.EqualTolerance(DecawattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.DecawattsPerCubicFoot, DecawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(DecawattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.DecawattsPerCubicInch, DecawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(DecawattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.DecawattsPerCubicMeter, DecawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(DecawattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.DecawattsPerLiter, DecawattsPerLiterTolerance); - AssertEx.EqualTolerance(DeciwattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.DeciwattsPerCubicFoot, DeciwattsPerCubicFootTolerance); - AssertEx.EqualTolerance(DeciwattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.DeciwattsPerCubicInch, DeciwattsPerCubicInchTolerance); - AssertEx.EqualTolerance(DeciwattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.DeciwattsPerCubicMeter, DeciwattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(DeciwattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.DeciwattsPerLiter, DeciwattsPerLiterTolerance); - AssertEx.EqualTolerance(GigawattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.GigawattsPerCubicFoot, GigawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(GigawattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.GigawattsPerCubicInch, GigawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(GigawattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.GigawattsPerCubicMeter, GigawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(GigawattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.GigawattsPerLiter, GigawattsPerLiterTolerance); - AssertEx.EqualTolerance(KilowattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.KilowattsPerCubicFoot, KilowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(KilowattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.KilowattsPerCubicInch, KilowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(KilowattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.KilowattsPerCubicMeter, KilowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(KilowattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.KilowattsPerLiter, KilowattsPerLiterTolerance); - AssertEx.EqualTolerance(MegawattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.MegawattsPerCubicFoot, MegawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(MegawattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.MegawattsPerCubicInch, MegawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(MegawattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.MegawattsPerCubicMeter, MegawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(MegawattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.MegawattsPerLiter, MegawattsPerLiterTolerance); - AssertEx.EqualTolerance(MicrowattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.MicrowattsPerCubicFoot, MicrowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(MicrowattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.MicrowattsPerCubicInch, MicrowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(MicrowattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.MicrowattsPerCubicMeter, MicrowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(MicrowattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.MicrowattsPerLiter, MicrowattsPerLiterTolerance); - AssertEx.EqualTolerance(MilliwattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.MilliwattsPerCubicFoot, MilliwattsPerCubicFootTolerance); - AssertEx.EqualTolerance(MilliwattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.MilliwattsPerCubicInch, MilliwattsPerCubicInchTolerance); - AssertEx.EqualTolerance(MilliwattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.MilliwattsPerCubicMeter, MilliwattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(MilliwattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.MilliwattsPerLiter, MilliwattsPerLiterTolerance); - AssertEx.EqualTolerance(NanowattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.NanowattsPerCubicFoot, NanowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(NanowattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.NanowattsPerCubicInch, NanowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(NanowattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.NanowattsPerCubicMeter, NanowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(NanowattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.NanowattsPerLiter, NanowattsPerLiterTolerance); - AssertEx.EqualTolerance(PicowattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.PicowattsPerCubicFoot, PicowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(PicowattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.PicowattsPerCubicInch, PicowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(PicowattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.PicowattsPerCubicMeter, PicowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(PicowattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.PicowattsPerLiter, PicowattsPerLiterTolerance); - AssertEx.EqualTolerance(TerawattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.TerawattsPerCubicFoot, TerawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(TerawattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.TerawattsPerCubicInch, TerawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(TerawattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.TerawattsPerCubicMeter, TerawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(TerawattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.TerawattsPerLiter, TerawattsPerLiterTolerance); - AssertEx.EqualTolerance(WattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.WattsPerCubicFoot, WattsPerCubicFootTolerance); - AssertEx.EqualTolerance(WattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.WattsPerCubicInch, WattsPerCubicInchTolerance); - AssertEx.EqualTolerance(WattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.WattsPerCubicMeter, WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(WattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.WattsPerLiter, WattsPerLiterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.DecawattPerCubicFoot).DecawattsPerCubicFoot, DecawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.DecawattPerCubicInch).DecawattsPerCubicInch, DecawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.DecawattPerCubicMeter).DecawattsPerCubicMeter, DecawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.DecawattPerLiter).DecawattsPerLiter, DecawattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.DeciwattPerCubicFoot).DeciwattsPerCubicFoot, DeciwattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.DeciwattPerCubicInch).DeciwattsPerCubicInch, DeciwattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.DeciwattPerCubicMeter).DeciwattsPerCubicMeter, DeciwattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.DeciwattPerLiter).DeciwattsPerLiter, DeciwattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.GigawattPerCubicFoot).GigawattsPerCubicFoot, GigawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.GigawattPerCubicInch).GigawattsPerCubicInch, GigawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.GigawattPerCubicMeter).GigawattsPerCubicMeter, GigawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.GigawattPerLiter).GigawattsPerLiter, GigawattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.KilowattPerCubicFoot).KilowattsPerCubicFoot, KilowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.KilowattPerCubicInch).KilowattsPerCubicInch, KilowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.KilowattPerCubicMeter).KilowattsPerCubicMeter, KilowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.KilowattPerLiter).KilowattsPerLiter, KilowattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MegawattPerCubicFoot).MegawattsPerCubicFoot, MegawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MegawattPerCubicInch).MegawattsPerCubicInch, MegawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MegawattPerCubicMeter).MegawattsPerCubicMeter, MegawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MegawattPerLiter).MegawattsPerLiter, MegawattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MicrowattPerCubicFoot).MicrowattsPerCubicFoot, MicrowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MicrowattPerCubicInch).MicrowattsPerCubicInch, MicrowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MicrowattPerCubicMeter).MicrowattsPerCubicMeter, MicrowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MicrowattPerLiter).MicrowattsPerLiter, MicrowattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MilliwattPerCubicFoot).MilliwattsPerCubicFoot, MilliwattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MilliwattPerCubicInch).MilliwattsPerCubicInch, MilliwattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MilliwattPerCubicMeter).MilliwattsPerCubicMeter, MilliwattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.MilliwattPerLiter).MilliwattsPerLiter, MilliwattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.NanowattPerCubicFoot).NanowattsPerCubicFoot, NanowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.NanowattPerCubicInch).NanowattsPerCubicInch, NanowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.NanowattPerCubicMeter).NanowattsPerCubicMeter, NanowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.NanowattPerLiter).NanowattsPerLiter, NanowattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.PicowattPerCubicFoot).PicowattsPerCubicFoot, PicowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.PicowattPerCubicInch).PicowattsPerCubicInch, PicowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.PicowattPerCubicMeter).PicowattsPerCubicMeter, PicowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.PicowattPerLiter).PicowattsPerLiter, PicowattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.TerawattPerCubicFoot).TerawattsPerCubicFoot, TerawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.TerawattPerCubicInch).TerawattsPerCubicInch, TerawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.TerawattPerCubicMeter).TerawattsPerCubicMeter, TerawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.TerawattPerLiter).TerawattsPerLiter, TerawattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.WattPerCubicFoot).WattsPerCubicFoot, WattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.WattPerCubicInch).WattsPerCubicInch, WattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.WattPerCubicMeter).WattsPerCubicMeter, WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.From(1, PowerDensityUnit.WattPerLiter).WattsPerLiter, WattsPerLiterTolerance); - } - - [Fact] - public void FromWattsPerCubicMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => PowerDensity.FromWattsPerCubicMeter(double.PositiveInfinity)); - Assert.Throws(() => PowerDensity.FromWattsPerCubicMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromWattsPerCubicMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => PowerDensity.FromWattsPerCubicMeter(double.NaN)); - } - - [Fact] - public void As() - { - var wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1); - AssertEx.EqualTolerance(DecawattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.DecawattPerCubicFoot), DecawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(DecawattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.DecawattPerCubicInch), DecawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(DecawattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.DecawattPerCubicMeter), DecawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(DecawattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.DecawattPerLiter), DecawattsPerLiterTolerance); - AssertEx.EqualTolerance(DeciwattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.DeciwattPerCubicFoot), DeciwattsPerCubicFootTolerance); - AssertEx.EqualTolerance(DeciwattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.DeciwattPerCubicInch), DeciwattsPerCubicInchTolerance); - AssertEx.EqualTolerance(DeciwattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.DeciwattPerCubicMeter), DeciwattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(DeciwattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.DeciwattPerLiter), DeciwattsPerLiterTolerance); - AssertEx.EqualTolerance(GigawattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.GigawattPerCubicFoot), GigawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(GigawattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.GigawattPerCubicInch), GigawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(GigawattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.GigawattPerCubicMeter), GigawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(GigawattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.GigawattPerLiter), GigawattsPerLiterTolerance); - AssertEx.EqualTolerance(KilowattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.KilowattPerCubicFoot), KilowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(KilowattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.KilowattPerCubicInch), KilowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(KilowattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.KilowattPerCubicMeter), KilowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(KilowattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.KilowattPerLiter), KilowattsPerLiterTolerance); - AssertEx.EqualTolerance(MegawattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MegawattPerCubicFoot), MegawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(MegawattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MegawattPerCubicInch), MegawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(MegawattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MegawattPerCubicMeter), MegawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(MegawattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MegawattPerLiter), MegawattsPerLiterTolerance); - AssertEx.EqualTolerance(MicrowattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MicrowattPerCubicFoot), MicrowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(MicrowattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MicrowattPerCubicInch), MicrowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(MicrowattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MicrowattPerCubicMeter), MicrowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(MicrowattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MicrowattPerLiter), MicrowattsPerLiterTolerance); - AssertEx.EqualTolerance(MilliwattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MilliwattPerCubicFoot), MilliwattsPerCubicFootTolerance); - AssertEx.EqualTolerance(MilliwattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MilliwattPerCubicInch), MilliwattsPerCubicInchTolerance); - AssertEx.EqualTolerance(MilliwattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MilliwattPerCubicMeter), MilliwattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(MilliwattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.MilliwattPerLiter), MilliwattsPerLiterTolerance); - AssertEx.EqualTolerance(NanowattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.NanowattPerCubicFoot), NanowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(NanowattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.NanowattPerCubicInch), NanowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(NanowattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.NanowattPerCubicMeter), NanowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(NanowattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.NanowattPerLiter), NanowattsPerLiterTolerance); - AssertEx.EqualTolerance(PicowattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.PicowattPerCubicFoot), PicowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(PicowattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.PicowattPerCubicInch), PicowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(PicowattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.PicowattPerCubicMeter), PicowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(PicowattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.PicowattPerLiter), PicowattsPerLiterTolerance); - AssertEx.EqualTolerance(TerawattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.TerawattPerCubicFoot), TerawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(TerawattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.TerawattPerCubicInch), TerawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(TerawattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.TerawattPerCubicMeter), TerawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(TerawattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.TerawattPerLiter), TerawattsPerLiterTolerance); - AssertEx.EqualTolerance(WattsPerCubicFootInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.WattPerCubicFoot), WattsPerCubicFootTolerance); - AssertEx.EqualTolerance(WattsPerCubicInchInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.WattPerCubicInch), WattsPerCubicInchTolerance); - AssertEx.EqualTolerance(WattsPerCubicMeterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.WattPerCubicMeter), WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(WattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.WattPerLiter), WattsPerLiterTolerance); - } - - [Fact] - public void ToUnit() - { - var wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1); - - var decawattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.DecawattPerCubicFoot); - AssertEx.EqualTolerance(DecawattsPerCubicFootInOneWattPerCubicMeter, (double)decawattpercubicfootQuantity.Value, DecawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerCubicFoot, decawattpercubicfootQuantity.Unit); - - var decawattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.DecawattPerCubicInch); - AssertEx.EqualTolerance(DecawattsPerCubicInchInOneWattPerCubicMeter, (double)decawattpercubicinchQuantity.Value, DecawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerCubicInch, decawattpercubicinchQuantity.Unit); - - var decawattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.DecawattPerCubicMeter); - AssertEx.EqualTolerance(DecawattsPerCubicMeterInOneWattPerCubicMeter, (double)decawattpercubicmeterQuantity.Value, DecawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerCubicMeter, decawattpercubicmeterQuantity.Unit); - - var decawattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.DecawattPerLiter); - AssertEx.EqualTolerance(DecawattsPerLiterInOneWattPerCubicMeter, (double)decawattperliterQuantity.Value, DecawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.DecawattPerLiter, decawattperliterQuantity.Unit); - - var deciwattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.DeciwattPerCubicFoot); - AssertEx.EqualTolerance(DeciwattsPerCubicFootInOneWattPerCubicMeter, (double)deciwattpercubicfootQuantity.Value, DeciwattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicFoot, deciwattpercubicfootQuantity.Unit); - - var deciwattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.DeciwattPerCubicInch); - AssertEx.EqualTolerance(DeciwattsPerCubicInchInOneWattPerCubicMeter, (double)deciwattpercubicinchQuantity.Value, DeciwattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicInch, deciwattpercubicinchQuantity.Unit); - - var deciwattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.DeciwattPerCubicMeter); - AssertEx.EqualTolerance(DeciwattsPerCubicMeterInOneWattPerCubicMeter, (double)deciwattpercubicmeterQuantity.Value, DeciwattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicMeter, deciwattpercubicmeterQuantity.Unit); - - var deciwattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.DeciwattPerLiter); - AssertEx.EqualTolerance(DeciwattsPerLiterInOneWattPerCubicMeter, (double)deciwattperliterQuantity.Value, DeciwattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.DeciwattPerLiter, deciwattperliterQuantity.Unit); - - var gigawattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.GigawattPerCubicFoot); - AssertEx.EqualTolerance(GigawattsPerCubicFootInOneWattPerCubicMeter, (double)gigawattpercubicfootQuantity.Value, GigawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerCubicFoot, gigawattpercubicfootQuantity.Unit); - - var gigawattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.GigawattPerCubicInch); - AssertEx.EqualTolerance(GigawattsPerCubicInchInOneWattPerCubicMeter, (double)gigawattpercubicinchQuantity.Value, GigawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerCubicInch, gigawattpercubicinchQuantity.Unit); - - var gigawattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.GigawattPerCubicMeter); - AssertEx.EqualTolerance(GigawattsPerCubicMeterInOneWattPerCubicMeter, (double)gigawattpercubicmeterQuantity.Value, GigawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerCubicMeter, gigawattpercubicmeterQuantity.Unit); - - var gigawattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.GigawattPerLiter); - AssertEx.EqualTolerance(GigawattsPerLiterInOneWattPerCubicMeter, (double)gigawattperliterQuantity.Value, GigawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.GigawattPerLiter, gigawattperliterQuantity.Unit); - - var kilowattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.KilowattPerCubicFoot); - AssertEx.EqualTolerance(KilowattsPerCubicFootInOneWattPerCubicMeter, (double)kilowattpercubicfootQuantity.Value, KilowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerCubicFoot, kilowattpercubicfootQuantity.Unit); - - var kilowattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.KilowattPerCubicInch); - AssertEx.EqualTolerance(KilowattsPerCubicInchInOneWattPerCubicMeter, (double)kilowattpercubicinchQuantity.Value, KilowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerCubicInch, kilowattpercubicinchQuantity.Unit); - - var kilowattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.KilowattPerCubicMeter); - AssertEx.EqualTolerance(KilowattsPerCubicMeterInOneWattPerCubicMeter, (double)kilowattpercubicmeterQuantity.Value, KilowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerCubicMeter, kilowattpercubicmeterQuantity.Unit); - - var kilowattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.KilowattPerLiter); - AssertEx.EqualTolerance(KilowattsPerLiterInOneWattPerCubicMeter, (double)kilowattperliterQuantity.Value, KilowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.KilowattPerLiter, kilowattperliterQuantity.Unit); - - var megawattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MegawattPerCubicFoot); - AssertEx.EqualTolerance(MegawattsPerCubicFootInOneWattPerCubicMeter, (double)megawattpercubicfootQuantity.Value, MegawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.MegawattPerCubicFoot, megawattpercubicfootQuantity.Unit); - - var megawattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MegawattPerCubicInch); - AssertEx.EqualTolerance(MegawattsPerCubicInchInOneWattPerCubicMeter, (double)megawattpercubicinchQuantity.Value, MegawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.MegawattPerCubicInch, megawattpercubicinchQuantity.Unit); - - var megawattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MegawattPerCubicMeter); - AssertEx.EqualTolerance(MegawattsPerCubicMeterInOneWattPerCubicMeter, (double)megawattpercubicmeterQuantity.Value, MegawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.MegawattPerCubicMeter, megawattpercubicmeterQuantity.Unit); - - var megawattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MegawattPerLiter); - AssertEx.EqualTolerance(MegawattsPerLiterInOneWattPerCubicMeter, (double)megawattperliterQuantity.Value, MegawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.MegawattPerLiter, megawattperliterQuantity.Unit); - - var microwattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MicrowattPerCubicFoot); - AssertEx.EqualTolerance(MicrowattsPerCubicFootInOneWattPerCubicMeter, (double)microwattpercubicfootQuantity.Value, MicrowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicFoot, microwattpercubicfootQuantity.Unit); - - var microwattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MicrowattPerCubicInch); - AssertEx.EqualTolerance(MicrowattsPerCubicInchInOneWattPerCubicMeter, (double)microwattpercubicinchQuantity.Value, MicrowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicInch, microwattpercubicinchQuantity.Unit); - - var microwattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MicrowattPerCubicMeter); - AssertEx.EqualTolerance(MicrowattsPerCubicMeterInOneWattPerCubicMeter, (double)microwattpercubicmeterQuantity.Value, MicrowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicMeter, microwattpercubicmeterQuantity.Unit); - - var microwattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MicrowattPerLiter); - AssertEx.EqualTolerance(MicrowattsPerLiterInOneWattPerCubicMeter, (double)microwattperliterQuantity.Value, MicrowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.MicrowattPerLiter, microwattperliterQuantity.Unit); - - var milliwattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MilliwattPerCubicFoot); - AssertEx.EqualTolerance(MilliwattsPerCubicFootInOneWattPerCubicMeter, (double)milliwattpercubicfootQuantity.Value, MilliwattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.MilliwattPerCubicFoot, milliwattpercubicfootQuantity.Unit); - - var milliwattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MilliwattPerCubicInch); - AssertEx.EqualTolerance(MilliwattsPerCubicInchInOneWattPerCubicMeter, (double)milliwattpercubicinchQuantity.Value, MilliwattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.MilliwattPerCubicInch, milliwattpercubicinchQuantity.Unit); - - var milliwattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MilliwattPerCubicMeter); - AssertEx.EqualTolerance(MilliwattsPerCubicMeterInOneWattPerCubicMeter, (double)milliwattpercubicmeterQuantity.Value, MilliwattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.MilliwattPerCubicMeter, milliwattpercubicmeterQuantity.Unit); - - var milliwattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.MilliwattPerLiter); - AssertEx.EqualTolerance(MilliwattsPerLiterInOneWattPerCubicMeter, (double)milliwattperliterQuantity.Value, MilliwattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.MilliwattPerLiter, milliwattperliterQuantity.Unit); - - var nanowattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.NanowattPerCubicFoot); - AssertEx.EqualTolerance(NanowattsPerCubicFootInOneWattPerCubicMeter, (double)nanowattpercubicfootQuantity.Value, NanowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerCubicFoot, nanowattpercubicfootQuantity.Unit); - - var nanowattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.NanowattPerCubicInch); - AssertEx.EqualTolerance(NanowattsPerCubicInchInOneWattPerCubicMeter, (double)nanowattpercubicinchQuantity.Value, NanowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerCubicInch, nanowattpercubicinchQuantity.Unit); - - var nanowattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.NanowattPerCubicMeter); - AssertEx.EqualTolerance(NanowattsPerCubicMeterInOneWattPerCubicMeter, (double)nanowattpercubicmeterQuantity.Value, NanowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerCubicMeter, nanowattpercubicmeterQuantity.Unit); - - var nanowattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.NanowattPerLiter); - AssertEx.EqualTolerance(NanowattsPerLiterInOneWattPerCubicMeter, (double)nanowattperliterQuantity.Value, NanowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.NanowattPerLiter, nanowattperliterQuantity.Unit); - - var picowattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.PicowattPerCubicFoot); - AssertEx.EqualTolerance(PicowattsPerCubicFootInOneWattPerCubicMeter, (double)picowattpercubicfootQuantity.Value, PicowattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerCubicFoot, picowattpercubicfootQuantity.Unit); - - var picowattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.PicowattPerCubicInch); - AssertEx.EqualTolerance(PicowattsPerCubicInchInOneWattPerCubicMeter, (double)picowattpercubicinchQuantity.Value, PicowattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerCubicInch, picowattpercubicinchQuantity.Unit); - - var picowattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.PicowattPerCubicMeter); - AssertEx.EqualTolerance(PicowattsPerCubicMeterInOneWattPerCubicMeter, (double)picowattpercubicmeterQuantity.Value, PicowattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerCubicMeter, picowattpercubicmeterQuantity.Unit); - - var picowattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.PicowattPerLiter); - AssertEx.EqualTolerance(PicowattsPerLiterInOneWattPerCubicMeter, (double)picowattperliterQuantity.Value, PicowattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.PicowattPerLiter, picowattperliterQuantity.Unit); - - var terawattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.TerawattPerCubicFoot); - AssertEx.EqualTolerance(TerawattsPerCubicFootInOneWattPerCubicMeter, (double)terawattpercubicfootQuantity.Value, TerawattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerCubicFoot, terawattpercubicfootQuantity.Unit); - - var terawattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.TerawattPerCubicInch); - AssertEx.EqualTolerance(TerawattsPerCubicInchInOneWattPerCubicMeter, (double)terawattpercubicinchQuantity.Value, TerawattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerCubicInch, terawattpercubicinchQuantity.Unit); - - var terawattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.TerawattPerCubicMeter); - AssertEx.EqualTolerance(TerawattsPerCubicMeterInOneWattPerCubicMeter, (double)terawattpercubicmeterQuantity.Value, TerawattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerCubicMeter, terawattpercubicmeterQuantity.Unit); - - var terawattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.TerawattPerLiter); - AssertEx.EqualTolerance(TerawattsPerLiterInOneWattPerCubicMeter, (double)terawattperliterQuantity.Value, TerawattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.TerawattPerLiter, terawattperliterQuantity.Unit); - - var wattpercubicfootQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.WattPerCubicFoot); - AssertEx.EqualTolerance(WattsPerCubicFootInOneWattPerCubicMeter, (double)wattpercubicfootQuantity.Value, WattsPerCubicFootTolerance); - Assert.Equal(PowerDensityUnit.WattPerCubicFoot, wattpercubicfootQuantity.Unit); - - var wattpercubicinchQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.WattPerCubicInch); - AssertEx.EqualTolerance(WattsPerCubicInchInOneWattPerCubicMeter, (double)wattpercubicinchQuantity.Value, WattsPerCubicInchTolerance); - Assert.Equal(PowerDensityUnit.WattPerCubicInch, wattpercubicinchQuantity.Unit); - - var wattpercubicmeterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.WattPerCubicMeter); - AssertEx.EqualTolerance(WattsPerCubicMeterInOneWattPerCubicMeter, (double)wattpercubicmeterQuantity.Value, WattsPerCubicMeterTolerance); - Assert.Equal(PowerDensityUnit.WattPerCubicMeter, wattpercubicmeterQuantity.Unit); - - var wattperliterQuantity = wattpercubicmeter.ToUnit(PowerDensityUnit.WattPerLiter); - AssertEx.EqualTolerance(WattsPerLiterInOneWattPerCubicMeter, (double)wattperliterQuantity.Value, WattsPerLiterTolerance); - Assert.Equal(PowerDensityUnit.WattPerLiter, wattperliterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1); - AssertEx.EqualTolerance(1, PowerDensity.FromDecawattsPerCubicFoot(wattpercubicmeter.DecawattsPerCubicFoot).WattsPerCubicMeter, DecawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromDecawattsPerCubicInch(wattpercubicmeter.DecawattsPerCubicInch).WattsPerCubicMeter, DecawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromDecawattsPerCubicMeter(wattpercubicmeter.DecawattsPerCubicMeter).WattsPerCubicMeter, DecawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromDecawattsPerLiter(wattpercubicmeter.DecawattsPerLiter).WattsPerCubicMeter, DecawattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromDeciwattsPerCubicFoot(wattpercubicmeter.DeciwattsPerCubicFoot).WattsPerCubicMeter, DeciwattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromDeciwattsPerCubicInch(wattpercubicmeter.DeciwattsPerCubicInch).WattsPerCubicMeter, DeciwattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromDeciwattsPerCubicMeter(wattpercubicmeter.DeciwattsPerCubicMeter).WattsPerCubicMeter, DeciwattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromDeciwattsPerLiter(wattpercubicmeter.DeciwattsPerLiter).WattsPerCubicMeter, DeciwattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromGigawattsPerCubicFoot(wattpercubicmeter.GigawattsPerCubicFoot).WattsPerCubicMeter, GigawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromGigawattsPerCubicInch(wattpercubicmeter.GigawattsPerCubicInch).WattsPerCubicMeter, GigawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromGigawattsPerCubicMeter(wattpercubicmeter.GigawattsPerCubicMeter).WattsPerCubicMeter, GigawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromGigawattsPerLiter(wattpercubicmeter.GigawattsPerLiter).WattsPerCubicMeter, GigawattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromKilowattsPerCubicFoot(wattpercubicmeter.KilowattsPerCubicFoot).WattsPerCubicMeter, KilowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromKilowattsPerCubicInch(wattpercubicmeter.KilowattsPerCubicInch).WattsPerCubicMeter, KilowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromKilowattsPerCubicMeter(wattpercubicmeter.KilowattsPerCubicMeter).WattsPerCubicMeter, KilowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromKilowattsPerLiter(wattpercubicmeter.KilowattsPerLiter).WattsPerCubicMeter, KilowattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMegawattsPerCubicFoot(wattpercubicmeter.MegawattsPerCubicFoot).WattsPerCubicMeter, MegawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMegawattsPerCubicInch(wattpercubicmeter.MegawattsPerCubicInch).WattsPerCubicMeter, MegawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMegawattsPerCubicMeter(wattpercubicmeter.MegawattsPerCubicMeter).WattsPerCubicMeter, MegawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMegawattsPerLiter(wattpercubicmeter.MegawattsPerLiter).WattsPerCubicMeter, MegawattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMicrowattsPerCubicFoot(wattpercubicmeter.MicrowattsPerCubicFoot).WattsPerCubicMeter, MicrowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMicrowattsPerCubicInch(wattpercubicmeter.MicrowattsPerCubicInch).WattsPerCubicMeter, MicrowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMicrowattsPerCubicMeter(wattpercubicmeter.MicrowattsPerCubicMeter).WattsPerCubicMeter, MicrowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMicrowattsPerLiter(wattpercubicmeter.MicrowattsPerLiter).WattsPerCubicMeter, MicrowattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMilliwattsPerCubicFoot(wattpercubicmeter.MilliwattsPerCubicFoot).WattsPerCubicMeter, MilliwattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMilliwattsPerCubicInch(wattpercubicmeter.MilliwattsPerCubicInch).WattsPerCubicMeter, MilliwattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMilliwattsPerCubicMeter(wattpercubicmeter.MilliwattsPerCubicMeter).WattsPerCubicMeter, MilliwattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromMilliwattsPerLiter(wattpercubicmeter.MilliwattsPerLiter).WattsPerCubicMeter, MilliwattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromNanowattsPerCubicFoot(wattpercubicmeter.NanowattsPerCubicFoot).WattsPerCubicMeter, NanowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromNanowattsPerCubicInch(wattpercubicmeter.NanowattsPerCubicInch).WattsPerCubicMeter, NanowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromNanowattsPerCubicMeter(wattpercubicmeter.NanowattsPerCubicMeter).WattsPerCubicMeter, NanowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromNanowattsPerLiter(wattpercubicmeter.NanowattsPerLiter).WattsPerCubicMeter, NanowattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromPicowattsPerCubicFoot(wattpercubicmeter.PicowattsPerCubicFoot).WattsPerCubicMeter, PicowattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromPicowattsPerCubicInch(wattpercubicmeter.PicowattsPerCubicInch).WattsPerCubicMeter, PicowattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromPicowattsPerCubicMeter(wattpercubicmeter.PicowattsPerCubicMeter).WattsPerCubicMeter, PicowattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromPicowattsPerLiter(wattpercubicmeter.PicowattsPerLiter).WattsPerCubicMeter, PicowattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromTerawattsPerCubicFoot(wattpercubicmeter.TerawattsPerCubicFoot).WattsPerCubicMeter, TerawattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromTerawattsPerCubicInch(wattpercubicmeter.TerawattsPerCubicInch).WattsPerCubicMeter, TerawattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromTerawattsPerCubicMeter(wattpercubicmeter.TerawattsPerCubicMeter).WattsPerCubicMeter, TerawattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromTerawattsPerLiter(wattpercubicmeter.TerawattsPerLiter).WattsPerCubicMeter, TerawattsPerLiterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromWattsPerCubicFoot(wattpercubicmeter.WattsPerCubicFoot).WattsPerCubicMeter, WattsPerCubicFootTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromWattsPerCubicInch(wattpercubicmeter.WattsPerCubicInch).WattsPerCubicMeter, WattsPerCubicInchTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromWattsPerCubicMeter(wattpercubicmeter.WattsPerCubicMeter).WattsPerCubicMeter, WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, PowerDensity.FromWattsPerLiter(wattpercubicmeter.WattsPerLiter).WattsPerCubicMeter, WattsPerLiterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - PowerDensity v = PowerDensity.FromWattsPerCubicMeter(1); - AssertEx.EqualTolerance(-1, -v.WattsPerCubicMeter, WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (PowerDensity.FromWattsPerCubicMeter(3)-v).WattsPerCubicMeter, WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).WattsPerCubicMeter, WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).WattsPerCubicMeter, WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).WattsPerCubicMeter, WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (PowerDensity.FromWattsPerCubicMeter(10)/5).WattsPerCubicMeter, WattsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, PowerDensity.FromWattsPerCubicMeter(10)/PowerDensity.FromWattsPerCubicMeter(5), WattsPerCubicMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - PowerDensity oneWattPerCubicMeter = PowerDensity.FromWattsPerCubicMeter(1); - PowerDensity twoWattsPerCubicMeter = PowerDensity.FromWattsPerCubicMeter(2); - - Assert.True(oneWattPerCubicMeter < twoWattsPerCubicMeter); - Assert.True(oneWattPerCubicMeter <= twoWattsPerCubicMeter); - Assert.True(twoWattsPerCubicMeter > oneWattPerCubicMeter); - Assert.True(twoWattsPerCubicMeter >= oneWattPerCubicMeter); - - Assert.False(oneWattPerCubicMeter > twoWattsPerCubicMeter); - Assert.False(oneWattPerCubicMeter >= twoWattsPerCubicMeter); - Assert.False(twoWattsPerCubicMeter < oneWattPerCubicMeter); - Assert.False(twoWattsPerCubicMeter <= oneWattPerCubicMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1); - Assert.Equal(0, wattpercubicmeter.CompareTo(wattpercubicmeter)); - Assert.True(wattpercubicmeter.CompareTo(PowerDensity.Zero) > 0); - Assert.True(PowerDensity.Zero.CompareTo(wattpercubicmeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1); - Assert.Throws(() => wattpercubicmeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1); - Assert.Throws(() => wattpercubicmeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - PowerDensity v = PowerDensity.FromWattsPerCubicMeter(1); - Assert.True(v.Equals(PowerDensity.FromWattsPerCubicMeter(1), WattsPerCubicMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(PowerDensity.Zero, WattsPerCubicMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1); - Assert.False(wattpercubicmeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - PowerDensity wattpercubicmeter = PowerDensity.FromWattsPerCubicMeter(1); - Assert.False(wattpercubicmeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(PowerDensityUnit.Undefined, PowerDensity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(PowerDensityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == PowerDensityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/PowerRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/PowerRatioTestsBase.g.cs deleted file mode 100644 index 6b544593f8..0000000000 --- a/UnitsNet.Tests/GeneratedCode/PowerRatioTestsBase.g.cs +++ /dev/null @@ -1,239 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of PowerRatio. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PowerRatioTestsBase - { - protected abstract double DecibelMilliwattsInOneDecibelWatt { get; } - protected abstract double DecibelWattsInOneDecibelWatt { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DecibelMilliwattsTolerance { get { return 1e-5; } } - protected virtual double DecibelWattsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new PowerRatio((double)0.0, PowerRatioUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new PowerRatio(double.PositiveInfinity, PowerRatioUnit.DecibelWatt)); - Assert.Throws(() => new PowerRatio(double.NegativeInfinity, PowerRatioUnit.DecibelWatt)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new PowerRatio(double.NaN, PowerRatioUnit.DecibelWatt)); - } - - [Fact] - public void DecibelWattToPowerRatioUnits() - { - PowerRatio decibelwatt = PowerRatio.FromDecibelWatts(1); - AssertEx.EqualTolerance(DecibelMilliwattsInOneDecibelWatt, decibelwatt.DecibelMilliwatts, DecibelMilliwattsTolerance); - AssertEx.EqualTolerance(DecibelWattsInOneDecibelWatt, decibelwatt.DecibelWatts, DecibelWattsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, PowerRatio.From(1, PowerRatioUnit.DecibelMilliwatt).DecibelMilliwatts, DecibelMilliwattsTolerance); - AssertEx.EqualTolerance(1, PowerRatio.From(1, PowerRatioUnit.DecibelWatt).DecibelWatts, DecibelWattsTolerance); - } - - [Fact] - public void FromDecibelWatts_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => PowerRatio.FromDecibelWatts(double.PositiveInfinity)); - Assert.Throws(() => PowerRatio.FromDecibelWatts(double.NegativeInfinity)); - } - - [Fact] - public void FromDecibelWatts_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => PowerRatio.FromDecibelWatts(double.NaN)); - } - - [Fact] - public void As() - { - var decibelwatt = PowerRatio.FromDecibelWatts(1); - AssertEx.EqualTolerance(DecibelMilliwattsInOneDecibelWatt, decibelwatt.As(PowerRatioUnit.DecibelMilliwatt), DecibelMilliwattsTolerance); - AssertEx.EqualTolerance(DecibelWattsInOneDecibelWatt, decibelwatt.As(PowerRatioUnit.DecibelWatt), DecibelWattsTolerance); - } - - [Fact] - public void ToUnit() - { - var decibelwatt = PowerRatio.FromDecibelWatts(1); - - var decibelmilliwattQuantity = decibelwatt.ToUnit(PowerRatioUnit.DecibelMilliwatt); - AssertEx.EqualTolerance(DecibelMilliwattsInOneDecibelWatt, (double)decibelmilliwattQuantity.Value, DecibelMilliwattsTolerance); - Assert.Equal(PowerRatioUnit.DecibelMilliwatt, decibelmilliwattQuantity.Unit); - - var decibelwattQuantity = decibelwatt.ToUnit(PowerRatioUnit.DecibelWatt); - AssertEx.EqualTolerance(DecibelWattsInOneDecibelWatt, (double)decibelwattQuantity.Value, DecibelWattsTolerance); - Assert.Equal(PowerRatioUnit.DecibelWatt, decibelwattQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - PowerRatio decibelwatt = PowerRatio.FromDecibelWatts(1); - AssertEx.EqualTolerance(1, PowerRatio.FromDecibelMilliwatts(decibelwatt.DecibelMilliwatts).DecibelWatts, DecibelMilliwattsTolerance); - AssertEx.EqualTolerance(1, PowerRatio.FromDecibelWatts(decibelwatt.DecibelWatts).DecibelWatts, DecibelWattsTolerance); - } - - [Fact] - public void LogarithmicArithmeticOperators() - { - PowerRatio v = PowerRatio.FromDecibelWatts(40); - AssertEx.EqualTolerance(-40, -v.DecibelWatts, DecibelWattsTolerance); - AssertLogarithmicAddition(); - AssertLogarithmicSubtraction(); - AssertEx.EqualTolerance(50, (v*10).DecibelWatts, DecibelWattsTolerance); - AssertEx.EqualTolerance(50, (10*v).DecibelWatts, DecibelWattsTolerance); - AssertEx.EqualTolerance(35, (v/5).DecibelWatts, DecibelWattsTolerance); - AssertEx.EqualTolerance(35, v/PowerRatio.FromDecibelWatts(5), DecibelWattsTolerance); - } - - protected abstract void AssertLogarithmicAddition(); - - protected abstract void AssertLogarithmicSubtraction(); - - - [Fact] - public void ComparisonOperators() - { - PowerRatio oneDecibelWatt = PowerRatio.FromDecibelWatts(1); - PowerRatio twoDecibelWatts = PowerRatio.FromDecibelWatts(2); - - Assert.True(oneDecibelWatt < twoDecibelWatts); - Assert.True(oneDecibelWatt <= twoDecibelWatts); - Assert.True(twoDecibelWatts > oneDecibelWatt); - Assert.True(twoDecibelWatts >= oneDecibelWatt); - - Assert.False(oneDecibelWatt > twoDecibelWatts); - Assert.False(oneDecibelWatt >= twoDecibelWatts); - Assert.False(twoDecibelWatts < oneDecibelWatt); - Assert.False(twoDecibelWatts <= oneDecibelWatt); - } - - [Fact] - public void CompareToIsImplemented() - { - PowerRatio decibelwatt = PowerRatio.FromDecibelWatts(1); - Assert.Equal(0, decibelwatt.CompareTo(decibelwatt)); - Assert.True(decibelwatt.CompareTo(PowerRatio.Zero) > 0); - Assert.True(PowerRatio.Zero.CompareTo(decibelwatt) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - PowerRatio decibelwatt = PowerRatio.FromDecibelWatts(1); - Assert.Throws(() => decibelwatt.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - PowerRatio decibelwatt = PowerRatio.FromDecibelWatts(1); - Assert.Throws(() => decibelwatt.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - PowerRatio v = PowerRatio.FromDecibelWatts(1); - Assert.True(v.Equals(PowerRatio.FromDecibelWatts(1), DecibelWattsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(PowerRatio.Zero, DecibelWattsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - PowerRatio decibelwatt = PowerRatio.FromDecibelWatts(1); - Assert.False(decibelwatt.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - PowerRatio decibelwatt = PowerRatio.FromDecibelWatts(1); - Assert.False(decibelwatt.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(PowerRatioUnit.Undefined, PowerRatio.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(PowerRatioUnit)).Cast(); - foreach(var unit in units) - { - if(unit == PowerRatioUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/PowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/PowerTestsBase.g.cs deleted file mode 100644 index efb6e9a3c0..0000000000 --- a/UnitsNet.Tests/GeneratedCode/PowerTestsBase.g.cs +++ /dev/null @@ -1,390 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Power. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PowerTestsBase - { - protected abstract double BoilerHorsepowerInOneWatt { get; } - protected abstract double BritishThermalUnitsPerHourInOneWatt { get; } - protected abstract double DecawattsInOneWatt { get; } - protected abstract double DeciwattsInOneWatt { get; } - protected abstract double ElectricalHorsepowerInOneWatt { get; } - protected abstract double FemtowattsInOneWatt { get; } - protected abstract double GigawattsInOneWatt { get; } - protected abstract double HydraulicHorsepowerInOneWatt { get; } - protected abstract double KilobritishThermalUnitsPerHourInOneWatt { get; } - protected abstract double KilowattsInOneWatt { get; } - protected abstract double MechanicalHorsepowerInOneWatt { get; } - protected abstract double MegawattsInOneWatt { get; } - protected abstract double MetricHorsepowerInOneWatt { get; } - protected abstract double MicrowattsInOneWatt { get; } - protected abstract double MilliwattsInOneWatt { get; } - protected abstract double NanowattsInOneWatt { get; } - protected abstract double PetawattsInOneWatt { get; } - protected abstract double PicowattsInOneWatt { get; } - protected abstract double TerawattsInOneWatt { get; } - protected abstract double WattsInOneWatt { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double BoilerHorsepowerTolerance { get { return 1e-5; } } - protected virtual double BritishThermalUnitsPerHourTolerance { get { return 1e-5; } } - protected virtual double DecawattsTolerance { get { return 1e-5; } } - protected virtual double DeciwattsTolerance { get { return 1e-5; } } - protected virtual double ElectricalHorsepowerTolerance { get { return 1e-5; } } - protected virtual double FemtowattsTolerance { get { return 1e-5; } } - protected virtual double GigawattsTolerance { get { return 1e-5; } } - protected virtual double HydraulicHorsepowerTolerance { get { return 1e-5; } } - protected virtual double KilobritishThermalUnitsPerHourTolerance { get { return 1e-5; } } - protected virtual double KilowattsTolerance { get { return 1e-5; } } - protected virtual double MechanicalHorsepowerTolerance { get { return 1e-5; } } - protected virtual double MegawattsTolerance { get { return 1e-5; } } - protected virtual double MetricHorsepowerTolerance { get { return 1e-5; } } - protected virtual double MicrowattsTolerance { get { return 1e-5; } } - protected virtual double MilliwattsTolerance { get { return 1e-5; } } - protected virtual double NanowattsTolerance { get { return 1e-5; } } - protected virtual double PetawattsTolerance { get { return 1e-5; } } - protected virtual double PicowattsTolerance { get { return 1e-5; } } - protected virtual double TerawattsTolerance { get { return 1e-5; } } - protected virtual double WattsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Power((decimal)0.0, PowerUnit.Undefined)); - } - - - [Fact] - public void WattToPowerUnits() - { - Power watt = Power.FromWatts(1); - AssertEx.EqualTolerance(BoilerHorsepowerInOneWatt, watt.BoilerHorsepower, BoilerHorsepowerTolerance); - AssertEx.EqualTolerance(BritishThermalUnitsPerHourInOneWatt, watt.BritishThermalUnitsPerHour, BritishThermalUnitsPerHourTolerance); - AssertEx.EqualTolerance(DecawattsInOneWatt, watt.Decawatts, DecawattsTolerance); - AssertEx.EqualTolerance(DeciwattsInOneWatt, watt.Deciwatts, DeciwattsTolerance); - AssertEx.EqualTolerance(ElectricalHorsepowerInOneWatt, watt.ElectricalHorsepower, ElectricalHorsepowerTolerance); - AssertEx.EqualTolerance(FemtowattsInOneWatt, watt.Femtowatts, FemtowattsTolerance); - AssertEx.EqualTolerance(GigawattsInOneWatt, watt.Gigawatts, GigawattsTolerance); - AssertEx.EqualTolerance(HydraulicHorsepowerInOneWatt, watt.HydraulicHorsepower, HydraulicHorsepowerTolerance); - AssertEx.EqualTolerance(KilobritishThermalUnitsPerHourInOneWatt, watt.KilobritishThermalUnitsPerHour, KilobritishThermalUnitsPerHourTolerance); - AssertEx.EqualTolerance(KilowattsInOneWatt, watt.Kilowatts, KilowattsTolerance); - AssertEx.EqualTolerance(MechanicalHorsepowerInOneWatt, watt.MechanicalHorsepower, MechanicalHorsepowerTolerance); - AssertEx.EqualTolerance(MegawattsInOneWatt, watt.Megawatts, MegawattsTolerance); - AssertEx.EqualTolerance(MetricHorsepowerInOneWatt, watt.MetricHorsepower, MetricHorsepowerTolerance); - AssertEx.EqualTolerance(MicrowattsInOneWatt, watt.Microwatts, MicrowattsTolerance); - AssertEx.EqualTolerance(MilliwattsInOneWatt, watt.Milliwatts, MilliwattsTolerance); - AssertEx.EqualTolerance(NanowattsInOneWatt, watt.Nanowatts, NanowattsTolerance); - AssertEx.EqualTolerance(PetawattsInOneWatt, watt.Petawatts, PetawattsTolerance); - AssertEx.EqualTolerance(PicowattsInOneWatt, watt.Picowatts, PicowattsTolerance); - AssertEx.EqualTolerance(TerawattsInOneWatt, watt.Terawatts, TerawattsTolerance); - AssertEx.EqualTolerance(WattsInOneWatt, watt.Watts, WattsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.BoilerHorsepower).BoilerHorsepower, BoilerHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.BritishThermalUnitPerHour).BritishThermalUnitsPerHour, BritishThermalUnitsPerHourTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Decawatt).Decawatts, DecawattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Deciwatt).Deciwatts, DeciwattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.ElectricalHorsepower).ElectricalHorsepower, ElectricalHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Femtowatt).Femtowatts, FemtowattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Gigawatt).Gigawatts, GigawattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.HydraulicHorsepower).HydraulicHorsepower, HydraulicHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.KilobritishThermalUnitPerHour).KilobritishThermalUnitsPerHour, KilobritishThermalUnitsPerHourTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Kilowatt).Kilowatts, KilowattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.MechanicalHorsepower).MechanicalHorsepower, MechanicalHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Megawatt).Megawatts, MegawattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.MetricHorsepower).MetricHorsepower, MetricHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Microwatt).Microwatts, MicrowattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Milliwatt).Milliwatts, MilliwattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Nanowatt).Nanowatts, NanowattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Petawatt).Petawatts, PetawattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Picowatt).Picowatts, PicowattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Terawatt).Terawatts, TerawattsTolerance); - AssertEx.EqualTolerance(1, Power.From(1, PowerUnit.Watt).Watts, WattsTolerance); - } - - - [Fact] - public void As() - { - var watt = Power.FromWatts(1); - AssertEx.EqualTolerance(BoilerHorsepowerInOneWatt, watt.As(PowerUnit.BoilerHorsepower), BoilerHorsepowerTolerance); - AssertEx.EqualTolerance(BritishThermalUnitsPerHourInOneWatt, watt.As(PowerUnit.BritishThermalUnitPerHour), BritishThermalUnitsPerHourTolerance); - AssertEx.EqualTolerance(DecawattsInOneWatt, watt.As(PowerUnit.Decawatt), DecawattsTolerance); - AssertEx.EqualTolerance(DeciwattsInOneWatt, watt.As(PowerUnit.Deciwatt), DeciwattsTolerance); - AssertEx.EqualTolerance(ElectricalHorsepowerInOneWatt, watt.As(PowerUnit.ElectricalHorsepower), ElectricalHorsepowerTolerance); - AssertEx.EqualTolerance(FemtowattsInOneWatt, watt.As(PowerUnit.Femtowatt), FemtowattsTolerance); - AssertEx.EqualTolerance(GigawattsInOneWatt, watt.As(PowerUnit.Gigawatt), GigawattsTolerance); - AssertEx.EqualTolerance(HydraulicHorsepowerInOneWatt, watt.As(PowerUnit.HydraulicHorsepower), HydraulicHorsepowerTolerance); - AssertEx.EqualTolerance(KilobritishThermalUnitsPerHourInOneWatt, watt.As(PowerUnit.KilobritishThermalUnitPerHour), KilobritishThermalUnitsPerHourTolerance); - AssertEx.EqualTolerance(KilowattsInOneWatt, watt.As(PowerUnit.Kilowatt), KilowattsTolerance); - AssertEx.EqualTolerance(MechanicalHorsepowerInOneWatt, watt.As(PowerUnit.MechanicalHorsepower), MechanicalHorsepowerTolerance); - AssertEx.EqualTolerance(MegawattsInOneWatt, watt.As(PowerUnit.Megawatt), MegawattsTolerance); - AssertEx.EqualTolerance(MetricHorsepowerInOneWatt, watt.As(PowerUnit.MetricHorsepower), MetricHorsepowerTolerance); - AssertEx.EqualTolerance(MicrowattsInOneWatt, watt.As(PowerUnit.Microwatt), MicrowattsTolerance); - AssertEx.EqualTolerance(MilliwattsInOneWatt, watt.As(PowerUnit.Milliwatt), MilliwattsTolerance); - AssertEx.EqualTolerance(NanowattsInOneWatt, watt.As(PowerUnit.Nanowatt), NanowattsTolerance); - AssertEx.EqualTolerance(PetawattsInOneWatt, watt.As(PowerUnit.Petawatt), PetawattsTolerance); - AssertEx.EqualTolerance(PicowattsInOneWatt, watt.As(PowerUnit.Picowatt), PicowattsTolerance); - AssertEx.EqualTolerance(TerawattsInOneWatt, watt.As(PowerUnit.Terawatt), TerawattsTolerance); - AssertEx.EqualTolerance(WattsInOneWatt, watt.As(PowerUnit.Watt), WattsTolerance); - } - - [Fact] - public void ToUnit() - { - var watt = Power.FromWatts(1); - - var boilerhorsepowerQuantity = watt.ToUnit(PowerUnit.BoilerHorsepower); - AssertEx.EqualTolerance(BoilerHorsepowerInOneWatt, (double)boilerhorsepowerQuantity.Value, BoilerHorsepowerTolerance); - Assert.Equal(PowerUnit.BoilerHorsepower, boilerhorsepowerQuantity.Unit); - - var britishthermalunitperhourQuantity = watt.ToUnit(PowerUnit.BritishThermalUnitPerHour); - AssertEx.EqualTolerance(BritishThermalUnitsPerHourInOneWatt, (double)britishthermalunitperhourQuantity.Value, BritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.BritishThermalUnitPerHour, britishthermalunitperhourQuantity.Unit); - - var decawattQuantity = watt.ToUnit(PowerUnit.Decawatt); - AssertEx.EqualTolerance(DecawattsInOneWatt, (double)decawattQuantity.Value, DecawattsTolerance); - Assert.Equal(PowerUnit.Decawatt, decawattQuantity.Unit); - - var deciwattQuantity = watt.ToUnit(PowerUnit.Deciwatt); - AssertEx.EqualTolerance(DeciwattsInOneWatt, (double)deciwattQuantity.Value, DeciwattsTolerance); - Assert.Equal(PowerUnit.Deciwatt, deciwattQuantity.Unit); - - var electricalhorsepowerQuantity = watt.ToUnit(PowerUnit.ElectricalHorsepower); - AssertEx.EqualTolerance(ElectricalHorsepowerInOneWatt, (double)electricalhorsepowerQuantity.Value, ElectricalHorsepowerTolerance); - Assert.Equal(PowerUnit.ElectricalHorsepower, electricalhorsepowerQuantity.Unit); - - var femtowattQuantity = watt.ToUnit(PowerUnit.Femtowatt); - AssertEx.EqualTolerance(FemtowattsInOneWatt, (double)femtowattQuantity.Value, FemtowattsTolerance); - Assert.Equal(PowerUnit.Femtowatt, femtowattQuantity.Unit); - - var gigawattQuantity = watt.ToUnit(PowerUnit.Gigawatt); - AssertEx.EqualTolerance(GigawattsInOneWatt, (double)gigawattQuantity.Value, GigawattsTolerance); - Assert.Equal(PowerUnit.Gigawatt, gigawattQuantity.Unit); - - var hydraulichorsepowerQuantity = watt.ToUnit(PowerUnit.HydraulicHorsepower); - AssertEx.EqualTolerance(HydraulicHorsepowerInOneWatt, (double)hydraulichorsepowerQuantity.Value, HydraulicHorsepowerTolerance); - Assert.Equal(PowerUnit.HydraulicHorsepower, hydraulichorsepowerQuantity.Unit); - - var kilobritishthermalunitperhourQuantity = watt.ToUnit(PowerUnit.KilobritishThermalUnitPerHour); - AssertEx.EqualTolerance(KilobritishThermalUnitsPerHourInOneWatt, (double)kilobritishthermalunitperhourQuantity.Value, KilobritishThermalUnitsPerHourTolerance); - Assert.Equal(PowerUnit.KilobritishThermalUnitPerHour, kilobritishthermalunitperhourQuantity.Unit); - - var kilowattQuantity = watt.ToUnit(PowerUnit.Kilowatt); - AssertEx.EqualTolerance(KilowattsInOneWatt, (double)kilowattQuantity.Value, KilowattsTolerance); - Assert.Equal(PowerUnit.Kilowatt, kilowattQuantity.Unit); - - var mechanicalhorsepowerQuantity = watt.ToUnit(PowerUnit.MechanicalHorsepower); - AssertEx.EqualTolerance(MechanicalHorsepowerInOneWatt, (double)mechanicalhorsepowerQuantity.Value, MechanicalHorsepowerTolerance); - Assert.Equal(PowerUnit.MechanicalHorsepower, mechanicalhorsepowerQuantity.Unit); - - var megawattQuantity = watt.ToUnit(PowerUnit.Megawatt); - AssertEx.EqualTolerance(MegawattsInOneWatt, (double)megawattQuantity.Value, MegawattsTolerance); - Assert.Equal(PowerUnit.Megawatt, megawattQuantity.Unit); - - var metrichorsepowerQuantity = watt.ToUnit(PowerUnit.MetricHorsepower); - AssertEx.EqualTolerance(MetricHorsepowerInOneWatt, (double)metrichorsepowerQuantity.Value, MetricHorsepowerTolerance); - Assert.Equal(PowerUnit.MetricHorsepower, metrichorsepowerQuantity.Unit); - - var microwattQuantity = watt.ToUnit(PowerUnit.Microwatt); - AssertEx.EqualTolerance(MicrowattsInOneWatt, (double)microwattQuantity.Value, MicrowattsTolerance); - Assert.Equal(PowerUnit.Microwatt, microwattQuantity.Unit); - - var milliwattQuantity = watt.ToUnit(PowerUnit.Milliwatt); - AssertEx.EqualTolerance(MilliwattsInOneWatt, (double)milliwattQuantity.Value, MilliwattsTolerance); - Assert.Equal(PowerUnit.Milliwatt, milliwattQuantity.Unit); - - var nanowattQuantity = watt.ToUnit(PowerUnit.Nanowatt); - AssertEx.EqualTolerance(NanowattsInOneWatt, (double)nanowattQuantity.Value, NanowattsTolerance); - Assert.Equal(PowerUnit.Nanowatt, nanowattQuantity.Unit); - - var petawattQuantity = watt.ToUnit(PowerUnit.Petawatt); - AssertEx.EqualTolerance(PetawattsInOneWatt, (double)petawattQuantity.Value, PetawattsTolerance); - Assert.Equal(PowerUnit.Petawatt, petawattQuantity.Unit); - - var picowattQuantity = watt.ToUnit(PowerUnit.Picowatt); - AssertEx.EqualTolerance(PicowattsInOneWatt, (double)picowattQuantity.Value, PicowattsTolerance); - Assert.Equal(PowerUnit.Picowatt, picowattQuantity.Unit); - - var terawattQuantity = watt.ToUnit(PowerUnit.Terawatt); - AssertEx.EqualTolerance(TerawattsInOneWatt, (double)terawattQuantity.Value, TerawattsTolerance); - Assert.Equal(PowerUnit.Terawatt, terawattQuantity.Unit); - - var wattQuantity = watt.ToUnit(PowerUnit.Watt); - AssertEx.EqualTolerance(WattsInOneWatt, (double)wattQuantity.Value, WattsTolerance); - Assert.Equal(PowerUnit.Watt, wattQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Power watt = Power.FromWatts(1); - AssertEx.EqualTolerance(1, Power.FromBoilerHorsepower(watt.BoilerHorsepower).Watts, BoilerHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.FromBritishThermalUnitsPerHour(watt.BritishThermalUnitsPerHour).Watts, BritishThermalUnitsPerHourTolerance); - AssertEx.EqualTolerance(1, Power.FromDecawatts(watt.Decawatts).Watts, DecawattsTolerance); - AssertEx.EqualTolerance(1, Power.FromDeciwatts(watt.Deciwatts).Watts, DeciwattsTolerance); - AssertEx.EqualTolerance(1, Power.FromElectricalHorsepower(watt.ElectricalHorsepower).Watts, ElectricalHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.FromFemtowatts(watt.Femtowatts).Watts, FemtowattsTolerance); - AssertEx.EqualTolerance(1, Power.FromGigawatts(watt.Gigawatts).Watts, GigawattsTolerance); - AssertEx.EqualTolerance(1, Power.FromHydraulicHorsepower(watt.HydraulicHorsepower).Watts, HydraulicHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.FromKilobritishThermalUnitsPerHour(watt.KilobritishThermalUnitsPerHour).Watts, KilobritishThermalUnitsPerHourTolerance); - AssertEx.EqualTolerance(1, Power.FromKilowatts(watt.Kilowatts).Watts, KilowattsTolerance); - AssertEx.EqualTolerance(1, Power.FromMechanicalHorsepower(watt.MechanicalHorsepower).Watts, MechanicalHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.FromMegawatts(watt.Megawatts).Watts, MegawattsTolerance); - AssertEx.EqualTolerance(1, Power.FromMetricHorsepower(watt.MetricHorsepower).Watts, MetricHorsepowerTolerance); - AssertEx.EqualTolerance(1, Power.FromMicrowatts(watt.Microwatts).Watts, MicrowattsTolerance); - AssertEx.EqualTolerance(1, Power.FromMilliwatts(watt.Milliwatts).Watts, MilliwattsTolerance); - AssertEx.EqualTolerance(1, Power.FromNanowatts(watt.Nanowatts).Watts, NanowattsTolerance); - AssertEx.EqualTolerance(1, Power.FromPetawatts(watt.Petawatts).Watts, PetawattsTolerance); - AssertEx.EqualTolerance(1, Power.FromPicowatts(watt.Picowatts).Watts, PicowattsTolerance); - AssertEx.EqualTolerance(1, Power.FromTerawatts(watt.Terawatts).Watts, TerawattsTolerance); - AssertEx.EqualTolerance(1, Power.FromWatts(watt.Watts).Watts, WattsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Power v = Power.FromWatts(1); - AssertEx.EqualTolerance(-1, -v.Watts, WattsTolerance); - AssertEx.EqualTolerance(2, (Power.FromWatts(3)-v).Watts, WattsTolerance); - AssertEx.EqualTolerance(2, (v + v).Watts, WattsTolerance); - AssertEx.EqualTolerance(10, (v*10).Watts, WattsTolerance); - AssertEx.EqualTolerance(10, (10*v).Watts, WattsTolerance); - AssertEx.EqualTolerance(2, (Power.FromWatts(10)/5).Watts, WattsTolerance); - AssertEx.EqualTolerance(2, Power.FromWatts(10)/Power.FromWatts(5), WattsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Power oneWatt = Power.FromWatts(1); - Power twoWatts = Power.FromWatts(2); - - Assert.True(oneWatt < twoWatts); - Assert.True(oneWatt <= twoWatts); - Assert.True(twoWatts > oneWatt); - Assert.True(twoWatts >= oneWatt); - - Assert.False(oneWatt > twoWatts); - Assert.False(oneWatt >= twoWatts); - Assert.False(twoWatts < oneWatt); - Assert.False(twoWatts <= oneWatt); - } - - [Fact] - public void CompareToIsImplemented() - { - Power watt = Power.FromWatts(1); - Assert.Equal(0, watt.CompareTo(watt)); - Assert.True(watt.CompareTo(Power.Zero) > 0); - Assert.True(Power.Zero.CompareTo(watt) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Power watt = Power.FromWatts(1); - Assert.Throws(() => watt.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Power watt = Power.FromWatts(1); - Assert.Throws(() => watt.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Power v = Power.FromWatts(1); - Assert.True(v.Equals(Power.FromWatts(1), WattsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Power.Zero, WattsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Power watt = Power.FromWatts(1); - Assert.False(watt.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Power watt = Power.FromWatts(1); - Assert.False(watt.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(PowerUnit.Undefined, Power.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(PowerUnit)).Cast(); - foreach(var unit in units) - { - if(unit == PowerUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/PressureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/PressureChangeRateTestsBase.g.cs deleted file mode 100644 index 44e37ef45e..0000000000 --- a/UnitsNet.Tests/GeneratedCode/PressureChangeRateTestsBase.g.cs +++ /dev/null @@ -1,254 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of PressureChangeRate. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PressureChangeRateTestsBase - { - protected abstract double AtmospheresPerSecondInOnePascalPerSecond { get; } - protected abstract double KilopascalsPerSecondInOnePascalPerSecond { get; } - protected abstract double MegapascalsPerSecondInOnePascalPerSecond { get; } - protected abstract double PascalsPerSecondInOnePascalPerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double AtmospheresPerSecondTolerance { get { return 1e-5; } } - protected virtual double KilopascalsPerSecondTolerance { get { return 1e-5; } } - protected virtual double MegapascalsPerSecondTolerance { get { return 1e-5; } } - protected virtual double PascalsPerSecondTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new PressureChangeRate((double)0.0, PressureChangeRateUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new PressureChangeRate(double.PositiveInfinity, PressureChangeRateUnit.PascalPerSecond)); - Assert.Throws(() => new PressureChangeRate(double.NegativeInfinity, PressureChangeRateUnit.PascalPerSecond)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new PressureChangeRate(double.NaN, PressureChangeRateUnit.PascalPerSecond)); - } - - [Fact] - public void PascalPerSecondToPressureChangeRateUnits() - { - PressureChangeRate pascalpersecond = PressureChangeRate.FromPascalsPerSecond(1); - AssertEx.EqualTolerance(AtmospheresPerSecondInOnePascalPerSecond, pascalpersecond.AtmospheresPerSecond, AtmospheresPerSecondTolerance); - AssertEx.EqualTolerance(KilopascalsPerSecondInOnePascalPerSecond, pascalpersecond.KilopascalsPerSecond, KilopascalsPerSecondTolerance); - AssertEx.EqualTolerance(MegapascalsPerSecondInOnePascalPerSecond, pascalpersecond.MegapascalsPerSecond, MegapascalsPerSecondTolerance); - AssertEx.EqualTolerance(PascalsPerSecondInOnePascalPerSecond, pascalpersecond.PascalsPerSecond, PascalsPerSecondTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, PressureChangeRate.From(1, PressureChangeRateUnit.AtmospherePerSecond).AtmospheresPerSecond, AtmospheresPerSecondTolerance); - AssertEx.EqualTolerance(1, PressureChangeRate.From(1, PressureChangeRateUnit.KilopascalPerSecond).KilopascalsPerSecond, KilopascalsPerSecondTolerance); - AssertEx.EqualTolerance(1, PressureChangeRate.From(1, PressureChangeRateUnit.MegapascalPerSecond).MegapascalsPerSecond, MegapascalsPerSecondTolerance); - AssertEx.EqualTolerance(1, PressureChangeRate.From(1, PressureChangeRateUnit.PascalPerSecond).PascalsPerSecond, PascalsPerSecondTolerance); - } - - [Fact] - public void FromPascalsPerSecond_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => PressureChangeRate.FromPascalsPerSecond(double.PositiveInfinity)); - Assert.Throws(() => PressureChangeRate.FromPascalsPerSecond(double.NegativeInfinity)); - } - - [Fact] - public void FromPascalsPerSecond_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => PressureChangeRate.FromPascalsPerSecond(double.NaN)); - } - - [Fact] - public void As() - { - var pascalpersecond = PressureChangeRate.FromPascalsPerSecond(1); - AssertEx.EqualTolerance(AtmospheresPerSecondInOnePascalPerSecond, pascalpersecond.As(PressureChangeRateUnit.AtmospherePerSecond), AtmospheresPerSecondTolerance); - AssertEx.EqualTolerance(KilopascalsPerSecondInOnePascalPerSecond, pascalpersecond.As(PressureChangeRateUnit.KilopascalPerSecond), KilopascalsPerSecondTolerance); - AssertEx.EqualTolerance(MegapascalsPerSecondInOnePascalPerSecond, pascalpersecond.As(PressureChangeRateUnit.MegapascalPerSecond), MegapascalsPerSecondTolerance); - AssertEx.EqualTolerance(PascalsPerSecondInOnePascalPerSecond, pascalpersecond.As(PressureChangeRateUnit.PascalPerSecond), PascalsPerSecondTolerance); - } - - [Fact] - public void ToUnit() - { - var pascalpersecond = PressureChangeRate.FromPascalsPerSecond(1); - - var atmospherepersecondQuantity = pascalpersecond.ToUnit(PressureChangeRateUnit.AtmospherePerSecond); - AssertEx.EqualTolerance(AtmospheresPerSecondInOnePascalPerSecond, (double)atmospherepersecondQuantity.Value, AtmospheresPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.AtmospherePerSecond, atmospherepersecondQuantity.Unit); - - var kilopascalpersecondQuantity = pascalpersecond.ToUnit(PressureChangeRateUnit.KilopascalPerSecond); - AssertEx.EqualTolerance(KilopascalsPerSecondInOnePascalPerSecond, (double)kilopascalpersecondQuantity.Value, KilopascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.KilopascalPerSecond, kilopascalpersecondQuantity.Unit); - - var megapascalpersecondQuantity = pascalpersecond.ToUnit(PressureChangeRateUnit.MegapascalPerSecond); - AssertEx.EqualTolerance(MegapascalsPerSecondInOnePascalPerSecond, (double)megapascalpersecondQuantity.Value, MegapascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.MegapascalPerSecond, megapascalpersecondQuantity.Unit); - - var pascalpersecondQuantity = pascalpersecond.ToUnit(PressureChangeRateUnit.PascalPerSecond); - AssertEx.EqualTolerance(PascalsPerSecondInOnePascalPerSecond, (double)pascalpersecondQuantity.Value, PascalsPerSecondTolerance); - Assert.Equal(PressureChangeRateUnit.PascalPerSecond, pascalpersecondQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - PressureChangeRate pascalpersecond = PressureChangeRate.FromPascalsPerSecond(1); - AssertEx.EqualTolerance(1, PressureChangeRate.FromAtmospheresPerSecond(pascalpersecond.AtmospheresPerSecond).PascalsPerSecond, AtmospheresPerSecondTolerance); - AssertEx.EqualTolerance(1, PressureChangeRate.FromKilopascalsPerSecond(pascalpersecond.KilopascalsPerSecond).PascalsPerSecond, KilopascalsPerSecondTolerance); - AssertEx.EqualTolerance(1, PressureChangeRate.FromMegapascalsPerSecond(pascalpersecond.MegapascalsPerSecond).PascalsPerSecond, MegapascalsPerSecondTolerance); - AssertEx.EqualTolerance(1, PressureChangeRate.FromPascalsPerSecond(pascalpersecond.PascalsPerSecond).PascalsPerSecond, PascalsPerSecondTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - PressureChangeRate v = PressureChangeRate.FromPascalsPerSecond(1); - AssertEx.EqualTolerance(-1, -v.PascalsPerSecond, PascalsPerSecondTolerance); - AssertEx.EqualTolerance(2, (PressureChangeRate.FromPascalsPerSecond(3)-v).PascalsPerSecond, PascalsPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).PascalsPerSecond, PascalsPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).PascalsPerSecond, PascalsPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).PascalsPerSecond, PascalsPerSecondTolerance); - AssertEx.EqualTolerance(2, (PressureChangeRate.FromPascalsPerSecond(10)/5).PascalsPerSecond, PascalsPerSecondTolerance); - AssertEx.EqualTolerance(2, PressureChangeRate.FromPascalsPerSecond(10)/PressureChangeRate.FromPascalsPerSecond(5), PascalsPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - PressureChangeRate onePascalPerSecond = PressureChangeRate.FromPascalsPerSecond(1); - PressureChangeRate twoPascalsPerSecond = PressureChangeRate.FromPascalsPerSecond(2); - - Assert.True(onePascalPerSecond < twoPascalsPerSecond); - Assert.True(onePascalPerSecond <= twoPascalsPerSecond); - Assert.True(twoPascalsPerSecond > onePascalPerSecond); - Assert.True(twoPascalsPerSecond >= onePascalPerSecond); - - Assert.False(onePascalPerSecond > twoPascalsPerSecond); - Assert.False(onePascalPerSecond >= twoPascalsPerSecond); - Assert.False(twoPascalsPerSecond < onePascalPerSecond); - Assert.False(twoPascalsPerSecond <= onePascalPerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - PressureChangeRate pascalpersecond = PressureChangeRate.FromPascalsPerSecond(1); - Assert.Equal(0, pascalpersecond.CompareTo(pascalpersecond)); - Assert.True(pascalpersecond.CompareTo(PressureChangeRate.Zero) > 0); - Assert.True(PressureChangeRate.Zero.CompareTo(pascalpersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - PressureChangeRate pascalpersecond = PressureChangeRate.FromPascalsPerSecond(1); - Assert.Throws(() => pascalpersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - PressureChangeRate pascalpersecond = PressureChangeRate.FromPascalsPerSecond(1); - Assert.Throws(() => pascalpersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - PressureChangeRate v = PressureChangeRate.FromPascalsPerSecond(1); - Assert.True(v.Equals(PressureChangeRate.FromPascalsPerSecond(1), PascalsPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(PressureChangeRate.Zero, PascalsPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - PressureChangeRate pascalpersecond = PressureChangeRate.FromPascalsPerSecond(1); - Assert.False(pascalpersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - PressureChangeRate pascalpersecond = PressureChangeRate.FromPascalsPerSecond(1); - Assert.False(pascalpersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(PressureChangeRateUnit.Undefined, PressureChangeRate.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(PressureChangeRateUnit)).Cast(); - foreach(var unit in units) - { - if(unit == PressureChangeRateUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/PressureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/PressureTestsBase.g.cs deleted file mode 100644 index 2204eb0ee3..0000000000 --- a/UnitsNet.Tests/GeneratedCode/PressureTestsBase.g.cs +++ /dev/null @@ -1,584 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Pressure. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PressureTestsBase - { - protected abstract double AtmospheresInOnePascal { get; } - protected abstract double BarsInOnePascal { get; } - protected abstract double CentibarsInOnePascal { get; } - protected abstract double DecapascalsInOnePascal { get; } - protected abstract double DecibarsInOnePascal { get; } - protected abstract double FeetOfHeadInOnePascal { get; } - protected abstract double GigapascalsInOnePascal { get; } - protected abstract double HectopascalsInOnePascal { get; } - protected abstract double InchesOfMercuryInOnePascal { get; } - protected abstract double KilobarsInOnePascal { get; } - protected abstract double KilogramsForcePerSquareCentimeterInOnePascal { get; } - protected abstract double KilogramsForcePerSquareMeterInOnePascal { get; } - protected abstract double KilogramsForcePerSquareMillimeterInOnePascal { get; } - protected abstract double KilonewtonsPerSquareCentimeterInOnePascal { get; } - protected abstract double KilonewtonsPerSquareMeterInOnePascal { get; } - protected abstract double KilonewtonsPerSquareMillimeterInOnePascal { get; } - protected abstract double KilopascalsInOnePascal { get; } - protected abstract double KilopoundsForcePerSquareFootInOnePascal { get; } - protected abstract double KilopoundsForcePerSquareInchInOnePascal { get; } - protected abstract double MegabarsInOnePascal { get; } - protected abstract double MeganewtonsPerSquareMeterInOnePascal { get; } - protected abstract double MegapascalsInOnePascal { get; } - protected abstract double MetersOfHeadInOnePascal { get; } - protected abstract double MicropascalsInOnePascal { get; } - protected abstract double MillibarsInOnePascal { get; } - protected abstract double MillimetersOfMercuryInOnePascal { get; } - protected abstract double NewtonsPerSquareCentimeterInOnePascal { get; } - protected abstract double NewtonsPerSquareMeterInOnePascal { get; } - protected abstract double NewtonsPerSquareMillimeterInOnePascal { get; } - protected abstract double PascalsInOnePascal { get; } - protected abstract double PoundsForcePerSquareFootInOnePascal { get; } - protected abstract double PoundsForcePerSquareInchInOnePascal { get; } - protected abstract double TechnicalAtmospheresInOnePascal { get; } - protected abstract double TonnesForcePerSquareCentimeterInOnePascal { get; } - protected abstract double TonnesForcePerSquareMeterInOnePascal { get; } - protected abstract double TonnesForcePerSquareMillimeterInOnePascal { get; } - protected abstract double TorrsInOnePascal { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double AtmospheresTolerance { get { return 1e-5; } } - protected virtual double BarsTolerance { get { return 1e-5; } } - protected virtual double CentibarsTolerance { get { return 1e-5; } } - protected virtual double DecapascalsTolerance { get { return 1e-5; } } - protected virtual double DecibarsTolerance { get { return 1e-5; } } - protected virtual double FeetOfHeadTolerance { get { return 1e-5; } } - protected virtual double GigapascalsTolerance { get { return 1e-5; } } - protected virtual double HectopascalsTolerance { get { return 1e-5; } } - protected virtual double InchesOfMercuryTolerance { get { return 1e-5; } } - protected virtual double KilobarsTolerance { get { return 1e-5; } } - protected virtual double KilogramsForcePerSquareCentimeterTolerance { get { return 1e-5; } } - protected virtual double KilogramsForcePerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double KilogramsForcePerSquareMillimeterTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsPerSquareCentimeterTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsPerSquareMillimeterTolerance { get { return 1e-5; } } - protected virtual double KilopascalsTolerance { get { return 1e-5; } } - protected virtual double KilopoundsForcePerSquareFootTolerance { get { return 1e-5; } } - protected virtual double KilopoundsForcePerSquareInchTolerance { get { return 1e-5; } } - protected virtual double MegabarsTolerance { get { return 1e-5; } } - protected virtual double MeganewtonsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double MegapascalsTolerance { get { return 1e-5; } } - protected virtual double MetersOfHeadTolerance { get { return 1e-5; } } - protected virtual double MicropascalsTolerance { get { return 1e-5; } } - protected virtual double MillibarsTolerance { get { return 1e-5; } } - protected virtual double MillimetersOfMercuryTolerance { get { return 1e-5; } } - protected virtual double NewtonsPerSquareCentimeterTolerance { get { return 1e-5; } } - protected virtual double NewtonsPerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double NewtonsPerSquareMillimeterTolerance { get { return 1e-5; } } - protected virtual double PascalsTolerance { get { return 1e-5; } } - protected virtual double PoundsForcePerSquareFootTolerance { get { return 1e-5; } } - protected virtual double PoundsForcePerSquareInchTolerance { get { return 1e-5; } } - protected virtual double TechnicalAtmospheresTolerance { get { return 1e-5; } } - protected virtual double TonnesForcePerSquareCentimeterTolerance { get { return 1e-5; } } - protected virtual double TonnesForcePerSquareMeterTolerance { get { return 1e-5; } } - protected virtual double TonnesForcePerSquareMillimeterTolerance { get { return 1e-5; } } - protected virtual double TorrsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Pressure((double)0.0, PressureUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Pressure(double.PositiveInfinity, PressureUnit.Pascal)); - Assert.Throws(() => new Pressure(double.NegativeInfinity, PressureUnit.Pascal)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Pressure(double.NaN, PressureUnit.Pascal)); - } - - [Fact] - public void PascalToPressureUnits() - { - Pressure pascal = Pressure.FromPascals(1); - AssertEx.EqualTolerance(AtmospheresInOnePascal, pascal.Atmospheres, AtmospheresTolerance); - AssertEx.EqualTolerance(BarsInOnePascal, pascal.Bars, BarsTolerance); - AssertEx.EqualTolerance(CentibarsInOnePascal, pascal.Centibars, CentibarsTolerance); - AssertEx.EqualTolerance(DecapascalsInOnePascal, pascal.Decapascals, DecapascalsTolerance); - AssertEx.EqualTolerance(DecibarsInOnePascal, pascal.Decibars, DecibarsTolerance); - AssertEx.EqualTolerance(FeetOfHeadInOnePascal, pascal.FeetOfHead, FeetOfHeadTolerance); - AssertEx.EqualTolerance(GigapascalsInOnePascal, pascal.Gigapascals, GigapascalsTolerance); - AssertEx.EqualTolerance(HectopascalsInOnePascal, pascal.Hectopascals, HectopascalsTolerance); - AssertEx.EqualTolerance(InchesOfMercuryInOnePascal, pascal.InchesOfMercury, InchesOfMercuryTolerance); - AssertEx.EqualTolerance(KilobarsInOnePascal, pascal.Kilobars, KilobarsTolerance); - AssertEx.EqualTolerance(KilogramsForcePerSquareCentimeterInOnePascal, pascal.KilogramsForcePerSquareCentimeter, KilogramsForcePerSquareCentimeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerSquareMeterInOnePascal, pascal.KilogramsForcePerSquareMeter, KilogramsForcePerSquareMeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerSquareMillimeterInOnePascal, pascal.KilogramsForcePerSquareMillimeter, KilogramsForcePerSquareMillimeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerSquareCentimeterInOnePascal, pascal.KilonewtonsPerSquareCentimeter, KilonewtonsPerSquareCentimeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerSquareMeterInOnePascal, pascal.KilonewtonsPerSquareMeter, KilonewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerSquareMillimeterInOnePascal, pascal.KilonewtonsPerSquareMillimeter, KilonewtonsPerSquareMillimeterTolerance); - AssertEx.EqualTolerance(KilopascalsInOnePascal, pascal.Kilopascals, KilopascalsTolerance); - AssertEx.EqualTolerance(KilopoundsForcePerSquareFootInOnePascal, pascal.KilopoundsForcePerSquareFoot, KilopoundsForcePerSquareFootTolerance); - AssertEx.EqualTolerance(KilopoundsForcePerSquareInchInOnePascal, pascal.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - AssertEx.EqualTolerance(MegabarsInOnePascal, pascal.Megabars, MegabarsTolerance); - AssertEx.EqualTolerance(MeganewtonsPerSquareMeterInOnePascal, pascal.MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(MegapascalsInOnePascal, pascal.Megapascals, MegapascalsTolerance); - AssertEx.EqualTolerance(MetersOfHeadInOnePascal, pascal.MetersOfHead, MetersOfHeadTolerance); - AssertEx.EqualTolerance(MicropascalsInOnePascal, pascal.Micropascals, MicropascalsTolerance); - AssertEx.EqualTolerance(MillibarsInOnePascal, pascal.Millibars, MillibarsTolerance); - AssertEx.EqualTolerance(MillimetersOfMercuryInOnePascal, pascal.MillimetersOfMercury, MillimetersOfMercuryTolerance); - AssertEx.EqualTolerance(NewtonsPerSquareCentimeterInOnePascal, pascal.NewtonsPerSquareCentimeter, NewtonsPerSquareCentimeterTolerance); - AssertEx.EqualTolerance(NewtonsPerSquareMeterInOnePascal, pascal.NewtonsPerSquareMeter, NewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(NewtonsPerSquareMillimeterInOnePascal, pascal.NewtonsPerSquareMillimeter, NewtonsPerSquareMillimeterTolerance); - AssertEx.EqualTolerance(PascalsInOnePascal, pascal.Pascals, PascalsTolerance); - AssertEx.EqualTolerance(PoundsForcePerSquareFootInOnePascal, pascal.PoundsForcePerSquareFoot, PoundsForcePerSquareFootTolerance); - AssertEx.EqualTolerance(PoundsForcePerSquareInchInOnePascal, pascal.PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - AssertEx.EqualTolerance(TechnicalAtmospheresInOnePascal, pascal.TechnicalAtmospheres, TechnicalAtmospheresTolerance); - AssertEx.EqualTolerance(TonnesForcePerSquareCentimeterInOnePascal, pascal.TonnesForcePerSquareCentimeter, TonnesForcePerSquareCentimeterTolerance); - AssertEx.EqualTolerance(TonnesForcePerSquareMeterInOnePascal, pascal.TonnesForcePerSquareMeter, TonnesForcePerSquareMeterTolerance); - AssertEx.EqualTolerance(TonnesForcePerSquareMillimeterInOnePascal, pascal.TonnesForcePerSquareMillimeter, TonnesForcePerSquareMillimeterTolerance); - AssertEx.EqualTolerance(TorrsInOnePascal, pascal.Torrs, TorrsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Atmosphere).Atmospheres, AtmospheresTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Bar).Bars, BarsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Centibar).Centibars, CentibarsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Decapascal).Decapascals, DecapascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Decibar).Decibars, DecibarsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.FootOfHead).FeetOfHead, FeetOfHeadTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Gigapascal).Gigapascals, GigapascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Hectopascal).Hectopascals, HectopascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.InchOfMercury).InchesOfMercury, InchesOfMercuryTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Kilobar).Kilobars, KilobarsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilogramForcePerSquareCentimeter).KilogramsForcePerSquareCentimeter, KilogramsForcePerSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilogramForcePerSquareMeter).KilogramsForcePerSquareMeter, KilogramsForcePerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilogramForcePerSquareMillimeter).KilogramsForcePerSquareMillimeter, KilogramsForcePerSquareMillimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilonewtonPerSquareCentimeter).KilonewtonsPerSquareCentimeter, KilonewtonsPerSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilonewtonPerSquareMeter).KilonewtonsPerSquareMeter, KilonewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilonewtonPerSquareMillimeter).KilonewtonsPerSquareMillimeter, KilonewtonsPerSquareMillimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Kilopascal).Kilopascals, KilopascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilopoundForcePerSquareFoot).KilopoundsForcePerSquareFoot, KilopoundsForcePerSquareFootTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilopoundForcePerSquareInch).KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Megabar).Megabars, MegabarsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.MeganewtonPerSquareMeter).MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Megapascal).Megapascals, MegapascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.MeterOfHead).MetersOfHead, MetersOfHeadTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Micropascal).Micropascals, MicropascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Millibar).Millibars, MillibarsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.MillimeterOfMercury).MillimetersOfMercury, MillimetersOfMercuryTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.NewtonPerSquareCentimeter).NewtonsPerSquareCentimeter, NewtonsPerSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.NewtonPerSquareMeter).NewtonsPerSquareMeter, NewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.NewtonPerSquareMillimeter).NewtonsPerSquareMillimeter, NewtonsPerSquareMillimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Pascal).Pascals, PascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.PoundForcePerSquareFoot).PoundsForcePerSquareFoot, PoundsForcePerSquareFootTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.PoundForcePerSquareInch).PoundsForcePerSquareInch, PoundsForcePerSquareInchTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.TechnicalAtmosphere).TechnicalAtmospheres, TechnicalAtmospheresTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.TonneForcePerSquareCentimeter).TonnesForcePerSquareCentimeter, TonnesForcePerSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.TonneForcePerSquareMeter).TonnesForcePerSquareMeter, TonnesForcePerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.TonneForcePerSquareMillimeter).TonnesForcePerSquareMillimeter, TonnesForcePerSquareMillimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Torr).Torrs, TorrsTolerance); - } - - [Fact] - public void FromPascals_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Pressure.FromPascals(double.PositiveInfinity)); - Assert.Throws(() => Pressure.FromPascals(double.NegativeInfinity)); - } - - [Fact] - public void FromPascals_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Pressure.FromPascals(double.NaN)); - } - - [Fact] - public void As() - { - var pascal = Pressure.FromPascals(1); - AssertEx.EqualTolerance(AtmospheresInOnePascal, pascal.As(PressureUnit.Atmosphere), AtmospheresTolerance); - AssertEx.EqualTolerance(BarsInOnePascal, pascal.As(PressureUnit.Bar), BarsTolerance); - AssertEx.EqualTolerance(CentibarsInOnePascal, pascal.As(PressureUnit.Centibar), CentibarsTolerance); - AssertEx.EqualTolerance(DecapascalsInOnePascal, pascal.As(PressureUnit.Decapascal), DecapascalsTolerance); - AssertEx.EqualTolerance(DecibarsInOnePascal, pascal.As(PressureUnit.Decibar), DecibarsTolerance); - AssertEx.EqualTolerance(FeetOfHeadInOnePascal, pascal.As(PressureUnit.FootOfHead), FeetOfHeadTolerance); - AssertEx.EqualTolerance(GigapascalsInOnePascal, pascal.As(PressureUnit.Gigapascal), GigapascalsTolerance); - AssertEx.EqualTolerance(HectopascalsInOnePascal, pascal.As(PressureUnit.Hectopascal), HectopascalsTolerance); - AssertEx.EqualTolerance(InchesOfMercuryInOnePascal, pascal.As(PressureUnit.InchOfMercury), InchesOfMercuryTolerance); - AssertEx.EqualTolerance(KilobarsInOnePascal, pascal.As(PressureUnit.Kilobar), KilobarsTolerance); - AssertEx.EqualTolerance(KilogramsForcePerSquareCentimeterInOnePascal, pascal.As(PressureUnit.KilogramForcePerSquareCentimeter), KilogramsForcePerSquareCentimeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerSquareMeterInOnePascal, pascal.As(PressureUnit.KilogramForcePerSquareMeter), KilogramsForcePerSquareMeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerSquareMillimeterInOnePascal, pascal.As(PressureUnit.KilogramForcePerSquareMillimeter), KilogramsForcePerSquareMillimeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerSquareCentimeterInOnePascal, pascal.As(PressureUnit.KilonewtonPerSquareCentimeter), KilonewtonsPerSquareCentimeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerSquareMeterInOnePascal, pascal.As(PressureUnit.KilonewtonPerSquareMeter), KilonewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerSquareMillimeterInOnePascal, pascal.As(PressureUnit.KilonewtonPerSquareMillimeter), KilonewtonsPerSquareMillimeterTolerance); - AssertEx.EqualTolerance(KilopascalsInOnePascal, pascal.As(PressureUnit.Kilopascal), KilopascalsTolerance); - AssertEx.EqualTolerance(KilopoundsForcePerSquareFootInOnePascal, pascal.As(PressureUnit.KilopoundForcePerSquareFoot), KilopoundsForcePerSquareFootTolerance); - AssertEx.EqualTolerance(KilopoundsForcePerSquareInchInOnePascal, pascal.As(PressureUnit.KilopoundForcePerSquareInch), KilopoundsForcePerSquareInchTolerance); - AssertEx.EqualTolerance(MegabarsInOnePascal, pascal.As(PressureUnit.Megabar), MegabarsTolerance); - AssertEx.EqualTolerance(MeganewtonsPerSquareMeterInOnePascal, pascal.As(PressureUnit.MeganewtonPerSquareMeter), MeganewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(MegapascalsInOnePascal, pascal.As(PressureUnit.Megapascal), MegapascalsTolerance); - AssertEx.EqualTolerance(MetersOfHeadInOnePascal, pascal.As(PressureUnit.MeterOfHead), MetersOfHeadTolerance); - AssertEx.EqualTolerance(MicropascalsInOnePascal, pascal.As(PressureUnit.Micropascal), MicropascalsTolerance); - AssertEx.EqualTolerance(MillibarsInOnePascal, pascal.As(PressureUnit.Millibar), MillibarsTolerance); - AssertEx.EqualTolerance(MillimetersOfMercuryInOnePascal, pascal.As(PressureUnit.MillimeterOfMercury), MillimetersOfMercuryTolerance); - AssertEx.EqualTolerance(NewtonsPerSquareCentimeterInOnePascal, pascal.As(PressureUnit.NewtonPerSquareCentimeter), NewtonsPerSquareCentimeterTolerance); - AssertEx.EqualTolerance(NewtonsPerSquareMeterInOnePascal, pascal.As(PressureUnit.NewtonPerSquareMeter), NewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(NewtonsPerSquareMillimeterInOnePascal, pascal.As(PressureUnit.NewtonPerSquareMillimeter), NewtonsPerSquareMillimeterTolerance); - AssertEx.EqualTolerance(PascalsInOnePascal, pascal.As(PressureUnit.Pascal), PascalsTolerance); - AssertEx.EqualTolerance(PoundsForcePerSquareFootInOnePascal, pascal.As(PressureUnit.PoundForcePerSquareFoot), PoundsForcePerSquareFootTolerance); - AssertEx.EqualTolerance(PoundsForcePerSquareInchInOnePascal, pascal.As(PressureUnit.PoundForcePerSquareInch), PoundsForcePerSquareInchTolerance); - AssertEx.EqualTolerance(TechnicalAtmospheresInOnePascal, pascal.As(PressureUnit.TechnicalAtmosphere), TechnicalAtmospheresTolerance); - AssertEx.EqualTolerance(TonnesForcePerSquareCentimeterInOnePascal, pascal.As(PressureUnit.TonneForcePerSquareCentimeter), TonnesForcePerSquareCentimeterTolerance); - AssertEx.EqualTolerance(TonnesForcePerSquareMeterInOnePascal, pascal.As(PressureUnit.TonneForcePerSquareMeter), TonnesForcePerSquareMeterTolerance); - AssertEx.EqualTolerance(TonnesForcePerSquareMillimeterInOnePascal, pascal.As(PressureUnit.TonneForcePerSquareMillimeter), TonnesForcePerSquareMillimeterTolerance); - AssertEx.EqualTolerance(TorrsInOnePascal, pascal.As(PressureUnit.Torr), TorrsTolerance); - } - - [Fact] - public void ToUnit() - { - var pascal = Pressure.FromPascals(1); - - var atmosphereQuantity = pascal.ToUnit(PressureUnit.Atmosphere); - AssertEx.EqualTolerance(AtmospheresInOnePascal, (double)atmosphereQuantity.Value, AtmospheresTolerance); - Assert.Equal(PressureUnit.Atmosphere, atmosphereQuantity.Unit); - - var barQuantity = pascal.ToUnit(PressureUnit.Bar); - AssertEx.EqualTolerance(BarsInOnePascal, (double)barQuantity.Value, BarsTolerance); - Assert.Equal(PressureUnit.Bar, barQuantity.Unit); - - var centibarQuantity = pascal.ToUnit(PressureUnit.Centibar); - AssertEx.EqualTolerance(CentibarsInOnePascal, (double)centibarQuantity.Value, CentibarsTolerance); - Assert.Equal(PressureUnit.Centibar, centibarQuantity.Unit); - - var decapascalQuantity = pascal.ToUnit(PressureUnit.Decapascal); - AssertEx.EqualTolerance(DecapascalsInOnePascal, (double)decapascalQuantity.Value, DecapascalsTolerance); - Assert.Equal(PressureUnit.Decapascal, decapascalQuantity.Unit); - - var decibarQuantity = pascal.ToUnit(PressureUnit.Decibar); - AssertEx.EqualTolerance(DecibarsInOnePascal, (double)decibarQuantity.Value, DecibarsTolerance); - Assert.Equal(PressureUnit.Decibar, decibarQuantity.Unit); - - var footofheadQuantity = pascal.ToUnit(PressureUnit.FootOfHead); - AssertEx.EqualTolerance(FeetOfHeadInOnePascal, (double)footofheadQuantity.Value, FeetOfHeadTolerance); - Assert.Equal(PressureUnit.FootOfHead, footofheadQuantity.Unit); - - var gigapascalQuantity = pascal.ToUnit(PressureUnit.Gigapascal); - AssertEx.EqualTolerance(GigapascalsInOnePascal, (double)gigapascalQuantity.Value, GigapascalsTolerance); - Assert.Equal(PressureUnit.Gigapascal, gigapascalQuantity.Unit); - - var hectopascalQuantity = pascal.ToUnit(PressureUnit.Hectopascal); - AssertEx.EqualTolerance(HectopascalsInOnePascal, (double)hectopascalQuantity.Value, HectopascalsTolerance); - Assert.Equal(PressureUnit.Hectopascal, hectopascalQuantity.Unit); - - var inchofmercuryQuantity = pascal.ToUnit(PressureUnit.InchOfMercury); - AssertEx.EqualTolerance(InchesOfMercuryInOnePascal, (double)inchofmercuryQuantity.Value, InchesOfMercuryTolerance); - Assert.Equal(PressureUnit.InchOfMercury, inchofmercuryQuantity.Unit); - - var kilobarQuantity = pascal.ToUnit(PressureUnit.Kilobar); - AssertEx.EqualTolerance(KilobarsInOnePascal, (double)kilobarQuantity.Value, KilobarsTolerance); - Assert.Equal(PressureUnit.Kilobar, kilobarQuantity.Unit); - - var kilogramforcepersquarecentimeterQuantity = pascal.ToUnit(PressureUnit.KilogramForcePerSquareCentimeter); - AssertEx.EqualTolerance(KilogramsForcePerSquareCentimeterInOnePascal, (double)kilogramforcepersquarecentimeterQuantity.Value, KilogramsForcePerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareCentimeter, kilogramforcepersquarecentimeterQuantity.Unit); - - var kilogramforcepersquaremeterQuantity = pascal.ToUnit(PressureUnit.KilogramForcePerSquareMeter); - AssertEx.EqualTolerance(KilogramsForcePerSquareMeterInOnePascal, (double)kilogramforcepersquaremeterQuantity.Value, KilogramsForcePerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMeter, kilogramforcepersquaremeterQuantity.Unit); - - var kilogramforcepersquaremillimeterQuantity = pascal.ToUnit(PressureUnit.KilogramForcePerSquareMillimeter); - AssertEx.EqualTolerance(KilogramsForcePerSquareMillimeterInOnePascal, (double)kilogramforcepersquaremillimeterQuantity.Value, KilogramsForcePerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilogramForcePerSquareMillimeter, kilogramforcepersquaremillimeterQuantity.Unit); - - var kilonewtonpersquarecentimeterQuantity = pascal.ToUnit(PressureUnit.KilonewtonPerSquareCentimeter); - AssertEx.EqualTolerance(KilonewtonsPerSquareCentimeterInOnePascal, (double)kilonewtonpersquarecentimeterQuantity.Value, KilonewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareCentimeter, kilonewtonpersquarecentimeterQuantity.Unit); - - var kilonewtonpersquaremeterQuantity = pascal.ToUnit(PressureUnit.KilonewtonPerSquareMeter); - AssertEx.EqualTolerance(KilonewtonsPerSquareMeterInOnePascal, (double)kilonewtonpersquaremeterQuantity.Value, KilonewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMeter, kilonewtonpersquaremeterQuantity.Unit); - - var kilonewtonpersquaremillimeterQuantity = pascal.ToUnit(PressureUnit.KilonewtonPerSquareMillimeter); - AssertEx.EqualTolerance(KilonewtonsPerSquareMillimeterInOnePascal, (double)kilonewtonpersquaremillimeterQuantity.Value, KilonewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.KilonewtonPerSquareMillimeter, kilonewtonpersquaremillimeterQuantity.Unit); - - var kilopascalQuantity = pascal.ToUnit(PressureUnit.Kilopascal); - AssertEx.EqualTolerance(KilopascalsInOnePascal, (double)kilopascalQuantity.Value, KilopascalsTolerance); - Assert.Equal(PressureUnit.Kilopascal, kilopascalQuantity.Unit); - - var kilopoundforcepersquarefootQuantity = pascal.ToUnit(PressureUnit.KilopoundForcePerSquareFoot); - AssertEx.EqualTolerance(KilopoundsForcePerSquareFootInOnePascal, (double)kilopoundforcepersquarefootQuantity.Value, KilopoundsForcePerSquareFootTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareFoot, kilopoundforcepersquarefootQuantity.Unit); - - var kilopoundforcepersquareinchQuantity = pascal.ToUnit(PressureUnit.KilopoundForcePerSquareInch); - AssertEx.EqualTolerance(KilopoundsForcePerSquareInchInOnePascal, (double)kilopoundforcepersquareinchQuantity.Value, KilopoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, kilopoundforcepersquareinchQuantity.Unit); - - var megabarQuantity = pascal.ToUnit(PressureUnit.Megabar); - AssertEx.EqualTolerance(MegabarsInOnePascal, (double)megabarQuantity.Value, MegabarsTolerance); - Assert.Equal(PressureUnit.Megabar, megabarQuantity.Unit); - - var meganewtonpersquaremeterQuantity = pascal.ToUnit(PressureUnit.MeganewtonPerSquareMeter); - AssertEx.EqualTolerance(MeganewtonsPerSquareMeterInOnePascal, (double)meganewtonpersquaremeterQuantity.Value, MeganewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.MeganewtonPerSquareMeter, meganewtonpersquaremeterQuantity.Unit); - - var megapascalQuantity = pascal.ToUnit(PressureUnit.Megapascal); - AssertEx.EqualTolerance(MegapascalsInOnePascal, (double)megapascalQuantity.Value, MegapascalsTolerance); - Assert.Equal(PressureUnit.Megapascal, megapascalQuantity.Unit); - - var meterofheadQuantity = pascal.ToUnit(PressureUnit.MeterOfHead); - AssertEx.EqualTolerance(MetersOfHeadInOnePascal, (double)meterofheadQuantity.Value, MetersOfHeadTolerance); - Assert.Equal(PressureUnit.MeterOfHead, meterofheadQuantity.Unit); - - var micropascalQuantity = pascal.ToUnit(PressureUnit.Micropascal); - AssertEx.EqualTolerance(MicropascalsInOnePascal, (double)micropascalQuantity.Value, MicropascalsTolerance); - Assert.Equal(PressureUnit.Micropascal, micropascalQuantity.Unit); - - var millibarQuantity = pascal.ToUnit(PressureUnit.Millibar); - AssertEx.EqualTolerance(MillibarsInOnePascal, (double)millibarQuantity.Value, MillibarsTolerance); - Assert.Equal(PressureUnit.Millibar, millibarQuantity.Unit); - - var millimeterofmercuryQuantity = pascal.ToUnit(PressureUnit.MillimeterOfMercury); - AssertEx.EqualTolerance(MillimetersOfMercuryInOnePascal, (double)millimeterofmercuryQuantity.Value, MillimetersOfMercuryTolerance); - Assert.Equal(PressureUnit.MillimeterOfMercury, millimeterofmercuryQuantity.Unit); - - var newtonpersquarecentimeterQuantity = pascal.ToUnit(PressureUnit.NewtonPerSquareCentimeter); - AssertEx.EqualTolerance(NewtonsPerSquareCentimeterInOnePascal, (double)newtonpersquarecentimeterQuantity.Value, NewtonsPerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareCentimeter, newtonpersquarecentimeterQuantity.Unit); - - var newtonpersquaremeterQuantity = pascal.ToUnit(PressureUnit.NewtonPerSquareMeter); - AssertEx.EqualTolerance(NewtonsPerSquareMeterInOnePascal, (double)newtonpersquaremeterQuantity.Value, NewtonsPerSquareMeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMeter, newtonpersquaremeterQuantity.Unit); - - var newtonpersquaremillimeterQuantity = pascal.ToUnit(PressureUnit.NewtonPerSquareMillimeter); - AssertEx.EqualTolerance(NewtonsPerSquareMillimeterInOnePascal, (double)newtonpersquaremillimeterQuantity.Value, NewtonsPerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.NewtonPerSquareMillimeter, newtonpersquaremillimeterQuantity.Unit); - - var pascalQuantity = pascal.ToUnit(PressureUnit.Pascal); - AssertEx.EqualTolerance(PascalsInOnePascal, (double)pascalQuantity.Value, PascalsTolerance); - Assert.Equal(PressureUnit.Pascal, pascalQuantity.Unit); - - var poundforcepersquarefootQuantity = pascal.ToUnit(PressureUnit.PoundForcePerSquareFoot); - AssertEx.EqualTolerance(PoundsForcePerSquareFootInOnePascal, (double)poundforcepersquarefootQuantity.Value, PoundsForcePerSquareFootTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareFoot, poundforcepersquarefootQuantity.Unit); - - var poundforcepersquareinchQuantity = pascal.ToUnit(PressureUnit.PoundForcePerSquareInch); - AssertEx.EqualTolerance(PoundsForcePerSquareInchInOnePascal, (double)poundforcepersquareinchQuantity.Value, PoundsForcePerSquareInchTolerance); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, poundforcepersquareinchQuantity.Unit); - - var technicalatmosphereQuantity = pascal.ToUnit(PressureUnit.TechnicalAtmosphere); - AssertEx.EqualTolerance(TechnicalAtmospheresInOnePascal, (double)technicalatmosphereQuantity.Value, TechnicalAtmospheresTolerance); - Assert.Equal(PressureUnit.TechnicalAtmosphere, technicalatmosphereQuantity.Unit); - - var tonneforcepersquarecentimeterQuantity = pascal.ToUnit(PressureUnit.TonneForcePerSquareCentimeter); - AssertEx.EqualTolerance(TonnesForcePerSquareCentimeterInOnePascal, (double)tonneforcepersquarecentimeterQuantity.Value, TonnesForcePerSquareCentimeterTolerance); - Assert.Equal(PressureUnit.TonneForcePerSquareCentimeter, tonneforcepersquarecentimeterQuantity.Unit); - - var tonneforcepersquaremeterQuantity = pascal.ToUnit(PressureUnit.TonneForcePerSquareMeter); - AssertEx.EqualTolerance(TonnesForcePerSquareMeterInOnePascal, (double)tonneforcepersquaremeterQuantity.Value, TonnesForcePerSquareMeterTolerance); - Assert.Equal(PressureUnit.TonneForcePerSquareMeter, tonneforcepersquaremeterQuantity.Unit); - - var tonneforcepersquaremillimeterQuantity = pascal.ToUnit(PressureUnit.TonneForcePerSquareMillimeter); - AssertEx.EqualTolerance(TonnesForcePerSquareMillimeterInOnePascal, (double)tonneforcepersquaremillimeterQuantity.Value, TonnesForcePerSquareMillimeterTolerance); - Assert.Equal(PressureUnit.TonneForcePerSquareMillimeter, tonneforcepersquaremillimeterQuantity.Unit); - - var torrQuantity = pascal.ToUnit(PressureUnit.Torr); - AssertEx.EqualTolerance(TorrsInOnePascal, (double)torrQuantity.Value, TorrsTolerance); - Assert.Equal(PressureUnit.Torr, torrQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Pressure pascal = Pressure.FromPascals(1); - AssertEx.EqualTolerance(1, Pressure.FromAtmospheres(pascal.Atmospheres).Pascals, AtmospheresTolerance); - AssertEx.EqualTolerance(1, Pressure.FromBars(pascal.Bars).Pascals, BarsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromCentibars(pascal.Centibars).Pascals, CentibarsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromDecapascals(pascal.Decapascals).Pascals, DecapascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromDecibars(pascal.Decibars).Pascals, DecibarsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromFeetOfHead(pascal.FeetOfHead).Pascals, FeetOfHeadTolerance); - AssertEx.EqualTolerance(1, Pressure.FromGigapascals(pascal.Gigapascals).Pascals, GigapascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromHectopascals(pascal.Hectopascals).Pascals, HectopascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromInchesOfMercury(pascal.InchesOfMercury).Pascals, InchesOfMercuryTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilobars(pascal.Kilobars).Pascals, KilobarsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilogramsForcePerSquareCentimeter(pascal.KilogramsForcePerSquareCentimeter).Pascals, KilogramsForcePerSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilogramsForcePerSquareMeter(pascal.KilogramsForcePerSquareMeter).Pascals, KilogramsForcePerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilogramsForcePerSquareMillimeter(pascal.KilogramsForcePerSquareMillimeter).Pascals, KilogramsForcePerSquareMillimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilonewtonsPerSquareCentimeter(pascal.KilonewtonsPerSquareCentimeter).Pascals, KilonewtonsPerSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilonewtonsPerSquareMeter(pascal.KilonewtonsPerSquareMeter).Pascals, KilonewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilonewtonsPerSquareMillimeter(pascal.KilonewtonsPerSquareMillimeter).Pascals, KilonewtonsPerSquareMillimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilopascals(pascal.Kilopascals).Pascals, KilopascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilopoundsForcePerSquareFoot(pascal.KilopoundsForcePerSquareFoot).Pascals, KilopoundsForcePerSquareFootTolerance); - AssertEx.EqualTolerance(1, Pressure.FromKilopoundsForcePerSquareInch(pascal.KilopoundsForcePerSquareInch).Pascals, KilopoundsForcePerSquareInchTolerance); - AssertEx.EqualTolerance(1, Pressure.FromMegabars(pascal.Megabars).Pascals, MegabarsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromMeganewtonsPerSquareMeter(pascal.MeganewtonsPerSquareMeter).Pascals, MeganewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromMegapascals(pascal.Megapascals).Pascals, MegapascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromMetersOfHead(pascal.MetersOfHead).Pascals, MetersOfHeadTolerance); - AssertEx.EqualTolerance(1, Pressure.FromMicropascals(pascal.Micropascals).Pascals, MicropascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromMillibars(pascal.Millibars).Pascals, MillibarsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromMillimetersOfMercury(pascal.MillimetersOfMercury).Pascals, MillimetersOfMercuryTolerance); - AssertEx.EqualTolerance(1, Pressure.FromNewtonsPerSquareCentimeter(pascal.NewtonsPerSquareCentimeter).Pascals, NewtonsPerSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromNewtonsPerSquareMeter(pascal.NewtonsPerSquareMeter).Pascals, NewtonsPerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromNewtonsPerSquareMillimeter(pascal.NewtonsPerSquareMillimeter).Pascals, NewtonsPerSquareMillimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromPascals(pascal.Pascals).Pascals, PascalsTolerance); - AssertEx.EqualTolerance(1, Pressure.FromPoundsForcePerSquareFoot(pascal.PoundsForcePerSquareFoot).Pascals, PoundsForcePerSquareFootTolerance); - AssertEx.EqualTolerance(1, Pressure.FromPoundsForcePerSquareInch(pascal.PoundsForcePerSquareInch).Pascals, PoundsForcePerSquareInchTolerance); - AssertEx.EqualTolerance(1, Pressure.FromTechnicalAtmospheres(pascal.TechnicalAtmospheres).Pascals, TechnicalAtmospheresTolerance); - AssertEx.EqualTolerance(1, Pressure.FromTonnesForcePerSquareCentimeter(pascal.TonnesForcePerSquareCentimeter).Pascals, TonnesForcePerSquareCentimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromTonnesForcePerSquareMeter(pascal.TonnesForcePerSquareMeter).Pascals, TonnesForcePerSquareMeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromTonnesForcePerSquareMillimeter(pascal.TonnesForcePerSquareMillimeter).Pascals, TonnesForcePerSquareMillimeterTolerance); - AssertEx.EqualTolerance(1, Pressure.FromTorrs(pascal.Torrs).Pascals, TorrsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Pressure v = Pressure.FromPascals(1); - AssertEx.EqualTolerance(-1, -v.Pascals, PascalsTolerance); - AssertEx.EqualTolerance(2, (Pressure.FromPascals(3)-v).Pascals, PascalsTolerance); - AssertEx.EqualTolerance(2, (v + v).Pascals, PascalsTolerance); - AssertEx.EqualTolerance(10, (v*10).Pascals, PascalsTolerance); - AssertEx.EqualTolerance(10, (10*v).Pascals, PascalsTolerance); - AssertEx.EqualTolerance(2, (Pressure.FromPascals(10)/5).Pascals, PascalsTolerance); - AssertEx.EqualTolerance(2, Pressure.FromPascals(10)/Pressure.FromPascals(5), PascalsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Pressure onePascal = Pressure.FromPascals(1); - Pressure twoPascals = Pressure.FromPascals(2); - - Assert.True(onePascal < twoPascals); - Assert.True(onePascal <= twoPascals); - Assert.True(twoPascals > onePascal); - Assert.True(twoPascals >= onePascal); - - Assert.False(onePascal > twoPascals); - Assert.False(onePascal >= twoPascals); - Assert.False(twoPascals < onePascal); - Assert.False(twoPascals <= onePascal); - } - - [Fact] - public void CompareToIsImplemented() - { - Pressure pascal = Pressure.FromPascals(1); - Assert.Equal(0, pascal.CompareTo(pascal)); - Assert.True(pascal.CompareTo(Pressure.Zero) > 0); - Assert.True(Pressure.Zero.CompareTo(pascal) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Pressure pascal = Pressure.FromPascals(1); - Assert.Throws(() => pascal.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Pressure pascal = Pressure.FromPascals(1); - Assert.Throws(() => pascal.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Pressure v = Pressure.FromPascals(1); - Assert.True(v.Equals(Pressure.FromPascals(1), PascalsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Pressure.Zero, PascalsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Pressure pascal = Pressure.FromPascals(1); - Assert.False(pascal.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Pressure pascal = Pressure.FromPascals(1); - Assert.False(pascal.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(PressureUnit.Undefined, Pressure.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(PressureUnit)).Cast(); - foreach(var unit in units) - { - if(unit == PressureUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/RatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/RatioTestsBase.g.cs deleted file mode 100644 index d3829553fb..0000000000 --- a/UnitsNet.Tests/GeneratedCode/RatioTestsBase.g.cs +++ /dev/null @@ -1,274 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Ratio. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RatioTestsBase - { - protected abstract double DecimalFractionsInOneDecimalFraction { get; } - protected abstract double PartsPerBillionInOneDecimalFraction { get; } - protected abstract double PartsPerMillionInOneDecimalFraction { get; } - protected abstract double PartsPerThousandInOneDecimalFraction { get; } - protected abstract double PartsPerTrillionInOneDecimalFraction { get; } - protected abstract double PercentInOneDecimalFraction { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DecimalFractionsTolerance { get { return 1e-5; } } - protected virtual double PartsPerBillionTolerance { get { return 1e-5; } } - protected virtual double PartsPerMillionTolerance { get { return 1e-5; } } - protected virtual double PartsPerThousandTolerance { get { return 1e-5; } } - protected virtual double PartsPerTrillionTolerance { get { return 1e-5; } } - protected virtual double PercentTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Ratio((double)0.0, RatioUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Ratio(double.PositiveInfinity, RatioUnit.DecimalFraction)); - Assert.Throws(() => new Ratio(double.NegativeInfinity, RatioUnit.DecimalFraction)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Ratio(double.NaN, RatioUnit.DecimalFraction)); - } - - [Fact] - public void DecimalFractionToRatioUnits() - { - Ratio decimalfraction = Ratio.FromDecimalFractions(1); - AssertEx.EqualTolerance(DecimalFractionsInOneDecimalFraction, decimalfraction.DecimalFractions, DecimalFractionsTolerance); - AssertEx.EqualTolerance(PartsPerBillionInOneDecimalFraction, decimalfraction.PartsPerBillion, PartsPerBillionTolerance); - AssertEx.EqualTolerance(PartsPerMillionInOneDecimalFraction, decimalfraction.PartsPerMillion, PartsPerMillionTolerance); - AssertEx.EqualTolerance(PartsPerThousandInOneDecimalFraction, decimalfraction.PartsPerThousand, PartsPerThousandTolerance); - AssertEx.EqualTolerance(PartsPerTrillionInOneDecimalFraction, decimalfraction.PartsPerTrillion, PartsPerTrillionTolerance); - AssertEx.EqualTolerance(PercentInOneDecimalFraction, decimalfraction.Percent, PercentTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Ratio.From(1, RatioUnit.DecimalFraction).DecimalFractions, DecimalFractionsTolerance); - AssertEx.EqualTolerance(1, Ratio.From(1, RatioUnit.PartPerBillion).PartsPerBillion, PartsPerBillionTolerance); - AssertEx.EqualTolerance(1, Ratio.From(1, RatioUnit.PartPerMillion).PartsPerMillion, PartsPerMillionTolerance); - AssertEx.EqualTolerance(1, Ratio.From(1, RatioUnit.PartPerThousand).PartsPerThousand, PartsPerThousandTolerance); - AssertEx.EqualTolerance(1, Ratio.From(1, RatioUnit.PartPerTrillion).PartsPerTrillion, PartsPerTrillionTolerance); - AssertEx.EqualTolerance(1, Ratio.From(1, RatioUnit.Percent).Percent, PercentTolerance); - } - - [Fact] - public void FromDecimalFractions_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Ratio.FromDecimalFractions(double.PositiveInfinity)); - Assert.Throws(() => Ratio.FromDecimalFractions(double.NegativeInfinity)); - } - - [Fact] - public void FromDecimalFractions_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Ratio.FromDecimalFractions(double.NaN)); - } - - [Fact] - public void As() - { - var decimalfraction = Ratio.FromDecimalFractions(1); - AssertEx.EqualTolerance(DecimalFractionsInOneDecimalFraction, decimalfraction.As(RatioUnit.DecimalFraction), DecimalFractionsTolerance); - AssertEx.EqualTolerance(PartsPerBillionInOneDecimalFraction, decimalfraction.As(RatioUnit.PartPerBillion), PartsPerBillionTolerance); - AssertEx.EqualTolerance(PartsPerMillionInOneDecimalFraction, decimalfraction.As(RatioUnit.PartPerMillion), PartsPerMillionTolerance); - AssertEx.EqualTolerance(PartsPerThousandInOneDecimalFraction, decimalfraction.As(RatioUnit.PartPerThousand), PartsPerThousandTolerance); - AssertEx.EqualTolerance(PartsPerTrillionInOneDecimalFraction, decimalfraction.As(RatioUnit.PartPerTrillion), PartsPerTrillionTolerance); - AssertEx.EqualTolerance(PercentInOneDecimalFraction, decimalfraction.As(RatioUnit.Percent), PercentTolerance); - } - - [Fact] - public void ToUnit() - { - var decimalfraction = Ratio.FromDecimalFractions(1); - - var decimalfractionQuantity = decimalfraction.ToUnit(RatioUnit.DecimalFraction); - AssertEx.EqualTolerance(DecimalFractionsInOneDecimalFraction, (double)decimalfractionQuantity.Value, DecimalFractionsTolerance); - Assert.Equal(RatioUnit.DecimalFraction, decimalfractionQuantity.Unit); - - var partperbillionQuantity = decimalfraction.ToUnit(RatioUnit.PartPerBillion); - AssertEx.EqualTolerance(PartsPerBillionInOneDecimalFraction, (double)partperbillionQuantity.Value, PartsPerBillionTolerance); - Assert.Equal(RatioUnit.PartPerBillion, partperbillionQuantity.Unit); - - var partpermillionQuantity = decimalfraction.ToUnit(RatioUnit.PartPerMillion); - AssertEx.EqualTolerance(PartsPerMillionInOneDecimalFraction, (double)partpermillionQuantity.Value, PartsPerMillionTolerance); - Assert.Equal(RatioUnit.PartPerMillion, partpermillionQuantity.Unit); - - var partperthousandQuantity = decimalfraction.ToUnit(RatioUnit.PartPerThousand); - AssertEx.EqualTolerance(PartsPerThousandInOneDecimalFraction, (double)partperthousandQuantity.Value, PartsPerThousandTolerance); - Assert.Equal(RatioUnit.PartPerThousand, partperthousandQuantity.Unit); - - var partpertrillionQuantity = decimalfraction.ToUnit(RatioUnit.PartPerTrillion); - AssertEx.EqualTolerance(PartsPerTrillionInOneDecimalFraction, (double)partpertrillionQuantity.Value, PartsPerTrillionTolerance); - Assert.Equal(RatioUnit.PartPerTrillion, partpertrillionQuantity.Unit); - - var percentQuantity = decimalfraction.ToUnit(RatioUnit.Percent); - AssertEx.EqualTolerance(PercentInOneDecimalFraction, (double)percentQuantity.Value, PercentTolerance); - Assert.Equal(RatioUnit.Percent, percentQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Ratio decimalfraction = Ratio.FromDecimalFractions(1); - AssertEx.EqualTolerance(1, Ratio.FromDecimalFractions(decimalfraction.DecimalFractions).DecimalFractions, DecimalFractionsTolerance); - AssertEx.EqualTolerance(1, Ratio.FromPartsPerBillion(decimalfraction.PartsPerBillion).DecimalFractions, PartsPerBillionTolerance); - AssertEx.EqualTolerance(1, Ratio.FromPartsPerMillion(decimalfraction.PartsPerMillion).DecimalFractions, PartsPerMillionTolerance); - AssertEx.EqualTolerance(1, Ratio.FromPartsPerThousand(decimalfraction.PartsPerThousand).DecimalFractions, PartsPerThousandTolerance); - AssertEx.EqualTolerance(1, Ratio.FromPartsPerTrillion(decimalfraction.PartsPerTrillion).DecimalFractions, PartsPerTrillionTolerance); - AssertEx.EqualTolerance(1, Ratio.FromPercent(decimalfraction.Percent).DecimalFractions, PercentTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Ratio v = Ratio.FromDecimalFractions(1); - AssertEx.EqualTolerance(-1, -v.DecimalFractions, DecimalFractionsTolerance); - AssertEx.EqualTolerance(2, (Ratio.FromDecimalFractions(3)-v).DecimalFractions, DecimalFractionsTolerance); - AssertEx.EqualTolerance(2, (v + v).DecimalFractions, DecimalFractionsTolerance); - AssertEx.EqualTolerance(10, (v*10).DecimalFractions, DecimalFractionsTolerance); - AssertEx.EqualTolerance(10, (10*v).DecimalFractions, DecimalFractionsTolerance); - AssertEx.EqualTolerance(2, (Ratio.FromDecimalFractions(10)/5).DecimalFractions, DecimalFractionsTolerance); - AssertEx.EqualTolerance(2, Ratio.FromDecimalFractions(10)/Ratio.FromDecimalFractions(5), DecimalFractionsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Ratio oneDecimalFraction = Ratio.FromDecimalFractions(1); - Ratio twoDecimalFractions = Ratio.FromDecimalFractions(2); - - Assert.True(oneDecimalFraction < twoDecimalFractions); - Assert.True(oneDecimalFraction <= twoDecimalFractions); - Assert.True(twoDecimalFractions > oneDecimalFraction); - Assert.True(twoDecimalFractions >= oneDecimalFraction); - - Assert.False(oneDecimalFraction > twoDecimalFractions); - Assert.False(oneDecimalFraction >= twoDecimalFractions); - Assert.False(twoDecimalFractions < oneDecimalFraction); - Assert.False(twoDecimalFractions <= oneDecimalFraction); - } - - [Fact] - public void CompareToIsImplemented() - { - Ratio decimalfraction = Ratio.FromDecimalFractions(1); - Assert.Equal(0, decimalfraction.CompareTo(decimalfraction)); - Assert.True(decimalfraction.CompareTo(Ratio.Zero) > 0); - Assert.True(Ratio.Zero.CompareTo(decimalfraction) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Ratio decimalfraction = Ratio.FromDecimalFractions(1); - Assert.Throws(() => decimalfraction.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Ratio decimalfraction = Ratio.FromDecimalFractions(1); - Assert.Throws(() => decimalfraction.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Ratio v = Ratio.FromDecimalFractions(1); - Assert.True(v.Equals(Ratio.FromDecimalFractions(1), DecimalFractionsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Ratio.Zero, DecimalFractionsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Ratio decimalfraction = Ratio.FromDecimalFractions(1); - Assert.False(decimalfraction.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Ratio decimalfraction = Ratio.FromDecimalFractions(1); - Assert.False(decimalfraction.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(RatioUnit.Undefined, Ratio.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(RatioUnit)).Cast(); - foreach(var unit in units) - { - if(unit == RatioUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ReactiveEnergyTestsBase.g.cs deleted file mode 100644 index 587e16695c..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ReactiveEnergyTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ReactiveEnergy. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ReactiveEnergyTestsBase - { - protected abstract double KilovoltampereReactiveHoursInOneVoltampereReactiveHour { get; } - protected abstract double MegavoltampereReactiveHoursInOneVoltampereReactiveHour { get; } - protected abstract double VoltampereReactiveHoursInOneVoltampereReactiveHour { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilovoltampereReactiveHoursTolerance { get { return 1e-5; } } - protected virtual double MegavoltampereReactiveHoursTolerance { get { return 1e-5; } } - protected virtual double VoltampereReactiveHoursTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ReactiveEnergy((double)0.0, ReactiveEnergyUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ReactiveEnergy(double.PositiveInfinity, ReactiveEnergyUnit.VoltampereReactiveHour)); - Assert.Throws(() => new ReactiveEnergy(double.NegativeInfinity, ReactiveEnergyUnit.VoltampereReactiveHour)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ReactiveEnergy(double.NaN, ReactiveEnergyUnit.VoltampereReactiveHour)); - } - - [Fact] - public void VoltampereReactiveHourToReactiveEnergyUnits() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - AssertEx.EqualTolerance(KilovoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(MegavoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(VoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ReactiveEnergy.From(1, ReactiveEnergyUnit.KilovoltampereReactiveHour).KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(1, ReactiveEnergy.From(1, ReactiveEnergyUnit.MegavoltampereReactiveHour).MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(1, ReactiveEnergy.From(1, ReactiveEnergyUnit.VoltampereReactiveHour).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - } - - [Fact] - public void FromVoltampereReactiveHours_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ReactiveEnergy.FromVoltampereReactiveHours(double.PositiveInfinity)); - Assert.Throws(() => ReactiveEnergy.FromVoltampereReactiveHours(double.NegativeInfinity)); - } - - [Fact] - public void FromVoltampereReactiveHours_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ReactiveEnergy.FromVoltampereReactiveHours(double.NaN)); - } - - [Fact] - public void As() - { - var voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - AssertEx.EqualTolerance(KilovoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ReactiveEnergyUnit.KilovoltampereReactiveHour), KilovoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(MegavoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ReactiveEnergyUnit.MegavoltampereReactiveHour), MegavoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(VoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ReactiveEnergyUnit.VoltampereReactiveHour), VoltampereReactiveHoursTolerance); - } - - [Fact] - public void ToUnit() - { - var voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - - var kilovoltamperereactivehourQuantity = voltamperereactivehour.ToUnit(ReactiveEnergyUnit.KilovoltampereReactiveHour); - AssertEx.EqualTolerance(KilovoltampereReactiveHoursInOneVoltampereReactiveHour, (double)kilovoltamperereactivehourQuantity.Value, KilovoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.KilovoltampereReactiveHour, kilovoltamperereactivehourQuantity.Unit); - - var megavoltamperereactivehourQuantity = voltamperereactivehour.ToUnit(ReactiveEnergyUnit.MegavoltampereReactiveHour); - AssertEx.EqualTolerance(MegavoltampereReactiveHoursInOneVoltampereReactiveHour, (double)megavoltamperereactivehourQuantity.Value, MegavoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.MegavoltampereReactiveHour, megavoltamperereactivehourQuantity.Unit); - - var voltamperereactivehourQuantity = voltamperereactivehour.ToUnit(ReactiveEnergyUnit.VoltampereReactiveHour); - AssertEx.EqualTolerance(VoltampereReactiveHoursInOneVoltampereReactiveHour, (double)voltamperereactivehourQuantity.Value, VoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.VoltampereReactiveHour, voltamperereactivehourQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - AssertEx.EqualTolerance(1, ReactiveEnergy.FromKilovoltampereReactiveHours(voltamperereactivehour.KilovoltampereReactiveHours).VoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(1, ReactiveEnergy.FromMegavoltampereReactiveHours(voltamperereactivehour.MegavoltampereReactiveHours).VoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(1, ReactiveEnergy.FromVoltampereReactiveHours(voltamperereactivehour.VoltampereReactiveHours).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ReactiveEnergy v = ReactiveEnergy.FromVoltampereReactiveHours(1); - AssertEx.EqualTolerance(-1, -v.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(2, (ReactiveEnergy.FromVoltampereReactiveHours(3)-v).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(2, (ReactiveEnergy.FromVoltampereReactiveHours(10)/5).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(2, ReactiveEnergy.FromVoltampereReactiveHours(10)/ReactiveEnergy.FromVoltampereReactiveHours(5), VoltampereReactiveHoursTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ReactiveEnergy oneVoltampereReactiveHour = ReactiveEnergy.FromVoltampereReactiveHours(1); - ReactiveEnergy twoVoltampereReactiveHours = ReactiveEnergy.FromVoltampereReactiveHours(2); - - Assert.True(oneVoltampereReactiveHour < twoVoltampereReactiveHours); - Assert.True(oneVoltampereReactiveHour <= twoVoltampereReactiveHours); - Assert.True(twoVoltampereReactiveHours > oneVoltampereReactiveHour); - Assert.True(twoVoltampereReactiveHours >= oneVoltampereReactiveHour); - - Assert.False(oneVoltampereReactiveHour > twoVoltampereReactiveHours); - Assert.False(oneVoltampereReactiveHour >= twoVoltampereReactiveHours); - Assert.False(twoVoltampereReactiveHours < oneVoltampereReactiveHour); - Assert.False(twoVoltampereReactiveHours <= oneVoltampereReactiveHour); - } - - [Fact] - public void CompareToIsImplemented() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.Equal(0, voltamperereactivehour.CompareTo(voltamperereactivehour)); - Assert.True(voltamperereactivehour.CompareTo(ReactiveEnergy.Zero) > 0); - Assert.True(ReactiveEnergy.Zero.CompareTo(voltamperereactivehour) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.Throws(() => voltamperereactivehour.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.Throws(() => voltamperereactivehour.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ReactiveEnergy v = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.True(v.Equals(ReactiveEnergy.FromVoltampereReactiveHours(1), VoltampereReactiveHoursTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ReactiveEnergy.Zero, VoltampereReactiveHoursTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.False(voltamperereactivehour.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.False(voltamperereactivehour.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ReactiveEnergyUnit.Undefined, ReactiveEnergy.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ReactiveEnergyUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ReactiveEnergyUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ReactivePowerTestsBase.g.cs deleted file mode 100644 index 4c99d361b4..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ReactivePowerTestsBase.g.cs +++ /dev/null @@ -1,254 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ReactivePower. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ReactivePowerTestsBase - { - protected abstract double GigavoltamperesReactiveInOneVoltampereReactive { get; } - protected abstract double KilovoltamperesReactiveInOneVoltampereReactive { get; } - protected abstract double MegavoltamperesReactiveInOneVoltampereReactive { get; } - protected abstract double VoltamperesReactiveInOneVoltampereReactive { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double GigavoltamperesReactiveTolerance { get { return 1e-5; } } - protected virtual double KilovoltamperesReactiveTolerance { get { return 1e-5; } } - protected virtual double MegavoltamperesReactiveTolerance { get { return 1e-5; } } - protected virtual double VoltamperesReactiveTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ReactivePower((double)0.0, ReactivePowerUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ReactivePower(double.PositiveInfinity, ReactivePowerUnit.VoltampereReactive)); - Assert.Throws(() => new ReactivePower(double.NegativeInfinity, ReactivePowerUnit.VoltampereReactive)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ReactivePower(double.NaN, ReactivePowerUnit.VoltampereReactive)); - } - - [Fact] - public void VoltampereReactiveToReactivePowerUnits() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - AssertEx.EqualTolerance(GigavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(KilovoltamperesReactiveInOneVoltampereReactive, voltamperereactive.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); - AssertEx.EqualTolerance(MegavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(VoltamperesReactiveInOneVoltampereReactive, voltamperereactive.VoltamperesReactive, VoltamperesReactiveTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ReactivePower.From(1, ReactivePowerUnit.GigavoltampereReactive).GigavoltamperesReactive, GigavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(1, ReactivePower.From(1, ReactivePowerUnit.KilovoltampereReactive).KilovoltamperesReactive, KilovoltamperesReactiveTolerance); - AssertEx.EqualTolerance(1, ReactivePower.From(1, ReactivePowerUnit.MegavoltampereReactive).MegavoltamperesReactive, MegavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(1, ReactivePower.From(1, ReactivePowerUnit.VoltampereReactive).VoltamperesReactive, VoltamperesReactiveTolerance); - } - - [Fact] - public void FromVoltamperesReactive_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ReactivePower.FromVoltamperesReactive(double.PositiveInfinity)); - Assert.Throws(() => ReactivePower.FromVoltamperesReactive(double.NegativeInfinity)); - } - - [Fact] - public void FromVoltamperesReactive_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ReactivePower.FromVoltamperesReactive(double.NaN)); - } - - [Fact] - public void As() - { - var voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - AssertEx.EqualTolerance(GigavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ReactivePowerUnit.GigavoltampereReactive), GigavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(KilovoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ReactivePowerUnit.KilovoltampereReactive), KilovoltamperesReactiveTolerance); - AssertEx.EqualTolerance(MegavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ReactivePowerUnit.MegavoltampereReactive), MegavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(VoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ReactivePowerUnit.VoltampereReactive), VoltamperesReactiveTolerance); - } - - [Fact] - public void ToUnit() - { - var voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - - var gigavoltamperereactiveQuantity = voltamperereactive.ToUnit(ReactivePowerUnit.GigavoltampereReactive); - AssertEx.EqualTolerance(GigavoltamperesReactiveInOneVoltampereReactive, (double)gigavoltamperereactiveQuantity.Value, GigavoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.GigavoltampereReactive, gigavoltamperereactiveQuantity.Unit); - - var kilovoltamperereactiveQuantity = voltamperereactive.ToUnit(ReactivePowerUnit.KilovoltampereReactive); - AssertEx.EqualTolerance(KilovoltamperesReactiveInOneVoltampereReactive, (double)kilovoltamperereactiveQuantity.Value, KilovoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.KilovoltampereReactive, kilovoltamperereactiveQuantity.Unit); - - var megavoltamperereactiveQuantity = voltamperereactive.ToUnit(ReactivePowerUnit.MegavoltampereReactive); - AssertEx.EqualTolerance(MegavoltamperesReactiveInOneVoltampereReactive, (double)megavoltamperereactiveQuantity.Value, MegavoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.MegavoltampereReactive, megavoltamperereactiveQuantity.Unit); - - var voltamperereactiveQuantity = voltamperereactive.ToUnit(ReactivePowerUnit.VoltampereReactive); - AssertEx.EqualTolerance(VoltamperesReactiveInOneVoltampereReactive, (double)voltamperereactiveQuantity.Value, VoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.VoltampereReactive, voltamperereactiveQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - AssertEx.EqualTolerance(1, ReactivePower.FromGigavoltamperesReactive(voltamperereactive.GigavoltamperesReactive).VoltamperesReactive, GigavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(1, ReactivePower.FromKilovoltamperesReactive(voltamperereactive.KilovoltamperesReactive).VoltamperesReactive, KilovoltamperesReactiveTolerance); - AssertEx.EqualTolerance(1, ReactivePower.FromMegavoltamperesReactive(voltamperereactive.MegavoltamperesReactive).VoltamperesReactive, MegavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(1, ReactivePower.FromVoltamperesReactive(voltamperereactive.VoltamperesReactive).VoltamperesReactive, VoltamperesReactiveTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ReactivePower v = ReactivePower.FromVoltamperesReactive(1); - AssertEx.EqualTolerance(-1, -v.VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(2, (ReactivePower.FromVoltamperesReactive(3)-v).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(2, (ReactivePower.FromVoltamperesReactive(10)/5).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(2, ReactivePower.FromVoltamperesReactive(10)/ReactivePower.FromVoltamperesReactive(5), VoltamperesReactiveTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ReactivePower oneVoltampereReactive = ReactivePower.FromVoltamperesReactive(1); - ReactivePower twoVoltamperesReactive = ReactivePower.FromVoltamperesReactive(2); - - Assert.True(oneVoltampereReactive < twoVoltamperesReactive); - Assert.True(oneVoltampereReactive <= twoVoltamperesReactive); - Assert.True(twoVoltamperesReactive > oneVoltampereReactive); - Assert.True(twoVoltamperesReactive >= oneVoltampereReactive); - - Assert.False(oneVoltampereReactive > twoVoltamperesReactive); - Assert.False(oneVoltampereReactive >= twoVoltamperesReactive); - Assert.False(twoVoltamperesReactive < oneVoltampereReactive); - Assert.False(twoVoltamperesReactive <= oneVoltampereReactive); - } - - [Fact] - public void CompareToIsImplemented() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.Equal(0, voltamperereactive.CompareTo(voltamperereactive)); - Assert.True(voltamperereactive.CompareTo(ReactivePower.Zero) > 0); - Assert.True(ReactivePower.Zero.CompareTo(voltamperereactive) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.Throws(() => voltamperereactive.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.Throws(() => voltamperereactive.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ReactivePower v = ReactivePower.FromVoltamperesReactive(1); - Assert.True(v.Equals(ReactivePower.FromVoltamperesReactive(1), VoltamperesReactiveTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ReactivePower.Zero, VoltamperesReactiveTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.False(voltamperereactive.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.False(voltamperereactive.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ReactivePowerUnit.Undefined, ReactivePower.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ReactivePowerUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ReactivePowerUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/RotationalAccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/RotationalAccelerationTestsBase.g.cs deleted file mode 100644 index 8312e239ce..0000000000 --- a/UnitsNet.Tests/GeneratedCode/RotationalAccelerationTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of RotationalAcceleration. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RotationalAccelerationTestsBase - { - protected abstract double DegreesPerSecondSquaredInOneRadianPerSecondSquared { get; } - protected abstract double RadiansPerSecondSquaredInOneRadianPerSecondSquared { get; } - protected abstract double RevolutionsPerMinutePerSecondInOneRadianPerSecondSquared { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DegreesPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double RadiansPerSecondSquaredTolerance { get { return 1e-5; } } - protected virtual double RevolutionsPerMinutePerSecondTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalAcceleration((double)0.0, RotationalAccelerationUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalAcceleration(double.PositiveInfinity, RotationalAccelerationUnit.RadianPerSecondSquared)); - Assert.Throws(() => new RotationalAcceleration(double.NegativeInfinity, RotationalAccelerationUnit.RadianPerSecondSquared)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalAcceleration(double.NaN, RotationalAccelerationUnit.RadianPerSecondSquared)); - } - - [Fact] - public void RadianPerSecondSquaredToRotationalAccelerationUnits() - { - RotationalAcceleration radianpersecondsquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - AssertEx.EqualTolerance(DegreesPerSecondSquaredInOneRadianPerSecondSquared, radianpersecondsquared.DegreesPerSecondSquared, DegreesPerSecondSquaredTolerance); - AssertEx.EqualTolerance(RadiansPerSecondSquaredInOneRadianPerSecondSquared, radianpersecondsquared.RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(RevolutionsPerMinutePerSecondInOneRadianPerSecondSquared, radianpersecondsquared.RevolutionsPerMinutePerSecond, RevolutionsPerMinutePerSecondTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, RotationalAcceleration.From(1, RotationalAccelerationUnit.DegreePerSecondSquared).DegreesPerSecondSquared, DegreesPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, RotationalAcceleration.From(1, RotationalAccelerationUnit.RadianPerSecondSquared).RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, RotationalAcceleration.From(1, RotationalAccelerationUnit.RevolutionPerMinutePerSecond).RevolutionsPerMinutePerSecond, RevolutionsPerMinutePerSecondTolerance); - } - - [Fact] - public void FromRadiansPerSecondSquared_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => RotationalAcceleration.FromRadiansPerSecondSquared(double.PositiveInfinity)); - Assert.Throws(() => RotationalAcceleration.FromRadiansPerSecondSquared(double.NegativeInfinity)); - } - - [Fact] - public void FromRadiansPerSecondSquared_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => RotationalAcceleration.FromRadiansPerSecondSquared(double.NaN)); - } - - [Fact] - public void As() - { - var radianpersecondsquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - AssertEx.EqualTolerance(DegreesPerSecondSquaredInOneRadianPerSecondSquared, radianpersecondsquared.As(RotationalAccelerationUnit.DegreePerSecondSquared), DegreesPerSecondSquaredTolerance); - AssertEx.EqualTolerance(RadiansPerSecondSquaredInOneRadianPerSecondSquared, radianpersecondsquared.As(RotationalAccelerationUnit.RadianPerSecondSquared), RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(RevolutionsPerMinutePerSecondInOneRadianPerSecondSquared, radianpersecondsquared.As(RotationalAccelerationUnit.RevolutionPerMinutePerSecond), RevolutionsPerMinutePerSecondTolerance); - } - - [Fact] - public void ToUnit() - { - var radianpersecondsquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - - var degreepersecondsquaredQuantity = radianpersecondsquared.ToUnit(RotationalAccelerationUnit.DegreePerSecondSquared); - AssertEx.EqualTolerance(DegreesPerSecondSquaredInOneRadianPerSecondSquared, (double)degreepersecondsquaredQuantity.Value, DegreesPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.DegreePerSecondSquared, degreepersecondsquaredQuantity.Unit); - - var radianpersecondsquaredQuantity = radianpersecondsquared.ToUnit(RotationalAccelerationUnit.RadianPerSecondSquared); - AssertEx.EqualTolerance(RadiansPerSecondSquaredInOneRadianPerSecondSquared, (double)radianpersecondsquaredQuantity.Value, RadiansPerSecondSquaredTolerance); - Assert.Equal(RotationalAccelerationUnit.RadianPerSecondSquared, radianpersecondsquaredQuantity.Unit); - - var revolutionperminutepersecondQuantity = radianpersecondsquared.ToUnit(RotationalAccelerationUnit.RevolutionPerMinutePerSecond); - AssertEx.EqualTolerance(RevolutionsPerMinutePerSecondInOneRadianPerSecondSquared, (double)revolutionperminutepersecondQuantity.Value, RevolutionsPerMinutePerSecondTolerance); - Assert.Equal(RotationalAccelerationUnit.RevolutionPerMinutePerSecond, revolutionperminutepersecondQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - RotationalAcceleration radianpersecondsquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - AssertEx.EqualTolerance(1, RotationalAcceleration.FromDegreesPerSecondSquared(radianpersecondsquared.DegreesPerSecondSquared).RadiansPerSecondSquared, DegreesPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, RotationalAcceleration.FromRadiansPerSecondSquared(radianpersecondsquared.RadiansPerSecondSquared).RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(1, RotationalAcceleration.FromRevolutionsPerMinutePerSecond(radianpersecondsquared.RevolutionsPerMinutePerSecond).RadiansPerSecondSquared, RevolutionsPerMinutePerSecondTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - RotationalAcceleration v = RotationalAcceleration.FromRadiansPerSecondSquared(1); - AssertEx.EqualTolerance(-1, -v.RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(2, (RotationalAcceleration.FromRadiansPerSecondSquared(3)-v).RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(2, (v + v).RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(10, (v*10).RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(10, (10*v).RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(2, (RotationalAcceleration.FromRadiansPerSecondSquared(10)/5).RadiansPerSecondSquared, RadiansPerSecondSquaredTolerance); - AssertEx.EqualTolerance(2, RotationalAcceleration.FromRadiansPerSecondSquared(10)/RotationalAcceleration.FromRadiansPerSecondSquared(5), RadiansPerSecondSquaredTolerance); - } - - [Fact] - public void ComparisonOperators() - { - RotationalAcceleration oneRadianPerSecondSquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - RotationalAcceleration twoRadiansPerSecondSquared = RotationalAcceleration.FromRadiansPerSecondSquared(2); - - Assert.True(oneRadianPerSecondSquared < twoRadiansPerSecondSquared); - Assert.True(oneRadianPerSecondSquared <= twoRadiansPerSecondSquared); - Assert.True(twoRadiansPerSecondSquared > oneRadianPerSecondSquared); - Assert.True(twoRadiansPerSecondSquared >= oneRadianPerSecondSquared); - - Assert.False(oneRadianPerSecondSquared > twoRadiansPerSecondSquared); - Assert.False(oneRadianPerSecondSquared >= twoRadiansPerSecondSquared); - Assert.False(twoRadiansPerSecondSquared < oneRadianPerSecondSquared); - Assert.False(twoRadiansPerSecondSquared <= oneRadianPerSecondSquared); - } - - [Fact] - public void CompareToIsImplemented() - { - RotationalAcceleration radianpersecondsquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - Assert.Equal(0, radianpersecondsquared.CompareTo(radianpersecondsquared)); - Assert.True(radianpersecondsquared.CompareTo(RotationalAcceleration.Zero) > 0); - Assert.True(RotationalAcceleration.Zero.CompareTo(radianpersecondsquared) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - RotationalAcceleration radianpersecondsquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - Assert.Throws(() => radianpersecondsquared.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - RotationalAcceleration radianpersecondsquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - Assert.Throws(() => radianpersecondsquared.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - RotationalAcceleration v = RotationalAcceleration.FromRadiansPerSecondSquared(1); - Assert.True(v.Equals(RotationalAcceleration.FromRadiansPerSecondSquared(1), RadiansPerSecondSquaredTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(RotationalAcceleration.Zero, RadiansPerSecondSquaredTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - RotationalAcceleration radianpersecondsquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - Assert.False(radianpersecondsquared.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - RotationalAcceleration radianpersecondsquared = RotationalAcceleration.FromRadiansPerSecondSquared(1); - Assert.False(radianpersecondsquared.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(RotationalAccelerationUnit.Undefined, RotationalAcceleration.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(RotationalAccelerationUnit)).Cast(); - foreach(var unit in units) - { - if(unit == RotationalAccelerationUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/RotationalSpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/RotationalSpeedTestsBase.g.cs deleted file mode 100644 index 8f109fd011..0000000000 --- a/UnitsNet.Tests/GeneratedCode/RotationalSpeedTestsBase.g.cs +++ /dev/null @@ -1,344 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of RotationalSpeed. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RotationalSpeedTestsBase - { - protected abstract double CentiradiansPerSecondInOneRadianPerSecond { get; } - protected abstract double DeciradiansPerSecondInOneRadianPerSecond { get; } - protected abstract double DegreesPerMinuteInOneRadianPerSecond { get; } - protected abstract double DegreesPerSecondInOneRadianPerSecond { get; } - protected abstract double MicrodegreesPerSecondInOneRadianPerSecond { get; } - protected abstract double MicroradiansPerSecondInOneRadianPerSecond { get; } - protected abstract double MillidegreesPerSecondInOneRadianPerSecond { get; } - protected abstract double MilliradiansPerSecondInOneRadianPerSecond { get; } - protected abstract double NanodegreesPerSecondInOneRadianPerSecond { get; } - protected abstract double NanoradiansPerSecondInOneRadianPerSecond { get; } - protected abstract double RadiansPerSecondInOneRadianPerSecond { get; } - protected abstract double RevolutionsPerMinuteInOneRadianPerSecond { get; } - protected abstract double RevolutionsPerSecondInOneRadianPerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentiradiansPerSecondTolerance { get { return 1e-5; } } - protected virtual double DeciradiansPerSecondTolerance { get { return 1e-5; } } - protected virtual double DegreesPerMinuteTolerance { get { return 1e-5; } } - protected virtual double DegreesPerSecondTolerance { get { return 1e-5; } } - protected virtual double MicrodegreesPerSecondTolerance { get { return 1e-5; } } - protected virtual double MicroradiansPerSecondTolerance { get { return 1e-5; } } - protected virtual double MillidegreesPerSecondTolerance { get { return 1e-5; } } - protected virtual double MilliradiansPerSecondTolerance { get { return 1e-5; } } - protected virtual double NanodegreesPerSecondTolerance { get { return 1e-5; } } - protected virtual double NanoradiansPerSecondTolerance { get { return 1e-5; } } - protected virtual double RadiansPerSecondTolerance { get { return 1e-5; } } - protected virtual double RevolutionsPerMinuteTolerance { get { return 1e-5; } } - protected virtual double RevolutionsPerSecondTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalSpeed((double)0.0, RotationalSpeedUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalSpeed(double.PositiveInfinity, RotationalSpeedUnit.RadianPerSecond)); - Assert.Throws(() => new RotationalSpeed(double.NegativeInfinity, RotationalSpeedUnit.RadianPerSecond)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalSpeed(double.NaN, RotationalSpeedUnit.RadianPerSecond)); - } - - [Fact] - public void RadianPerSecondToRotationalSpeedUnits() - { - RotationalSpeed radianpersecond = RotationalSpeed.FromRadiansPerSecond(1); - AssertEx.EqualTolerance(CentiradiansPerSecondInOneRadianPerSecond, radianpersecond.CentiradiansPerSecond, CentiradiansPerSecondTolerance); - AssertEx.EqualTolerance(DeciradiansPerSecondInOneRadianPerSecond, radianpersecond.DeciradiansPerSecond, DeciradiansPerSecondTolerance); - AssertEx.EqualTolerance(DegreesPerMinuteInOneRadianPerSecond, radianpersecond.DegreesPerMinute, DegreesPerMinuteTolerance); - AssertEx.EqualTolerance(DegreesPerSecondInOneRadianPerSecond, radianpersecond.DegreesPerSecond, DegreesPerSecondTolerance); - AssertEx.EqualTolerance(MicrodegreesPerSecondInOneRadianPerSecond, radianpersecond.MicrodegreesPerSecond, MicrodegreesPerSecondTolerance); - AssertEx.EqualTolerance(MicroradiansPerSecondInOneRadianPerSecond, radianpersecond.MicroradiansPerSecond, MicroradiansPerSecondTolerance); - AssertEx.EqualTolerance(MillidegreesPerSecondInOneRadianPerSecond, radianpersecond.MillidegreesPerSecond, MillidegreesPerSecondTolerance); - AssertEx.EqualTolerance(MilliradiansPerSecondInOneRadianPerSecond, radianpersecond.MilliradiansPerSecond, MilliradiansPerSecondTolerance); - AssertEx.EqualTolerance(NanodegreesPerSecondInOneRadianPerSecond, radianpersecond.NanodegreesPerSecond, NanodegreesPerSecondTolerance); - AssertEx.EqualTolerance(NanoradiansPerSecondInOneRadianPerSecond, radianpersecond.NanoradiansPerSecond, NanoradiansPerSecondTolerance); - AssertEx.EqualTolerance(RadiansPerSecondInOneRadianPerSecond, radianpersecond.RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(RevolutionsPerMinuteInOneRadianPerSecond, radianpersecond.RevolutionsPerMinute, RevolutionsPerMinuteTolerance); - AssertEx.EqualTolerance(RevolutionsPerSecondInOneRadianPerSecond, radianpersecond.RevolutionsPerSecond, RevolutionsPerSecondTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.CentiradianPerSecond).CentiradiansPerSecond, CentiradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.DeciradianPerSecond).DeciradiansPerSecond, DeciradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.DegreePerMinute).DegreesPerMinute, DegreesPerMinuteTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.DegreePerSecond).DegreesPerSecond, DegreesPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.MicrodegreePerSecond).MicrodegreesPerSecond, MicrodegreesPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.MicroradianPerSecond).MicroradiansPerSecond, MicroradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.MillidegreePerSecond).MillidegreesPerSecond, MillidegreesPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.MilliradianPerSecond).MilliradiansPerSecond, MilliradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.NanodegreePerSecond).NanodegreesPerSecond, NanodegreesPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.NanoradianPerSecond).NanoradiansPerSecond, NanoradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.RadianPerSecond).RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.RevolutionPerMinute).RevolutionsPerMinute, RevolutionsPerMinuteTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.From(1, RotationalSpeedUnit.RevolutionPerSecond).RevolutionsPerSecond, RevolutionsPerSecondTolerance); - } - - [Fact] - public void FromRadiansPerSecond_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => RotationalSpeed.FromRadiansPerSecond(double.PositiveInfinity)); - Assert.Throws(() => RotationalSpeed.FromRadiansPerSecond(double.NegativeInfinity)); - } - - [Fact] - public void FromRadiansPerSecond_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => RotationalSpeed.FromRadiansPerSecond(double.NaN)); - } - - [Fact] - public void As() - { - var radianpersecond = RotationalSpeed.FromRadiansPerSecond(1); - AssertEx.EqualTolerance(CentiradiansPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.CentiradianPerSecond), CentiradiansPerSecondTolerance); - AssertEx.EqualTolerance(DeciradiansPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.DeciradianPerSecond), DeciradiansPerSecondTolerance); - AssertEx.EqualTolerance(DegreesPerMinuteInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.DegreePerMinute), DegreesPerMinuteTolerance); - AssertEx.EqualTolerance(DegreesPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.DegreePerSecond), DegreesPerSecondTolerance); - AssertEx.EqualTolerance(MicrodegreesPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.MicrodegreePerSecond), MicrodegreesPerSecondTolerance); - AssertEx.EqualTolerance(MicroradiansPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.MicroradianPerSecond), MicroradiansPerSecondTolerance); - AssertEx.EqualTolerance(MillidegreesPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.MillidegreePerSecond), MillidegreesPerSecondTolerance); - AssertEx.EqualTolerance(MilliradiansPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.MilliradianPerSecond), MilliradiansPerSecondTolerance); - AssertEx.EqualTolerance(NanodegreesPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.NanodegreePerSecond), NanodegreesPerSecondTolerance); - AssertEx.EqualTolerance(NanoradiansPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.NanoradianPerSecond), NanoradiansPerSecondTolerance); - AssertEx.EqualTolerance(RadiansPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.RadianPerSecond), RadiansPerSecondTolerance); - AssertEx.EqualTolerance(RevolutionsPerMinuteInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.RevolutionPerMinute), RevolutionsPerMinuteTolerance); - AssertEx.EqualTolerance(RevolutionsPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.RevolutionPerSecond), RevolutionsPerSecondTolerance); - } - - [Fact] - public void ToUnit() - { - var radianpersecond = RotationalSpeed.FromRadiansPerSecond(1); - - var centiradianpersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.CentiradianPerSecond); - AssertEx.EqualTolerance(CentiradiansPerSecondInOneRadianPerSecond, (double)centiradianpersecondQuantity.Value, CentiradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.CentiradianPerSecond, centiradianpersecondQuantity.Unit); - - var deciradianpersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.DeciradianPerSecond); - AssertEx.EqualTolerance(DeciradiansPerSecondInOneRadianPerSecond, (double)deciradianpersecondQuantity.Value, DeciradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DeciradianPerSecond, deciradianpersecondQuantity.Unit); - - var degreeperminuteQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.DegreePerMinute); - AssertEx.EqualTolerance(DegreesPerMinuteInOneRadianPerSecond, (double)degreeperminuteQuantity.Value, DegreesPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerMinute, degreeperminuteQuantity.Unit); - - var degreepersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.DegreePerSecond); - AssertEx.EqualTolerance(DegreesPerSecondInOneRadianPerSecond, (double)degreepersecondQuantity.Value, DegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, degreepersecondQuantity.Unit); - - var microdegreepersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.MicrodegreePerSecond); - AssertEx.EqualTolerance(MicrodegreesPerSecondInOneRadianPerSecond, (double)microdegreepersecondQuantity.Value, MicrodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, microdegreepersecondQuantity.Unit); - - var microradianpersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.MicroradianPerSecond); - AssertEx.EqualTolerance(MicroradiansPerSecondInOneRadianPerSecond, (double)microradianpersecondQuantity.Value, MicroradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MicroradianPerSecond, microradianpersecondQuantity.Unit); - - var millidegreepersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.MillidegreePerSecond); - AssertEx.EqualTolerance(MillidegreesPerSecondInOneRadianPerSecond, (double)millidegreepersecondQuantity.Value, MillidegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, millidegreepersecondQuantity.Unit); - - var milliradianpersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.MilliradianPerSecond); - AssertEx.EqualTolerance(MilliradiansPerSecondInOneRadianPerSecond, (double)milliradianpersecondQuantity.Value, MilliradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.MilliradianPerSecond, milliradianpersecondQuantity.Unit); - - var nanodegreepersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.NanodegreePerSecond); - AssertEx.EqualTolerance(NanodegreesPerSecondInOneRadianPerSecond, (double)nanodegreepersecondQuantity.Value, NanodegreesPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, nanodegreepersecondQuantity.Unit); - - var nanoradianpersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.NanoradianPerSecond); - AssertEx.EqualTolerance(NanoradiansPerSecondInOneRadianPerSecond, (double)nanoradianpersecondQuantity.Value, NanoradiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.NanoradianPerSecond, nanoradianpersecondQuantity.Unit); - - var radianpersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.RadianPerSecond); - AssertEx.EqualTolerance(RadiansPerSecondInOneRadianPerSecond, (double)radianpersecondQuantity.Value, RadiansPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RadianPerSecond, radianpersecondQuantity.Unit); - - var revolutionperminuteQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.RevolutionPerMinute); - AssertEx.EqualTolerance(RevolutionsPerMinuteInOneRadianPerSecond, (double)revolutionperminuteQuantity.Value, RevolutionsPerMinuteTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, revolutionperminuteQuantity.Unit); - - var revolutionpersecondQuantity = radianpersecond.ToUnit(RotationalSpeedUnit.RevolutionPerSecond); - AssertEx.EqualTolerance(RevolutionsPerSecondInOneRadianPerSecond, (double)revolutionpersecondQuantity.Value, RevolutionsPerSecondTolerance); - Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, revolutionpersecondQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - RotationalSpeed radianpersecond = RotationalSpeed.FromRadiansPerSecond(1); - AssertEx.EqualTolerance(1, RotationalSpeed.FromCentiradiansPerSecond(radianpersecond.CentiradiansPerSecond).RadiansPerSecond, CentiradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromDeciradiansPerSecond(radianpersecond.DeciradiansPerSecond).RadiansPerSecond, DeciradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromDegreesPerMinute(radianpersecond.DegreesPerMinute).RadiansPerSecond, DegreesPerMinuteTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromDegreesPerSecond(radianpersecond.DegreesPerSecond).RadiansPerSecond, DegreesPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromMicrodegreesPerSecond(radianpersecond.MicrodegreesPerSecond).RadiansPerSecond, MicrodegreesPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromMicroradiansPerSecond(radianpersecond.MicroradiansPerSecond).RadiansPerSecond, MicroradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromMillidegreesPerSecond(radianpersecond.MillidegreesPerSecond).RadiansPerSecond, MillidegreesPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromMilliradiansPerSecond(radianpersecond.MilliradiansPerSecond).RadiansPerSecond, MilliradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromNanodegreesPerSecond(radianpersecond.NanodegreesPerSecond).RadiansPerSecond, NanodegreesPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromNanoradiansPerSecond(radianpersecond.NanoradiansPerSecond).RadiansPerSecond, NanoradiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromRadiansPerSecond(radianpersecond.RadiansPerSecond).RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromRevolutionsPerMinute(radianpersecond.RevolutionsPerMinute).RadiansPerSecond, RevolutionsPerMinuteTolerance); - AssertEx.EqualTolerance(1, RotationalSpeed.FromRevolutionsPerSecond(radianpersecond.RevolutionsPerSecond).RadiansPerSecond, RevolutionsPerSecondTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - RotationalSpeed v = RotationalSpeed.FromRadiansPerSecond(1); - AssertEx.EqualTolerance(-1, -v.RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(2, (RotationalSpeed.FromRadiansPerSecond(3)-v).RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(2, (RotationalSpeed.FromRadiansPerSecond(10)/5).RadiansPerSecond, RadiansPerSecondTolerance); - AssertEx.EqualTolerance(2, RotationalSpeed.FromRadiansPerSecond(10)/RotationalSpeed.FromRadiansPerSecond(5), RadiansPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - RotationalSpeed oneRadianPerSecond = RotationalSpeed.FromRadiansPerSecond(1); - RotationalSpeed twoRadiansPerSecond = RotationalSpeed.FromRadiansPerSecond(2); - - Assert.True(oneRadianPerSecond < twoRadiansPerSecond); - Assert.True(oneRadianPerSecond <= twoRadiansPerSecond); - Assert.True(twoRadiansPerSecond > oneRadianPerSecond); - Assert.True(twoRadiansPerSecond >= oneRadianPerSecond); - - Assert.False(oneRadianPerSecond > twoRadiansPerSecond); - Assert.False(oneRadianPerSecond >= twoRadiansPerSecond); - Assert.False(twoRadiansPerSecond < oneRadianPerSecond); - Assert.False(twoRadiansPerSecond <= oneRadianPerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - RotationalSpeed radianpersecond = RotationalSpeed.FromRadiansPerSecond(1); - Assert.Equal(0, radianpersecond.CompareTo(radianpersecond)); - Assert.True(radianpersecond.CompareTo(RotationalSpeed.Zero) > 0); - Assert.True(RotationalSpeed.Zero.CompareTo(radianpersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - RotationalSpeed radianpersecond = RotationalSpeed.FromRadiansPerSecond(1); - Assert.Throws(() => radianpersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - RotationalSpeed radianpersecond = RotationalSpeed.FromRadiansPerSecond(1); - Assert.Throws(() => radianpersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - RotationalSpeed v = RotationalSpeed.FromRadiansPerSecond(1); - Assert.True(v.Equals(RotationalSpeed.FromRadiansPerSecond(1), RadiansPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(RotationalSpeed.Zero, RadiansPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - RotationalSpeed radianpersecond = RotationalSpeed.FromRadiansPerSecond(1); - Assert.False(radianpersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - RotationalSpeed radianpersecond = RotationalSpeed.FromRadiansPerSecond(1); - Assert.False(radianpersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(RotationalSpeedUnit.Undefined, RotationalSpeed.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(RotationalSpeedUnit)).Cast(); - foreach(var unit in units) - { - if(unit == RotationalSpeedUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/RotationalStiffnessPerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/RotationalStiffnessPerLengthTestsBase.g.cs deleted file mode 100644 index 9ab73ea579..0000000000 --- a/UnitsNet.Tests/GeneratedCode/RotationalStiffnessPerLengthTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of RotationalStiffnessPerLength. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RotationalStiffnessPerLengthTestsBase - { - protected abstract double KilonewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter { get; } - protected abstract double MeganewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter { get; } - protected abstract double NewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilonewtonMetersPerRadianPerMeterTolerance { get { return 1e-5; } } - protected virtual double MeganewtonMetersPerRadianPerMeterTolerance { get { return 1e-5; } } - protected virtual double NewtonMetersPerRadianPerMeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalStiffnessPerLength((double)0.0, RotationalStiffnessPerLengthUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalStiffnessPerLength(double.PositiveInfinity, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)); - Assert.Throws(() => new RotationalStiffnessPerLength(double.NegativeInfinity, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalStiffnessPerLength(double.NaN, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)); - } - - [Fact] - public void NewtonMeterPerRadianPerMeterToRotationalStiffnessPerLengthUnits() - { - RotationalStiffnessPerLength newtonmeterperradianpermeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - AssertEx.EqualTolerance(KilonewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, newtonmeterperradianpermeter.KilonewtonMetersPerRadianPerMeter, KilonewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(MeganewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, newtonmeterperradianpermeter.MeganewtonMetersPerRadianPerMeter, MeganewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(NewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, newtonmeterperradianpermeter.NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, RotationalStiffnessPerLength.From(1, RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter).KilonewtonMetersPerRadianPerMeter, KilonewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(1, RotationalStiffnessPerLength.From(1, RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter).MeganewtonMetersPerRadianPerMeter, MeganewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(1, RotationalStiffnessPerLength.From(1, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter).NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - } - - [Fact] - public void FromNewtonMetersPerRadianPerMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(double.PositiveInfinity)); - Assert.Throws(() => RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromNewtonMetersPerRadianPerMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(double.NaN)); - } - - [Fact] - public void As() - { - var newtonmeterperradianpermeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - AssertEx.EqualTolerance(KilonewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, newtonmeterperradianpermeter.As(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter), KilonewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(MeganewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, newtonmeterperradianpermeter.As(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter), MeganewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(NewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, newtonmeterperradianpermeter.As(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter), NewtonMetersPerRadianPerMeterTolerance); - } - - [Fact] - public void ToUnit() - { - var newtonmeterperradianpermeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - - var kilonewtonmeterperradianpermeterQuantity = newtonmeterperradianpermeter.ToUnit(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter); - AssertEx.EqualTolerance(KilonewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, (double)kilonewtonmeterperradianpermeterQuantity.Value, KilonewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, kilonewtonmeterperradianpermeterQuantity.Unit); - - var meganewtonmeterperradianpermeterQuantity = newtonmeterperradianpermeter.ToUnit(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter); - AssertEx.EqualTolerance(MeganewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, (double)meganewtonmeterperradianpermeterQuantity.Value, MeganewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, meganewtonmeterperradianpermeterQuantity.Unit); - - var newtonmeterperradianpermeterQuantity = newtonmeterperradianpermeter.ToUnit(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter); - AssertEx.EqualTolerance(NewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, (double)newtonmeterperradianpermeterQuantity.Value, NewtonMetersPerRadianPerMeterTolerance); - Assert.Equal(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, newtonmeterperradianpermeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - RotationalStiffnessPerLength newtonmeterperradianpermeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - AssertEx.EqualTolerance(1, RotationalStiffnessPerLength.FromKilonewtonMetersPerRadianPerMeter(newtonmeterperradianpermeter.KilonewtonMetersPerRadianPerMeter).NewtonMetersPerRadianPerMeter, KilonewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(1, RotationalStiffnessPerLength.FromMeganewtonMetersPerRadianPerMeter(newtonmeterperradianpermeter.MeganewtonMetersPerRadianPerMeter).NewtonMetersPerRadianPerMeter, MeganewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(1, RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(newtonmeterperradianpermeter.NewtonMetersPerRadianPerMeter).NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - RotationalStiffnessPerLength v = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - AssertEx.EqualTolerance(-1, -v.NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(2, (RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(3)-v).NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(2, (RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(10)/5).NewtonMetersPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance); - AssertEx.EqualTolerance(2, RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(10)/RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(5), NewtonMetersPerRadianPerMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - RotationalStiffnessPerLength oneNewtonMeterPerRadianPerMeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - RotationalStiffnessPerLength twoNewtonMetersPerRadianPerMeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(2); - - Assert.True(oneNewtonMeterPerRadianPerMeter < twoNewtonMetersPerRadianPerMeter); - Assert.True(oneNewtonMeterPerRadianPerMeter <= twoNewtonMetersPerRadianPerMeter); - Assert.True(twoNewtonMetersPerRadianPerMeter > oneNewtonMeterPerRadianPerMeter); - Assert.True(twoNewtonMetersPerRadianPerMeter >= oneNewtonMeterPerRadianPerMeter); - - Assert.False(oneNewtonMeterPerRadianPerMeter > twoNewtonMetersPerRadianPerMeter); - Assert.False(oneNewtonMeterPerRadianPerMeter >= twoNewtonMetersPerRadianPerMeter); - Assert.False(twoNewtonMetersPerRadianPerMeter < oneNewtonMeterPerRadianPerMeter); - Assert.False(twoNewtonMetersPerRadianPerMeter <= oneNewtonMeterPerRadianPerMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - RotationalStiffnessPerLength newtonmeterperradianpermeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - Assert.Equal(0, newtonmeterperradianpermeter.CompareTo(newtonmeterperradianpermeter)); - Assert.True(newtonmeterperradianpermeter.CompareTo(RotationalStiffnessPerLength.Zero) > 0); - Assert.True(RotationalStiffnessPerLength.Zero.CompareTo(newtonmeterperradianpermeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - RotationalStiffnessPerLength newtonmeterperradianpermeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - Assert.Throws(() => newtonmeterperradianpermeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - RotationalStiffnessPerLength newtonmeterperradianpermeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - Assert.Throws(() => newtonmeterperradianpermeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - RotationalStiffnessPerLength v = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - Assert.True(v.Equals(RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1), NewtonMetersPerRadianPerMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(RotationalStiffnessPerLength.Zero, NewtonMetersPerRadianPerMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - RotationalStiffnessPerLength newtonmeterperradianpermeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - Assert.False(newtonmeterperradianpermeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - RotationalStiffnessPerLength newtonmeterperradianpermeter = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1); - Assert.False(newtonmeterperradianpermeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(RotationalStiffnessPerLengthUnit.Undefined, RotationalStiffnessPerLength.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(RotationalStiffnessPerLengthUnit)).Cast(); - foreach(var unit in units) - { - if(unit == RotationalStiffnessPerLengthUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/RotationalStiffnessTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/RotationalStiffnessTestsBase.g.cs deleted file mode 100644 index 8813ed8ae6..0000000000 --- a/UnitsNet.Tests/GeneratedCode/RotationalStiffnessTestsBase.g.cs +++ /dev/null @@ -1,244 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of RotationalStiffness. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RotationalStiffnessTestsBase - { - protected abstract double KilonewtonMetersPerRadianInOneNewtonMeterPerRadian { get; } - protected abstract double MeganewtonMetersPerRadianInOneNewtonMeterPerRadian { get; } - protected abstract double NewtonMetersPerRadianInOneNewtonMeterPerRadian { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilonewtonMetersPerRadianTolerance { get { return 1e-5; } } - protected virtual double MeganewtonMetersPerRadianTolerance { get { return 1e-5; } } - protected virtual double NewtonMetersPerRadianTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalStiffness((double)0.0, RotationalStiffnessUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalStiffness(double.PositiveInfinity, RotationalStiffnessUnit.NewtonMeterPerRadian)); - Assert.Throws(() => new RotationalStiffness(double.NegativeInfinity, RotationalStiffnessUnit.NewtonMeterPerRadian)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new RotationalStiffness(double.NaN, RotationalStiffnessUnit.NewtonMeterPerRadian)); - } - - [Fact] - public void NewtonMeterPerRadianToRotationalStiffnessUnits() - { - RotationalStiffness newtonmeterperradian = RotationalStiffness.FromNewtonMetersPerRadian(1); - AssertEx.EqualTolerance(KilonewtonMetersPerRadianInOneNewtonMeterPerRadian, newtonmeterperradian.KilonewtonMetersPerRadian, KilonewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(MeganewtonMetersPerRadianInOneNewtonMeterPerRadian, newtonmeterperradian.MeganewtonMetersPerRadian, MeganewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(NewtonMetersPerRadianInOneNewtonMeterPerRadian, newtonmeterperradian.NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, RotationalStiffness.From(1, RotationalStiffnessUnit.KilonewtonMeterPerRadian).KilonewtonMetersPerRadian, KilonewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(1, RotationalStiffness.From(1, RotationalStiffnessUnit.MeganewtonMeterPerRadian).MeganewtonMetersPerRadian, MeganewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(1, RotationalStiffness.From(1, RotationalStiffnessUnit.NewtonMeterPerRadian).NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - } - - [Fact] - public void FromNewtonMetersPerRadian_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => RotationalStiffness.FromNewtonMetersPerRadian(double.PositiveInfinity)); - Assert.Throws(() => RotationalStiffness.FromNewtonMetersPerRadian(double.NegativeInfinity)); - } - - [Fact] - public void FromNewtonMetersPerRadian_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => RotationalStiffness.FromNewtonMetersPerRadian(double.NaN)); - } - - [Fact] - public void As() - { - var newtonmeterperradian = RotationalStiffness.FromNewtonMetersPerRadian(1); - AssertEx.EqualTolerance(KilonewtonMetersPerRadianInOneNewtonMeterPerRadian, newtonmeterperradian.As(RotationalStiffnessUnit.KilonewtonMeterPerRadian), KilonewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(MeganewtonMetersPerRadianInOneNewtonMeterPerRadian, newtonmeterperradian.As(RotationalStiffnessUnit.MeganewtonMeterPerRadian), MeganewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(NewtonMetersPerRadianInOneNewtonMeterPerRadian, newtonmeterperradian.As(RotationalStiffnessUnit.NewtonMeterPerRadian), NewtonMetersPerRadianTolerance); - } - - [Fact] - public void ToUnit() - { - var newtonmeterperradian = RotationalStiffness.FromNewtonMetersPerRadian(1); - - var kilonewtonmeterperradianQuantity = newtonmeterperradian.ToUnit(RotationalStiffnessUnit.KilonewtonMeterPerRadian); - AssertEx.EqualTolerance(KilonewtonMetersPerRadianInOneNewtonMeterPerRadian, (double)kilonewtonmeterperradianQuantity.Value, KilonewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerRadian, kilonewtonmeterperradianQuantity.Unit); - - var meganewtonmeterperradianQuantity = newtonmeterperradian.ToUnit(RotationalStiffnessUnit.MeganewtonMeterPerRadian); - AssertEx.EqualTolerance(MeganewtonMetersPerRadianInOneNewtonMeterPerRadian, (double)meganewtonmeterperradianQuantity.Value, MeganewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerRadian, meganewtonmeterperradianQuantity.Unit); - - var newtonmeterperradianQuantity = newtonmeterperradian.ToUnit(RotationalStiffnessUnit.NewtonMeterPerRadian); - AssertEx.EqualTolerance(NewtonMetersPerRadianInOneNewtonMeterPerRadian, (double)newtonmeterperradianQuantity.Value, NewtonMetersPerRadianTolerance); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerRadian, newtonmeterperradianQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - RotationalStiffness newtonmeterperradian = RotationalStiffness.FromNewtonMetersPerRadian(1); - AssertEx.EqualTolerance(1, RotationalStiffness.FromKilonewtonMetersPerRadian(newtonmeterperradian.KilonewtonMetersPerRadian).NewtonMetersPerRadian, KilonewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(1, RotationalStiffness.FromMeganewtonMetersPerRadian(newtonmeterperradian.MeganewtonMetersPerRadian).NewtonMetersPerRadian, MeganewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(1, RotationalStiffness.FromNewtonMetersPerRadian(newtonmeterperradian.NewtonMetersPerRadian).NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - RotationalStiffness v = RotationalStiffness.FromNewtonMetersPerRadian(1); - AssertEx.EqualTolerance(-1, -v.NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(2, (RotationalStiffness.FromNewtonMetersPerRadian(3)-v).NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(2, (v + v).NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(10, (v*10).NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(10, (10*v).NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(2, (RotationalStiffness.FromNewtonMetersPerRadian(10)/5).NewtonMetersPerRadian, NewtonMetersPerRadianTolerance); - AssertEx.EqualTolerance(2, RotationalStiffness.FromNewtonMetersPerRadian(10)/RotationalStiffness.FromNewtonMetersPerRadian(5), NewtonMetersPerRadianTolerance); - } - - [Fact] - public void ComparisonOperators() - { - RotationalStiffness oneNewtonMeterPerRadian = RotationalStiffness.FromNewtonMetersPerRadian(1); - RotationalStiffness twoNewtonMetersPerRadian = RotationalStiffness.FromNewtonMetersPerRadian(2); - - Assert.True(oneNewtonMeterPerRadian < twoNewtonMetersPerRadian); - Assert.True(oneNewtonMeterPerRadian <= twoNewtonMetersPerRadian); - Assert.True(twoNewtonMetersPerRadian > oneNewtonMeterPerRadian); - Assert.True(twoNewtonMetersPerRadian >= oneNewtonMeterPerRadian); - - Assert.False(oneNewtonMeterPerRadian > twoNewtonMetersPerRadian); - Assert.False(oneNewtonMeterPerRadian >= twoNewtonMetersPerRadian); - Assert.False(twoNewtonMetersPerRadian < oneNewtonMeterPerRadian); - Assert.False(twoNewtonMetersPerRadian <= oneNewtonMeterPerRadian); - } - - [Fact] - public void CompareToIsImplemented() - { - RotationalStiffness newtonmeterperradian = RotationalStiffness.FromNewtonMetersPerRadian(1); - Assert.Equal(0, newtonmeterperradian.CompareTo(newtonmeterperradian)); - Assert.True(newtonmeterperradian.CompareTo(RotationalStiffness.Zero) > 0); - Assert.True(RotationalStiffness.Zero.CompareTo(newtonmeterperradian) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - RotationalStiffness newtonmeterperradian = RotationalStiffness.FromNewtonMetersPerRadian(1); - Assert.Throws(() => newtonmeterperradian.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - RotationalStiffness newtonmeterperradian = RotationalStiffness.FromNewtonMetersPerRadian(1); - Assert.Throws(() => newtonmeterperradian.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - RotationalStiffness v = RotationalStiffness.FromNewtonMetersPerRadian(1); - Assert.True(v.Equals(RotationalStiffness.FromNewtonMetersPerRadian(1), NewtonMetersPerRadianTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(RotationalStiffness.Zero, NewtonMetersPerRadianTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - RotationalStiffness newtonmeterperradian = RotationalStiffness.FromNewtonMetersPerRadian(1); - Assert.False(newtonmeterperradian.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - RotationalStiffness newtonmeterperradian = RotationalStiffness.FromNewtonMetersPerRadian(1); - Assert.False(newtonmeterperradian.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(RotationalStiffnessUnit.Undefined, RotationalStiffness.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(RotationalStiffnessUnit)).Cast(); - foreach(var unit in units) - { - if(unit == RotationalStiffnessUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/SolidAngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/SolidAngleTestsBase.g.cs deleted file mode 100644 index ffef4404df..0000000000 --- a/UnitsNet.Tests/GeneratedCode/SolidAngleTestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of SolidAngle. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SolidAngleTestsBase - { - protected abstract double SteradiansInOneSteradian { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double SteradiansTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new SolidAngle((double)0.0, SolidAngleUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new SolidAngle(double.PositiveInfinity, SolidAngleUnit.Steradian)); - Assert.Throws(() => new SolidAngle(double.NegativeInfinity, SolidAngleUnit.Steradian)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new SolidAngle(double.NaN, SolidAngleUnit.Steradian)); - } - - [Fact] - public void SteradianToSolidAngleUnits() - { - SolidAngle steradian = SolidAngle.FromSteradians(1); - AssertEx.EqualTolerance(SteradiansInOneSteradian, steradian.Steradians, SteradiansTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, SolidAngle.From(1, SolidAngleUnit.Steradian).Steradians, SteradiansTolerance); - } - - [Fact] - public void FromSteradians_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => SolidAngle.FromSteradians(double.PositiveInfinity)); - Assert.Throws(() => SolidAngle.FromSteradians(double.NegativeInfinity)); - } - - [Fact] - public void FromSteradians_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => SolidAngle.FromSteradians(double.NaN)); - } - - [Fact] - public void As() - { - var steradian = SolidAngle.FromSteradians(1); - AssertEx.EqualTolerance(SteradiansInOneSteradian, steradian.As(SolidAngleUnit.Steradian), SteradiansTolerance); - } - - [Fact] - public void ToUnit() - { - var steradian = SolidAngle.FromSteradians(1); - - var steradianQuantity = steradian.ToUnit(SolidAngleUnit.Steradian); - AssertEx.EqualTolerance(SteradiansInOneSteradian, (double)steradianQuantity.Value, SteradiansTolerance); - Assert.Equal(SolidAngleUnit.Steradian, steradianQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - SolidAngle steradian = SolidAngle.FromSteradians(1); - AssertEx.EqualTolerance(1, SolidAngle.FromSteradians(steradian.Steradians).Steradians, SteradiansTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - SolidAngle v = SolidAngle.FromSteradians(1); - AssertEx.EqualTolerance(-1, -v.Steradians, SteradiansTolerance); - AssertEx.EqualTolerance(2, (SolidAngle.FromSteradians(3)-v).Steradians, SteradiansTolerance); - AssertEx.EqualTolerance(2, (v + v).Steradians, SteradiansTolerance); - AssertEx.EqualTolerance(10, (v*10).Steradians, SteradiansTolerance); - AssertEx.EqualTolerance(10, (10*v).Steradians, SteradiansTolerance); - AssertEx.EqualTolerance(2, (SolidAngle.FromSteradians(10)/5).Steradians, SteradiansTolerance); - AssertEx.EqualTolerance(2, SolidAngle.FromSteradians(10)/SolidAngle.FromSteradians(5), SteradiansTolerance); - } - - [Fact] - public void ComparisonOperators() - { - SolidAngle oneSteradian = SolidAngle.FromSteradians(1); - SolidAngle twoSteradians = SolidAngle.FromSteradians(2); - - Assert.True(oneSteradian < twoSteradians); - Assert.True(oneSteradian <= twoSteradians); - Assert.True(twoSteradians > oneSteradian); - Assert.True(twoSteradians >= oneSteradian); - - Assert.False(oneSteradian > twoSteradians); - Assert.False(oneSteradian >= twoSteradians); - Assert.False(twoSteradians < oneSteradian); - Assert.False(twoSteradians <= oneSteradian); - } - - [Fact] - public void CompareToIsImplemented() - { - SolidAngle steradian = SolidAngle.FromSteradians(1); - Assert.Equal(0, steradian.CompareTo(steradian)); - Assert.True(steradian.CompareTo(SolidAngle.Zero) > 0); - Assert.True(SolidAngle.Zero.CompareTo(steradian) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - SolidAngle steradian = SolidAngle.FromSteradians(1); - Assert.Throws(() => steradian.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - SolidAngle steradian = SolidAngle.FromSteradians(1); - Assert.Throws(() => steradian.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - SolidAngle v = SolidAngle.FromSteradians(1); - Assert.True(v.Equals(SolidAngle.FromSteradians(1), SteradiansTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(SolidAngle.Zero, SteradiansTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - SolidAngle steradian = SolidAngle.FromSteradians(1); - Assert.False(steradian.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - SolidAngle steradian = SolidAngle.FromSteradians(1); - Assert.False(steradian.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(SolidAngleUnit.Undefined, SolidAngle.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(SolidAngleUnit)).Cast(); - foreach(var unit in units) - { - if(unit == SolidAngleUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/SpecificEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/SpecificEnergyTestsBase.g.cs deleted file mode 100644 index 1335fdae20..0000000000 --- a/UnitsNet.Tests/GeneratedCode/SpecificEnergyTestsBase.g.cs +++ /dev/null @@ -1,294 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of SpecificEnergy. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpecificEnergyTestsBase - { - protected abstract double CaloriesPerGramInOneJoulePerKilogram { get; } - protected abstract double JoulesPerKilogramInOneJoulePerKilogram { get; } - protected abstract double KilocaloriesPerGramInOneJoulePerKilogram { get; } - protected abstract double KilojoulesPerKilogramInOneJoulePerKilogram { get; } - protected abstract double KilowattHoursPerKilogramInOneJoulePerKilogram { get; } - protected abstract double MegajoulesPerKilogramInOneJoulePerKilogram { get; } - protected abstract double MegawattHoursPerKilogramInOneJoulePerKilogram { get; } - protected abstract double WattHoursPerKilogramInOneJoulePerKilogram { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CaloriesPerGramTolerance { get { return 1e-5; } } - protected virtual double JoulesPerKilogramTolerance { get { return 1e-5; } } - protected virtual double KilocaloriesPerGramTolerance { get { return 1e-5; } } - protected virtual double KilojoulesPerKilogramTolerance { get { return 1e-5; } } - protected virtual double KilowattHoursPerKilogramTolerance { get { return 1e-5; } } - protected virtual double MegajoulesPerKilogramTolerance { get { return 1e-5; } } - protected virtual double MegawattHoursPerKilogramTolerance { get { return 1e-5; } } - protected virtual double WattHoursPerKilogramTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificEnergy((double)0.0, SpecificEnergyUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificEnergy(double.PositiveInfinity, SpecificEnergyUnit.JoulePerKilogram)); - Assert.Throws(() => new SpecificEnergy(double.NegativeInfinity, SpecificEnergyUnit.JoulePerKilogram)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificEnergy(double.NaN, SpecificEnergyUnit.JoulePerKilogram)); - } - - [Fact] - public void JoulePerKilogramToSpecificEnergyUnits() - { - SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); - AssertEx.EqualTolerance(CaloriesPerGramInOneJoulePerKilogram, jouleperkilogram.CaloriesPerGram, CaloriesPerGramTolerance); - AssertEx.EqualTolerance(JoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.JoulesPerKilogram, JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(KilocaloriesPerGramInOneJoulePerKilogram, jouleperkilogram.KilocaloriesPerGram, KilocaloriesPerGramTolerance); - AssertEx.EqualTolerance(KilojoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.KilojoulesPerKilogram, KilojoulesPerKilogramTolerance); - AssertEx.EqualTolerance(KilowattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.KilowattHoursPerKilogram, KilowattHoursPerKilogramTolerance); - AssertEx.EqualTolerance(MegajoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.MegajoulesPerKilogram, MegajoulesPerKilogramTolerance); - AssertEx.EqualTolerance(MegawattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.MegawattHoursPerKilogram, MegawattHoursPerKilogramTolerance); - AssertEx.EqualTolerance(WattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.WattHoursPerKilogram, WattHoursPerKilogramTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, SpecificEnergy.From(1, SpecificEnergyUnit.CaloriePerGram).CaloriesPerGram, CaloriesPerGramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.From(1, SpecificEnergyUnit.JoulePerKilogram).JoulesPerKilogram, JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.From(1, SpecificEnergyUnit.KilocaloriePerGram).KilocaloriesPerGram, KilocaloriesPerGramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.From(1, SpecificEnergyUnit.KilojoulePerKilogram).KilojoulesPerKilogram, KilojoulesPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.From(1, SpecificEnergyUnit.KilowattHourPerKilogram).KilowattHoursPerKilogram, KilowattHoursPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.From(1, SpecificEnergyUnit.MegajoulePerKilogram).MegajoulesPerKilogram, MegajoulesPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.From(1, SpecificEnergyUnit.MegawattHourPerKilogram).MegawattHoursPerKilogram, MegawattHoursPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.From(1, SpecificEnergyUnit.WattHourPerKilogram).WattHoursPerKilogram, WattHoursPerKilogramTolerance); - } - - [Fact] - public void FromJoulesPerKilogram_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => SpecificEnergy.FromJoulesPerKilogram(double.PositiveInfinity)); - Assert.Throws(() => SpecificEnergy.FromJoulesPerKilogram(double.NegativeInfinity)); - } - - [Fact] - public void FromJoulesPerKilogram_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => SpecificEnergy.FromJoulesPerKilogram(double.NaN)); - } - - [Fact] - public void As() - { - var jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); - AssertEx.EqualTolerance(CaloriesPerGramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.CaloriePerGram), CaloriesPerGramTolerance); - AssertEx.EqualTolerance(JoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.JoulePerKilogram), JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(KilocaloriesPerGramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.KilocaloriePerGram), KilocaloriesPerGramTolerance); - AssertEx.EqualTolerance(KilojoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.KilojoulePerKilogram), KilojoulesPerKilogramTolerance); - AssertEx.EqualTolerance(KilowattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.KilowattHourPerKilogram), KilowattHoursPerKilogramTolerance); - AssertEx.EqualTolerance(MegajoulesPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.MegajoulePerKilogram), MegajoulesPerKilogramTolerance); - AssertEx.EqualTolerance(MegawattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.MegawattHourPerKilogram), MegawattHoursPerKilogramTolerance); - AssertEx.EqualTolerance(WattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.WattHourPerKilogram), WattHoursPerKilogramTolerance); - } - - [Fact] - public void ToUnit() - { - var jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); - - var caloriepergramQuantity = jouleperkilogram.ToUnit(SpecificEnergyUnit.CaloriePerGram); - AssertEx.EqualTolerance(CaloriesPerGramInOneJoulePerKilogram, (double)caloriepergramQuantity.Value, CaloriesPerGramTolerance); - Assert.Equal(SpecificEnergyUnit.CaloriePerGram, caloriepergramQuantity.Unit); - - var jouleperkilogramQuantity = jouleperkilogram.ToUnit(SpecificEnergyUnit.JoulePerKilogram); - AssertEx.EqualTolerance(JoulesPerKilogramInOneJoulePerKilogram, (double)jouleperkilogramQuantity.Value, JoulesPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.JoulePerKilogram, jouleperkilogramQuantity.Unit); - - var kilocaloriepergramQuantity = jouleperkilogram.ToUnit(SpecificEnergyUnit.KilocaloriePerGram); - AssertEx.EqualTolerance(KilocaloriesPerGramInOneJoulePerKilogram, (double)kilocaloriepergramQuantity.Value, KilocaloriesPerGramTolerance); - Assert.Equal(SpecificEnergyUnit.KilocaloriePerGram, kilocaloriepergramQuantity.Unit); - - var kilojouleperkilogramQuantity = jouleperkilogram.ToUnit(SpecificEnergyUnit.KilojoulePerKilogram); - AssertEx.EqualTolerance(KilojoulesPerKilogramInOneJoulePerKilogram, (double)kilojouleperkilogramQuantity.Value, KilojoulesPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.KilojoulePerKilogram, kilojouleperkilogramQuantity.Unit); - - var kilowatthourperkilogramQuantity = jouleperkilogram.ToUnit(SpecificEnergyUnit.KilowattHourPerKilogram); - AssertEx.EqualTolerance(KilowattHoursPerKilogramInOneJoulePerKilogram, (double)kilowatthourperkilogramQuantity.Value, KilowattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.KilowattHourPerKilogram, kilowatthourperkilogramQuantity.Unit); - - var megajouleperkilogramQuantity = jouleperkilogram.ToUnit(SpecificEnergyUnit.MegajoulePerKilogram); - AssertEx.EqualTolerance(MegajoulesPerKilogramInOneJoulePerKilogram, (double)megajouleperkilogramQuantity.Value, MegajoulesPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.MegajoulePerKilogram, megajouleperkilogramQuantity.Unit); - - var megawatthourperkilogramQuantity = jouleperkilogram.ToUnit(SpecificEnergyUnit.MegawattHourPerKilogram); - AssertEx.EqualTolerance(MegawattHoursPerKilogramInOneJoulePerKilogram, (double)megawatthourperkilogramQuantity.Value, MegawattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.MegawattHourPerKilogram, megawatthourperkilogramQuantity.Unit); - - var watthourperkilogramQuantity = jouleperkilogram.ToUnit(SpecificEnergyUnit.WattHourPerKilogram); - AssertEx.EqualTolerance(WattHoursPerKilogramInOneJoulePerKilogram, (double)watthourperkilogramQuantity.Value, WattHoursPerKilogramTolerance); - Assert.Equal(SpecificEnergyUnit.WattHourPerKilogram, watthourperkilogramQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); - AssertEx.EqualTolerance(1, SpecificEnergy.FromCaloriesPerGram(jouleperkilogram.CaloriesPerGram).JoulesPerKilogram, CaloriesPerGramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.FromJoulesPerKilogram(jouleperkilogram.JoulesPerKilogram).JoulesPerKilogram, JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.FromKilocaloriesPerGram(jouleperkilogram.KilocaloriesPerGram).JoulesPerKilogram, KilocaloriesPerGramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.FromKilojoulesPerKilogram(jouleperkilogram.KilojoulesPerKilogram).JoulesPerKilogram, KilojoulesPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.FromKilowattHoursPerKilogram(jouleperkilogram.KilowattHoursPerKilogram).JoulesPerKilogram, KilowattHoursPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.FromMegajoulesPerKilogram(jouleperkilogram.MegajoulesPerKilogram).JoulesPerKilogram, MegajoulesPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.FromMegawattHoursPerKilogram(jouleperkilogram.MegawattHoursPerKilogram).JoulesPerKilogram, MegawattHoursPerKilogramTolerance); - AssertEx.EqualTolerance(1, SpecificEnergy.FromWattHoursPerKilogram(jouleperkilogram.WattHoursPerKilogram).JoulesPerKilogram, WattHoursPerKilogramTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - SpecificEnergy v = SpecificEnergy.FromJoulesPerKilogram(1); - AssertEx.EqualTolerance(-1, -v.JoulesPerKilogram, JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(2, (SpecificEnergy.FromJoulesPerKilogram(3)-v).JoulesPerKilogram, JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(2, (v + v).JoulesPerKilogram, JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(10, (v*10).JoulesPerKilogram, JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(10, (10*v).JoulesPerKilogram, JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(2, (SpecificEnergy.FromJoulesPerKilogram(10)/5).JoulesPerKilogram, JoulesPerKilogramTolerance); - AssertEx.EqualTolerance(2, SpecificEnergy.FromJoulesPerKilogram(10)/SpecificEnergy.FromJoulesPerKilogram(5), JoulesPerKilogramTolerance); - } - - [Fact] - public void ComparisonOperators() - { - SpecificEnergy oneJoulePerKilogram = SpecificEnergy.FromJoulesPerKilogram(1); - SpecificEnergy twoJoulesPerKilogram = SpecificEnergy.FromJoulesPerKilogram(2); - - Assert.True(oneJoulePerKilogram < twoJoulesPerKilogram); - Assert.True(oneJoulePerKilogram <= twoJoulesPerKilogram); - Assert.True(twoJoulesPerKilogram > oneJoulePerKilogram); - Assert.True(twoJoulesPerKilogram >= oneJoulePerKilogram); - - Assert.False(oneJoulePerKilogram > twoJoulesPerKilogram); - Assert.False(oneJoulePerKilogram >= twoJoulesPerKilogram); - Assert.False(twoJoulesPerKilogram < oneJoulePerKilogram); - Assert.False(twoJoulesPerKilogram <= oneJoulePerKilogram); - } - - [Fact] - public void CompareToIsImplemented() - { - SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); - Assert.Equal(0, jouleperkilogram.CompareTo(jouleperkilogram)); - Assert.True(jouleperkilogram.CompareTo(SpecificEnergy.Zero) > 0); - Assert.True(SpecificEnergy.Zero.CompareTo(jouleperkilogram) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); - Assert.Throws(() => jouleperkilogram.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); - Assert.Throws(() => jouleperkilogram.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - SpecificEnergy v = SpecificEnergy.FromJoulesPerKilogram(1); - Assert.True(v.Equals(SpecificEnergy.FromJoulesPerKilogram(1), JoulesPerKilogramTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(SpecificEnergy.Zero, JoulesPerKilogramTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); - Assert.False(jouleperkilogram.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - SpecificEnergy jouleperkilogram = SpecificEnergy.FromJoulesPerKilogram(1); - Assert.False(jouleperkilogram.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(SpecificEnergyUnit.Undefined, SpecificEnergy.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(SpecificEnergyUnit)).Cast(); - foreach(var unit in units) - { - if(unit == SpecificEnergyUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/SpecificEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/SpecificEntropyTestsBase.g.cs deleted file mode 100644 index 7e26f65596..0000000000 --- a/UnitsNet.Tests/GeneratedCode/SpecificEntropyTestsBase.g.cs +++ /dev/null @@ -1,294 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of SpecificEntropy. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpecificEntropyTestsBase - { - protected abstract double CaloriesPerGramKelvinInOneJoulePerKilogramKelvin { get; } - protected abstract double JoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin { get; } - protected abstract double JoulesPerKilogramKelvinInOneJoulePerKilogramKelvin { get; } - protected abstract double KilocaloriesPerGramKelvinInOneJoulePerKilogramKelvin { get; } - protected abstract double KilojoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin { get; } - protected abstract double KilojoulesPerKilogramKelvinInOneJoulePerKilogramKelvin { get; } - protected abstract double MegajoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin { get; } - protected abstract double MegajoulesPerKilogramKelvinInOneJoulePerKilogramKelvin { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CaloriesPerGramKelvinTolerance { get { return 1e-5; } } - protected virtual double JoulesPerKilogramDegreeCelsiusTolerance { get { return 1e-5; } } - protected virtual double JoulesPerKilogramKelvinTolerance { get { return 1e-5; } } - protected virtual double KilocaloriesPerGramKelvinTolerance { get { return 1e-5; } } - protected virtual double KilojoulesPerKilogramDegreeCelsiusTolerance { get { return 1e-5; } } - protected virtual double KilojoulesPerKilogramKelvinTolerance { get { return 1e-5; } } - protected virtual double MegajoulesPerKilogramDegreeCelsiusTolerance { get { return 1e-5; } } - protected virtual double MegajoulesPerKilogramKelvinTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificEntropy((double)0.0, SpecificEntropyUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificEntropy(double.PositiveInfinity, SpecificEntropyUnit.JoulePerKilogramKelvin)); - Assert.Throws(() => new SpecificEntropy(double.NegativeInfinity, SpecificEntropyUnit.JoulePerKilogramKelvin)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificEntropy(double.NaN, SpecificEntropyUnit.JoulePerKilogramKelvin)); - } - - [Fact] - public void JoulePerKilogramKelvinToSpecificEntropyUnits() - { - SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - AssertEx.EqualTolerance(CaloriesPerGramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.CaloriesPerGramKelvin, CaloriesPerGramKelvinTolerance); - AssertEx.EqualTolerance(JoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.JoulesPerKilogramDegreeCelsius, JoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(JoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(KilocaloriesPerGramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.KilocaloriesPerGramKelvin, KilocaloriesPerGramKelvinTolerance); - AssertEx.EqualTolerance(KilojoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.KilojoulesPerKilogramDegreeCelsius, KilojoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(KilojoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.KilojoulesPerKilogramKelvin, KilojoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(MegajoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.MegajoulesPerKilogramDegreeCelsius, MegajoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(MegajoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.MegajoulesPerKilogramKelvin, MegajoulesPerKilogramKelvinTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.CaloriePerGramKelvin).CaloriesPerGramKelvin, CaloriesPerGramKelvinTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.JoulePerKilogramDegreeCelsius).JoulesPerKilogramDegreeCelsius, JoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.JoulePerKilogramKelvin).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.KilocaloriePerGramKelvin).KilocaloriesPerGramKelvin, KilocaloriesPerGramKelvinTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius).KilojoulesPerKilogramDegreeCelsius, KilojoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.KilojoulePerKilogramKelvin).KilojoulesPerKilogramKelvin, KilojoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius).MegajoulesPerKilogramDegreeCelsius, MegajoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.From(1, SpecificEntropyUnit.MegajoulePerKilogramKelvin).MegajoulesPerKilogramKelvin, MegajoulesPerKilogramKelvinTolerance); - } - - [Fact] - public void FromJoulesPerKilogramKelvin_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => SpecificEntropy.FromJoulesPerKilogramKelvin(double.PositiveInfinity)); - Assert.Throws(() => SpecificEntropy.FromJoulesPerKilogramKelvin(double.NegativeInfinity)); - } - - [Fact] - public void FromJoulesPerKilogramKelvin_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => SpecificEntropy.FromJoulesPerKilogramKelvin(double.NaN)); - } - - [Fact] - public void As() - { - var jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - AssertEx.EqualTolerance(CaloriesPerGramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.CaloriePerGramKelvin), CaloriesPerGramKelvinTolerance); - AssertEx.EqualTolerance(JoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius), JoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(JoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.JoulePerKilogramKelvin), JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(KilocaloriesPerGramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.KilocaloriePerGramKelvin), KilocaloriesPerGramKelvinTolerance); - AssertEx.EqualTolerance(KilojoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius), KilojoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(KilojoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.KilojoulePerKilogramKelvin), KilojoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(MegajoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius), MegajoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(MegajoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.MegajoulePerKilogramKelvin), MegajoulesPerKilogramKelvinTolerance); - } - - [Fact] - public void ToUnit() - { - var jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - - var caloriepergramkelvinQuantity = jouleperkilogramkelvin.ToUnit(SpecificEntropyUnit.CaloriePerGramKelvin); - AssertEx.EqualTolerance(CaloriesPerGramKelvinInOneJoulePerKilogramKelvin, (double)caloriepergramkelvinQuantity.Value, CaloriesPerGramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.CaloriePerGramKelvin, caloriepergramkelvinQuantity.Unit); - - var jouleperkilogramdegreecelsiusQuantity = jouleperkilogramkelvin.ToUnit(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius); - AssertEx.EqualTolerance(JoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, (double)jouleperkilogramdegreecelsiusQuantity.Value, JoulesPerKilogramDegreeCelsiusTolerance); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, jouleperkilogramdegreecelsiusQuantity.Unit); - - var jouleperkilogramkelvinQuantity = jouleperkilogramkelvin.ToUnit(SpecificEntropyUnit.JoulePerKilogramKelvin); - AssertEx.EqualTolerance(JoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, (double)jouleperkilogramkelvinQuantity.Value, JoulesPerKilogramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramKelvin, jouleperkilogramkelvinQuantity.Unit); - - var kilocaloriepergramkelvinQuantity = jouleperkilogramkelvin.ToUnit(SpecificEntropyUnit.KilocaloriePerGramKelvin); - AssertEx.EqualTolerance(KilocaloriesPerGramKelvinInOneJoulePerKilogramKelvin, (double)kilocaloriepergramkelvinQuantity.Value, KilocaloriesPerGramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.KilocaloriePerGramKelvin, kilocaloriepergramkelvinQuantity.Unit); - - var kilojouleperkilogramdegreecelsiusQuantity = jouleperkilogramkelvin.ToUnit(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius); - AssertEx.EqualTolerance(KilojoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, (double)kilojouleperkilogramdegreecelsiusQuantity.Value, KilojoulesPerKilogramDegreeCelsiusTolerance); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, kilojouleperkilogramdegreecelsiusQuantity.Unit); - - var kilojouleperkilogramkelvinQuantity = jouleperkilogramkelvin.ToUnit(SpecificEntropyUnit.KilojoulePerKilogramKelvin); - AssertEx.EqualTolerance(KilojoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, (double)kilojouleperkilogramkelvinQuantity.Value, KilojoulesPerKilogramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramKelvin, kilojouleperkilogramkelvinQuantity.Unit); - - var megajouleperkilogramdegreecelsiusQuantity = jouleperkilogramkelvin.ToUnit(SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius); - AssertEx.EqualTolerance(MegajoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin, (double)megajouleperkilogramdegreecelsiusQuantity.Value, MegajoulesPerKilogramDegreeCelsiusTolerance); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, megajouleperkilogramdegreecelsiusQuantity.Unit); - - var megajouleperkilogramkelvinQuantity = jouleperkilogramkelvin.ToUnit(SpecificEntropyUnit.MegajoulePerKilogramKelvin); - AssertEx.EqualTolerance(MegajoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, (double)megajouleperkilogramkelvinQuantity.Value, MegajoulesPerKilogramKelvinTolerance); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramKelvin, megajouleperkilogramkelvinQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - AssertEx.EqualTolerance(1, SpecificEntropy.FromCaloriesPerGramKelvin(jouleperkilogramkelvin.CaloriesPerGramKelvin).JoulesPerKilogramKelvin, CaloriesPerGramKelvinTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.FromJoulesPerKilogramDegreeCelsius(jouleperkilogramkelvin.JoulesPerKilogramDegreeCelsius).JoulesPerKilogramKelvin, JoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.FromJoulesPerKilogramKelvin(jouleperkilogramkelvin.JoulesPerKilogramKelvin).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.FromKilocaloriesPerGramKelvin(jouleperkilogramkelvin.KilocaloriesPerGramKelvin).JoulesPerKilogramKelvin, KilocaloriesPerGramKelvinTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.FromKilojoulesPerKilogramDegreeCelsius(jouleperkilogramkelvin.KilojoulesPerKilogramDegreeCelsius).JoulesPerKilogramKelvin, KilojoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.FromKilojoulesPerKilogramKelvin(jouleperkilogramkelvin.KilojoulesPerKilogramKelvin).JoulesPerKilogramKelvin, KilojoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.FromMegajoulesPerKilogramDegreeCelsius(jouleperkilogramkelvin.MegajoulesPerKilogramDegreeCelsius).JoulesPerKilogramKelvin, MegajoulesPerKilogramDegreeCelsiusTolerance); - AssertEx.EqualTolerance(1, SpecificEntropy.FromMegajoulesPerKilogramKelvin(jouleperkilogramkelvin.MegajoulesPerKilogramKelvin).JoulesPerKilogramKelvin, MegajoulesPerKilogramKelvinTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - SpecificEntropy v = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - AssertEx.EqualTolerance(-1, -v.JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(2, (SpecificEntropy.FromJoulesPerKilogramKelvin(3)-v).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(2, (v + v).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(10, (v*10).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(10, (10*v).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(2, (SpecificEntropy.FromJoulesPerKilogramKelvin(10)/5).JoulesPerKilogramKelvin, JoulesPerKilogramKelvinTolerance); - AssertEx.EqualTolerance(2, SpecificEntropy.FromJoulesPerKilogramKelvin(10)/SpecificEntropy.FromJoulesPerKilogramKelvin(5), JoulesPerKilogramKelvinTolerance); - } - - [Fact] - public void ComparisonOperators() - { - SpecificEntropy oneJoulePerKilogramKelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - SpecificEntropy twoJoulesPerKilogramKelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(2); - - Assert.True(oneJoulePerKilogramKelvin < twoJoulesPerKilogramKelvin); - Assert.True(oneJoulePerKilogramKelvin <= twoJoulesPerKilogramKelvin); - Assert.True(twoJoulesPerKilogramKelvin > oneJoulePerKilogramKelvin); - Assert.True(twoJoulesPerKilogramKelvin >= oneJoulePerKilogramKelvin); - - Assert.False(oneJoulePerKilogramKelvin > twoJoulesPerKilogramKelvin); - Assert.False(oneJoulePerKilogramKelvin >= twoJoulesPerKilogramKelvin); - Assert.False(twoJoulesPerKilogramKelvin < oneJoulePerKilogramKelvin); - Assert.False(twoJoulesPerKilogramKelvin <= oneJoulePerKilogramKelvin); - } - - [Fact] - public void CompareToIsImplemented() - { - SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - Assert.Equal(0, jouleperkilogramkelvin.CompareTo(jouleperkilogramkelvin)); - Assert.True(jouleperkilogramkelvin.CompareTo(SpecificEntropy.Zero) > 0); - Assert.True(SpecificEntropy.Zero.CompareTo(jouleperkilogramkelvin) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - Assert.Throws(() => jouleperkilogramkelvin.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - Assert.Throws(() => jouleperkilogramkelvin.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - SpecificEntropy v = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - Assert.True(v.Equals(SpecificEntropy.FromJoulesPerKilogramKelvin(1), JoulesPerKilogramKelvinTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(SpecificEntropy.Zero, JoulesPerKilogramKelvinTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - Assert.False(jouleperkilogramkelvin.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - SpecificEntropy jouleperkilogramkelvin = SpecificEntropy.FromJoulesPerKilogramKelvin(1); - Assert.False(jouleperkilogramkelvin.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(SpecificEntropyUnit.Undefined, SpecificEntropy.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(SpecificEntropyUnit)).Cast(); - foreach(var unit in units) - { - if(unit == SpecificEntropyUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/SpecificVolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/SpecificVolumeTestsBase.g.cs deleted file mode 100644 index dd4e38f4fe..0000000000 --- a/UnitsNet.Tests/GeneratedCode/SpecificVolumeTestsBase.g.cs +++ /dev/null @@ -1,234 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of SpecificVolume. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpecificVolumeTestsBase - { - protected abstract double CubicFeetPerPoundInOneCubicMeterPerKilogram { get; } - protected abstract double CubicMetersPerKilogramInOneCubicMeterPerKilogram { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CubicFeetPerPoundTolerance { get { return 1e-5; } } - protected virtual double CubicMetersPerKilogramTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificVolume((double)0.0, SpecificVolumeUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificVolume(double.PositiveInfinity, SpecificVolumeUnit.CubicMeterPerKilogram)); - Assert.Throws(() => new SpecificVolume(double.NegativeInfinity, SpecificVolumeUnit.CubicMeterPerKilogram)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificVolume(double.NaN, SpecificVolumeUnit.CubicMeterPerKilogram)); - } - - [Fact] - public void CubicMeterPerKilogramToSpecificVolumeUnits() - { - SpecificVolume cubicmeterperkilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - AssertEx.EqualTolerance(CubicFeetPerPoundInOneCubicMeterPerKilogram, cubicmeterperkilogram.CubicFeetPerPound, CubicFeetPerPoundTolerance); - AssertEx.EqualTolerance(CubicMetersPerKilogramInOneCubicMeterPerKilogram, cubicmeterperkilogram.CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, SpecificVolume.From(1, SpecificVolumeUnit.CubicFootPerPound).CubicFeetPerPound, CubicFeetPerPoundTolerance); - AssertEx.EqualTolerance(1, SpecificVolume.From(1, SpecificVolumeUnit.CubicMeterPerKilogram).CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - } - - [Fact] - public void FromCubicMetersPerKilogram_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => SpecificVolume.FromCubicMetersPerKilogram(double.PositiveInfinity)); - Assert.Throws(() => SpecificVolume.FromCubicMetersPerKilogram(double.NegativeInfinity)); - } - - [Fact] - public void FromCubicMetersPerKilogram_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => SpecificVolume.FromCubicMetersPerKilogram(double.NaN)); - } - - [Fact] - public void As() - { - var cubicmeterperkilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - AssertEx.EqualTolerance(CubicFeetPerPoundInOneCubicMeterPerKilogram, cubicmeterperkilogram.As(SpecificVolumeUnit.CubicFootPerPound), CubicFeetPerPoundTolerance); - AssertEx.EqualTolerance(CubicMetersPerKilogramInOneCubicMeterPerKilogram, cubicmeterperkilogram.As(SpecificVolumeUnit.CubicMeterPerKilogram), CubicMetersPerKilogramTolerance); - } - - [Fact] - public void ToUnit() - { - var cubicmeterperkilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - - var cubicfootperpoundQuantity = cubicmeterperkilogram.ToUnit(SpecificVolumeUnit.CubicFootPerPound); - AssertEx.EqualTolerance(CubicFeetPerPoundInOneCubicMeterPerKilogram, (double)cubicfootperpoundQuantity.Value, CubicFeetPerPoundTolerance); - Assert.Equal(SpecificVolumeUnit.CubicFootPerPound, cubicfootperpoundQuantity.Unit); - - var cubicmeterperkilogramQuantity = cubicmeterperkilogram.ToUnit(SpecificVolumeUnit.CubicMeterPerKilogram); - AssertEx.EqualTolerance(CubicMetersPerKilogramInOneCubicMeterPerKilogram, (double)cubicmeterperkilogramQuantity.Value, CubicMetersPerKilogramTolerance); - Assert.Equal(SpecificVolumeUnit.CubicMeterPerKilogram, cubicmeterperkilogramQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - SpecificVolume cubicmeterperkilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - AssertEx.EqualTolerance(1, SpecificVolume.FromCubicFeetPerPound(cubicmeterperkilogram.CubicFeetPerPound).CubicMetersPerKilogram, CubicFeetPerPoundTolerance); - AssertEx.EqualTolerance(1, SpecificVolume.FromCubicMetersPerKilogram(cubicmeterperkilogram.CubicMetersPerKilogram).CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - SpecificVolume v = SpecificVolume.FromCubicMetersPerKilogram(1); - AssertEx.EqualTolerance(-1, -v.CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - AssertEx.EqualTolerance(2, (SpecificVolume.FromCubicMetersPerKilogram(3)-v).CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - AssertEx.EqualTolerance(2, (v + v).CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - AssertEx.EqualTolerance(10, (v*10).CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - AssertEx.EqualTolerance(10, (10*v).CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - AssertEx.EqualTolerance(2, (SpecificVolume.FromCubicMetersPerKilogram(10)/5).CubicMetersPerKilogram, CubicMetersPerKilogramTolerance); - AssertEx.EqualTolerance(2, SpecificVolume.FromCubicMetersPerKilogram(10)/SpecificVolume.FromCubicMetersPerKilogram(5), CubicMetersPerKilogramTolerance); - } - - [Fact] - public void ComparisonOperators() - { - SpecificVolume oneCubicMeterPerKilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - SpecificVolume twoCubicMetersPerKilogram = SpecificVolume.FromCubicMetersPerKilogram(2); - - Assert.True(oneCubicMeterPerKilogram < twoCubicMetersPerKilogram); - Assert.True(oneCubicMeterPerKilogram <= twoCubicMetersPerKilogram); - Assert.True(twoCubicMetersPerKilogram > oneCubicMeterPerKilogram); - Assert.True(twoCubicMetersPerKilogram >= oneCubicMeterPerKilogram); - - Assert.False(oneCubicMeterPerKilogram > twoCubicMetersPerKilogram); - Assert.False(oneCubicMeterPerKilogram >= twoCubicMetersPerKilogram); - Assert.False(twoCubicMetersPerKilogram < oneCubicMeterPerKilogram); - Assert.False(twoCubicMetersPerKilogram <= oneCubicMeterPerKilogram); - } - - [Fact] - public void CompareToIsImplemented() - { - SpecificVolume cubicmeterperkilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - Assert.Equal(0, cubicmeterperkilogram.CompareTo(cubicmeterperkilogram)); - Assert.True(cubicmeterperkilogram.CompareTo(SpecificVolume.Zero) > 0); - Assert.True(SpecificVolume.Zero.CompareTo(cubicmeterperkilogram) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - SpecificVolume cubicmeterperkilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - Assert.Throws(() => cubicmeterperkilogram.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - SpecificVolume cubicmeterperkilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - Assert.Throws(() => cubicmeterperkilogram.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - SpecificVolume v = SpecificVolume.FromCubicMetersPerKilogram(1); - Assert.True(v.Equals(SpecificVolume.FromCubicMetersPerKilogram(1), CubicMetersPerKilogramTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(SpecificVolume.Zero, CubicMetersPerKilogramTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - SpecificVolume cubicmeterperkilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - Assert.False(cubicmeterperkilogram.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - SpecificVolume cubicmeterperkilogram = SpecificVolume.FromCubicMetersPerKilogram(1); - Assert.False(cubicmeterperkilogram.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(SpecificVolumeUnit.Undefined, SpecificVolume.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(SpecificVolumeUnit)).Cast(); - foreach(var unit in units) - { - if(unit == SpecificVolumeUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/SpecificWeightTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/SpecificWeightTestsBase.g.cs deleted file mode 100644 index c2191684bf..0000000000 --- a/UnitsNet.Tests/GeneratedCode/SpecificWeightTestsBase.g.cs +++ /dev/null @@ -1,384 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of SpecificWeight. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpecificWeightTestsBase - { - protected abstract double KilogramsForcePerCubicCentimeterInOneNewtonPerCubicMeter { get; } - protected abstract double KilogramsForcePerCubicMeterInOneNewtonPerCubicMeter { get; } - protected abstract double KilogramsForcePerCubicMillimeterInOneNewtonPerCubicMeter { get; } - protected abstract double KilonewtonsPerCubicCentimeterInOneNewtonPerCubicMeter { get; } - protected abstract double KilonewtonsPerCubicMeterInOneNewtonPerCubicMeter { get; } - protected abstract double KilonewtonsPerCubicMillimeterInOneNewtonPerCubicMeter { get; } - protected abstract double KilopoundsForcePerCubicFootInOneNewtonPerCubicMeter { get; } - protected abstract double KilopoundsForcePerCubicInchInOneNewtonPerCubicMeter { get; } - protected abstract double MeganewtonsPerCubicMeterInOneNewtonPerCubicMeter { get; } - protected abstract double NewtonsPerCubicCentimeterInOneNewtonPerCubicMeter { get; } - protected abstract double NewtonsPerCubicMeterInOneNewtonPerCubicMeter { get; } - protected abstract double NewtonsPerCubicMillimeterInOneNewtonPerCubicMeter { get; } - protected abstract double PoundsForcePerCubicFootInOneNewtonPerCubicMeter { get; } - protected abstract double PoundsForcePerCubicInchInOneNewtonPerCubicMeter { get; } - protected abstract double TonnesForcePerCubicCentimeterInOneNewtonPerCubicMeter { get; } - protected abstract double TonnesForcePerCubicMeterInOneNewtonPerCubicMeter { get; } - protected abstract double TonnesForcePerCubicMillimeterInOneNewtonPerCubicMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilogramsForcePerCubicCentimeterTolerance { get { return 1e-5; } } - protected virtual double KilogramsForcePerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double KilogramsForcePerCubicMillimeterTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsPerCubicCentimeterTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double KilonewtonsPerCubicMillimeterTolerance { get { return 1e-5; } } - protected virtual double KilopoundsForcePerCubicFootTolerance { get { return 1e-5; } } - protected virtual double KilopoundsForcePerCubicInchTolerance { get { return 1e-5; } } - protected virtual double MeganewtonsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double NewtonsPerCubicCentimeterTolerance { get { return 1e-5; } } - protected virtual double NewtonsPerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double NewtonsPerCubicMillimeterTolerance { get { return 1e-5; } } - protected virtual double PoundsForcePerCubicFootTolerance { get { return 1e-5; } } - protected virtual double PoundsForcePerCubicInchTolerance { get { return 1e-5; } } - protected virtual double TonnesForcePerCubicCentimeterTolerance { get { return 1e-5; } } - protected virtual double TonnesForcePerCubicMeterTolerance { get { return 1e-5; } } - protected virtual double TonnesForcePerCubicMillimeterTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificWeight((double)0.0, SpecificWeightUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificWeight(double.PositiveInfinity, SpecificWeightUnit.NewtonPerCubicMeter)); - Assert.Throws(() => new SpecificWeight(double.NegativeInfinity, SpecificWeightUnit.NewtonPerCubicMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new SpecificWeight(double.NaN, SpecificWeightUnit.NewtonPerCubicMeter)); - } - - [Fact] - public void NewtonPerCubicMeterToSpecificWeightUnits() - { - SpecificWeight newtonpercubicmeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - AssertEx.EqualTolerance(KilogramsForcePerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.KilogramsForcePerCubicCentimeter, KilogramsForcePerCubicCentimeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.KilogramsForcePerCubicMeter, KilogramsForcePerCubicMeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.KilogramsForcePerCubicMillimeter, KilogramsForcePerCubicMillimeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.KilonewtonsPerCubicCentimeter, KilonewtonsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.KilonewtonsPerCubicMeter, KilonewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.KilonewtonsPerCubicMillimeter, KilonewtonsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(KilopoundsForcePerCubicFootInOneNewtonPerCubicMeter, newtonpercubicmeter.KilopoundsForcePerCubicFoot, KilopoundsForcePerCubicFootTolerance); - AssertEx.EqualTolerance(KilopoundsForcePerCubicInchInOneNewtonPerCubicMeter, newtonpercubicmeter.KilopoundsForcePerCubicInch, KilopoundsForcePerCubicInchTolerance); - AssertEx.EqualTolerance(MeganewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.MeganewtonsPerCubicMeter, MeganewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(NewtonsPerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.NewtonsPerCubicCentimeter, NewtonsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(NewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(NewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.NewtonsPerCubicMillimeter, NewtonsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(PoundsForcePerCubicFootInOneNewtonPerCubicMeter, newtonpercubicmeter.PoundsForcePerCubicFoot, PoundsForcePerCubicFootTolerance); - AssertEx.EqualTolerance(PoundsForcePerCubicInchInOneNewtonPerCubicMeter, newtonpercubicmeter.PoundsForcePerCubicInch, PoundsForcePerCubicInchTolerance); - AssertEx.EqualTolerance(TonnesForcePerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.TonnesForcePerCubicCentimeter, TonnesForcePerCubicCentimeterTolerance); - AssertEx.EqualTolerance(TonnesForcePerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.TonnesForcePerCubicMeter, TonnesForcePerCubicMeterTolerance); - AssertEx.EqualTolerance(TonnesForcePerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.TonnesForcePerCubicMillimeter, TonnesForcePerCubicMillimeterTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilogramForcePerCubicCentimeter).KilogramsForcePerCubicCentimeter, KilogramsForcePerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilogramForcePerCubicMeter).KilogramsForcePerCubicMeter, KilogramsForcePerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilogramForcePerCubicMillimeter).KilogramsForcePerCubicMillimeter, KilogramsForcePerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilonewtonPerCubicCentimeter).KilonewtonsPerCubicCentimeter, KilonewtonsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilonewtonPerCubicMeter).KilonewtonsPerCubicMeter, KilonewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilonewtonPerCubicMillimeter).KilonewtonsPerCubicMillimeter, KilonewtonsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilopoundForcePerCubicFoot).KilopoundsForcePerCubicFoot, KilopoundsForcePerCubicFootTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilopoundForcePerCubicInch).KilopoundsForcePerCubicInch, KilopoundsForcePerCubicInchTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.MeganewtonPerCubicMeter).MeganewtonsPerCubicMeter, MeganewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.NewtonPerCubicCentimeter).NewtonsPerCubicCentimeter, NewtonsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.NewtonPerCubicMeter).NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.NewtonPerCubicMillimeter).NewtonsPerCubicMillimeter, NewtonsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.PoundForcePerCubicFoot).PoundsForcePerCubicFoot, PoundsForcePerCubicFootTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.PoundForcePerCubicInch).PoundsForcePerCubicInch, PoundsForcePerCubicInchTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.TonneForcePerCubicCentimeter).TonnesForcePerCubicCentimeter, TonnesForcePerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.TonneForcePerCubicMeter).TonnesForcePerCubicMeter, TonnesForcePerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.TonneForcePerCubicMillimeter).TonnesForcePerCubicMillimeter, TonnesForcePerCubicMillimeterTolerance); - } - - [Fact] - public void FromNewtonsPerCubicMeter_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => SpecificWeight.FromNewtonsPerCubicMeter(double.PositiveInfinity)); - Assert.Throws(() => SpecificWeight.FromNewtonsPerCubicMeter(double.NegativeInfinity)); - } - - [Fact] - public void FromNewtonsPerCubicMeter_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => SpecificWeight.FromNewtonsPerCubicMeter(double.NaN)); - } - - [Fact] - public void As() - { - var newtonpercubicmeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - AssertEx.EqualTolerance(KilogramsForcePerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilogramForcePerCubicCentimeter), KilogramsForcePerCubicCentimeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilogramForcePerCubicMeter), KilogramsForcePerCubicMeterTolerance); - AssertEx.EqualTolerance(KilogramsForcePerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilogramForcePerCubicMillimeter), KilogramsForcePerCubicMillimeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilonewtonPerCubicCentimeter), KilonewtonsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilonewtonPerCubicMeter), KilonewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(KilonewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilonewtonPerCubicMillimeter), KilonewtonsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(KilopoundsForcePerCubicFootInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilopoundForcePerCubicFoot), KilopoundsForcePerCubicFootTolerance); - AssertEx.EqualTolerance(KilopoundsForcePerCubicInchInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilopoundForcePerCubicInch), KilopoundsForcePerCubicInchTolerance); - AssertEx.EqualTolerance(MeganewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.MeganewtonPerCubicMeter), MeganewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(NewtonsPerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.NewtonPerCubicCentimeter), NewtonsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(NewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.NewtonPerCubicMeter), NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(NewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.NewtonPerCubicMillimeter), NewtonsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(PoundsForcePerCubicFootInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.PoundForcePerCubicFoot), PoundsForcePerCubicFootTolerance); - AssertEx.EqualTolerance(PoundsForcePerCubicInchInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.PoundForcePerCubicInch), PoundsForcePerCubicInchTolerance); - AssertEx.EqualTolerance(TonnesForcePerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.TonneForcePerCubicCentimeter), TonnesForcePerCubicCentimeterTolerance); - AssertEx.EqualTolerance(TonnesForcePerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.TonneForcePerCubicMeter), TonnesForcePerCubicMeterTolerance); - AssertEx.EqualTolerance(TonnesForcePerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.TonneForcePerCubicMillimeter), TonnesForcePerCubicMillimeterTolerance); - } - - [Fact] - public void ToUnit() - { - var newtonpercubicmeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - - var kilogramforcepercubiccentimeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.KilogramForcePerCubicCentimeter); - AssertEx.EqualTolerance(KilogramsForcePerCubicCentimeterInOneNewtonPerCubicMeter, (double)kilogramforcepercubiccentimeterQuantity.Value, KilogramsForcePerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicCentimeter, kilogramforcepercubiccentimeterQuantity.Unit); - - var kilogramforcepercubicmeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.KilogramForcePerCubicMeter); - AssertEx.EqualTolerance(KilogramsForcePerCubicMeterInOneNewtonPerCubicMeter, (double)kilogramforcepercubicmeterQuantity.Value, KilogramsForcePerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMeter, kilogramforcepercubicmeterQuantity.Unit); - - var kilogramforcepercubicmillimeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.KilogramForcePerCubicMillimeter); - AssertEx.EqualTolerance(KilogramsForcePerCubicMillimeterInOneNewtonPerCubicMeter, (double)kilogramforcepercubicmillimeterQuantity.Value, KilogramsForcePerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMillimeter, kilogramforcepercubicmillimeterQuantity.Unit); - - var kilonewtonpercubiccentimeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.KilonewtonPerCubicCentimeter); - AssertEx.EqualTolerance(KilonewtonsPerCubicCentimeterInOneNewtonPerCubicMeter, (double)kilonewtonpercubiccentimeterQuantity.Value, KilonewtonsPerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicCentimeter, kilonewtonpercubiccentimeterQuantity.Unit); - - var kilonewtonpercubicmeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.KilonewtonPerCubicMeter); - AssertEx.EqualTolerance(KilonewtonsPerCubicMeterInOneNewtonPerCubicMeter, (double)kilonewtonpercubicmeterQuantity.Value, KilonewtonsPerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMeter, kilonewtonpercubicmeterQuantity.Unit); - - var kilonewtonpercubicmillimeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.KilonewtonPerCubicMillimeter); - AssertEx.EqualTolerance(KilonewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, (double)kilonewtonpercubicmillimeterQuantity.Value, KilonewtonsPerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMillimeter, kilonewtonpercubicmillimeterQuantity.Unit); - - var kilopoundforcepercubicfootQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.KilopoundForcePerCubicFoot); - AssertEx.EqualTolerance(KilopoundsForcePerCubicFootInOneNewtonPerCubicMeter, (double)kilopoundforcepercubicfootQuantity.Value, KilopoundsForcePerCubicFootTolerance); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicFoot, kilopoundforcepercubicfootQuantity.Unit); - - var kilopoundforcepercubicinchQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.KilopoundForcePerCubicInch); - AssertEx.EqualTolerance(KilopoundsForcePerCubicInchInOneNewtonPerCubicMeter, (double)kilopoundforcepercubicinchQuantity.Value, KilopoundsForcePerCubicInchTolerance); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicInch, kilopoundforcepercubicinchQuantity.Unit); - - var meganewtonpercubicmeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.MeganewtonPerCubicMeter); - AssertEx.EqualTolerance(MeganewtonsPerCubicMeterInOneNewtonPerCubicMeter, (double)meganewtonpercubicmeterQuantity.Value, MeganewtonsPerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.MeganewtonPerCubicMeter, meganewtonpercubicmeterQuantity.Unit); - - var newtonpercubiccentimeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.NewtonPerCubicCentimeter); - AssertEx.EqualTolerance(NewtonsPerCubicCentimeterInOneNewtonPerCubicMeter, (double)newtonpercubiccentimeterQuantity.Value, NewtonsPerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicCentimeter, newtonpercubiccentimeterQuantity.Unit); - - var newtonpercubicmeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.NewtonPerCubicMeter); - AssertEx.EqualTolerance(NewtonsPerCubicMeterInOneNewtonPerCubicMeter, (double)newtonpercubicmeterQuantity.Value, NewtonsPerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMeter, newtonpercubicmeterQuantity.Unit); - - var newtonpercubicmillimeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.NewtonPerCubicMillimeter); - AssertEx.EqualTolerance(NewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, (double)newtonpercubicmillimeterQuantity.Value, NewtonsPerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMillimeter, newtonpercubicmillimeterQuantity.Unit); - - var poundforcepercubicfootQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.PoundForcePerCubicFoot); - AssertEx.EqualTolerance(PoundsForcePerCubicFootInOneNewtonPerCubicMeter, (double)poundforcepercubicfootQuantity.Value, PoundsForcePerCubicFootTolerance); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicFoot, poundforcepercubicfootQuantity.Unit); - - var poundforcepercubicinchQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.PoundForcePerCubicInch); - AssertEx.EqualTolerance(PoundsForcePerCubicInchInOneNewtonPerCubicMeter, (double)poundforcepercubicinchQuantity.Value, PoundsForcePerCubicInchTolerance); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicInch, poundforcepercubicinchQuantity.Unit); - - var tonneforcepercubiccentimeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.TonneForcePerCubicCentimeter); - AssertEx.EqualTolerance(TonnesForcePerCubicCentimeterInOneNewtonPerCubicMeter, (double)tonneforcepercubiccentimeterQuantity.Value, TonnesForcePerCubicCentimeterTolerance); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicCentimeter, tonneforcepercubiccentimeterQuantity.Unit); - - var tonneforcepercubicmeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.TonneForcePerCubicMeter); - AssertEx.EqualTolerance(TonnesForcePerCubicMeterInOneNewtonPerCubicMeter, (double)tonneforcepercubicmeterQuantity.Value, TonnesForcePerCubicMeterTolerance); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMeter, tonneforcepercubicmeterQuantity.Unit); - - var tonneforcepercubicmillimeterQuantity = newtonpercubicmeter.ToUnit(SpecificWeightUnit.TonneForcePerCubicMillimeter); - AssertEx.EqualTolerance(TonnesForcePerCubicMillimeterInOneNewtonPerCubicMeter, (double)tonneforcepercubicmillimeterQuantity.Value, TonnesForcePerCubicMillimeterTolerance); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMillimeter, tonneforcepercubicmillimeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - SpecificWeight newtonpercubicmeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - AssertEx.EqualTolerance(1, SpecificWeight.FromKilogramsForcePerCubicCentimeter(newtonpercubicmeter.KilogramsForcePerCubicCentimeter).NewtonsPerCubicMeter, KilogramsForcePerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromKilogramsForcePerCubicMeter(newtonpercubicmeter.KilogramsForcePerCubicMeter).NewtonsPerCubicMeter, KilogramsForcePerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromKilogramsForcePerCubicMillimeter(newtonpercubicmeter.KilogramsForcePerCubicMillimeter).NewtonsPerCubicMeter, KilogramsForcePerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromKilonewtonsPerCubicCentimeter(newtonpercubicmeter.KilonewtonsPerCubicCentimeter).NewtonsPerCubicMeter, KilonewtonsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromKilonewtonsPerCubicMeter(newtonpercubicmeter.KilonewtonsPerCubicMeter).NewtonsPerCubicMeter, KilonewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromKilonewtonsPerCubicMillimeter(newtonpercubicmeter.KilonewtonsPerCubicMillimeter).NewtonsPerCubicMeter, KilonewtonsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromKilopoundsForcePerCubicFoot(newtonpercubicmeter.KilopoundsForcePerCubicFoot).NewtonsPerCubicMeter, KilopoundsForcePerCubicFootTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromKilopoundsForcePerCubicInch(newtonpercubicmeter.KilopoundsForcePerCubicInch).NewtonsPerCubicMeter, KilopoundsForcePerCubicInchTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromMeganewtonsPerCubicMeter(newtonpercubicmeter.MeganewtonsPerCubicMeter).NewtonsPerCubicMeter, MeganewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromNewtonsPerCubicCentimeter(newtonpercubicmeter.NewtonsPerCubicCentimeter).NewtonsPerCubicMeter, NewtonsPerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromNewtonsPerCubicMeter(newtonpercubicmeter.NewtonsPerCubicMeter).NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromNewtonsPerCubicMillimeter(newtonpercubicmeter.NewtonsPerCubicMillimeter).NewtonsPerCubicMeter, NewtonsPerCubicMillimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromPoundsForcePerCubicFoot(newtonpercubicmeter.PoundsForcePerCubicFoot).NewtonsPerCubicMeter, PoundsForcePerCubicFootTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromPoundsForcePerCubicInch(newtonpercubicmeter.PoundsForcePerCubicInch).NewtonsPerCubicMeter, PoundsForcePerCubicInchTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromTonnesForcePerCubicCentimeter(newtonpercubicmeter.TonnesForcePerCubicCentimeter).NewtonsPerCubicMeter, TonnesForcePerCubicCentimeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromTonnesForcePerCubicMeter(newtonpercubicmeter.TonnesForcePerCubicMeter).NewtonsPerCubicMeter, TonnesForcePerCubicMeterTolerance); - AssertEx.EqualTolerance(1, SpecificWeight.FromTonnesForcePerCubicMillimeter(newtonpercubicmeter.TonnesForcePerCubicMillimeter).NewtonsPerCubicMeter, TonnesForcePerCubicMillimeterTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - SpecificWeight v = SpecificWeight.FromNewtonsPerCubicMeter(1); - AssertEx.EqualTolerance(-1, -v.NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (SpecificWeight.FromNewtonsPerCubicMeter(3)-v).NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (v + v).NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (v*10).NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(10, (10*v).NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, (SpecificWeight.FromNewtonsPerCubicMeter(10)/5).NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance); - AssertEx.EqualTolerance(2, SpecificWeight.FromNewtonsPerCubicMeter(10)/SpecificWeight.FromNewtonsPerCubicMeter(5), NewtonsPerCubicMeterTolerance); - } - - [Fact] - public void ComparisonOperators() - { - SpecificWeight oneNewtonPerCubicMeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - SpecificWeight twoNewtonsPerCubicMeter = SpecificWeight.FromNewtonsPerCubicMeter(2); - - Assert.True(oneNewtonPerCubicMeter < twoNewtonsPerCubicMeter); - Assert.True(oneNewtonPerCubicMeter <= twoNewtonsPerCubicMeter); - Assert.True(twoNewtonsPerCubicMeter > oneNewtonPerCubicMeter); - Assert.True(twoNewtonsPerCubicMeter >= oneNewtonPerCubicMeter); - - Assert.False(oneNewtonPerCubicMeter > twoNewtonsPerCubicMeter); - Assert.False(oneNewtonPerCubicMeter >= twoNewtonsPerCubicMeter); - Assert.False(twoNewtonsPerCubicMeter < oneNewtonPerCubicMeter); - Assert.False(twoNewtonsPerCubicMeter <= oneNewtonPerCubicMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - SpecificWeight newtonpercubicmeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - Assert.Equal(0, newtonpercubicmeter.CompareTo(newtonpercubicmeter)); - Assert.True(newtonpercubicmeter.CompareTo(SpecificWeight.Zero) > 0); - Assert.True(SpecificWeight.Zero.CompareTo(newtonpercubicmeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - SpecificWeight newtonpercubicmeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - Assert.Throws(() => newtonpercubicmeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - SpecificWeight newtonpercubicmeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - Assert.Throws(() => newtonpercubicmeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - SpecificWeight v = SpecificWeight.FromNewtonsPerCubicMeter(1); - Assert.True(v.Equals(SpecificWeight.FromNewtonsPerCubicMeter(1), NewtonsPerCubicMeterTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(SpecificWeight.Zero, NewtonsPerCubicMeterTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - SpecificWeight newtonpercubicmeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - Assert.False(newtonpercubicmeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - SpecificWeight newtonpercubicmeter = SpecificWeight.FromNewtonsPerCubicMeter(1); - Assert.False(newtonpercubicmeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(SpecificWeightUnit.Undefined, SpecificWeight.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(SpecificWeightUnit)).Cast(); - foreach(var unit in units) - { - if(unit == SpecificWeightUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/SpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/SpeedTestsBase.g.cs deleted file mode 100644 index d9b733b984..0000000000 --- a/UnitsNet.Tests/GeneratedCode/SpeedTestsBase.g.cs +++ /dev/null @@ -1,534 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Speed. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpeedTestsBase - { - protected abstract double CentimetersPerHourInOneMeterPerSecond { get; } - protected abstract double CentimetersPerMinutesInOneMeterPerSecond { get; } - protected abstract double CentimetersPerSecondInOneMeterPerSecond { get; } - protected abstract double DecimetersPerMinutesInOneMeterPerSecond { get; } - protected abstract double DecimetersPerSecondInOneMeterPerSecond { get; } - protected abstract double FeetPerHourInOneMeterPerSecond { get; } - protected abstract double FeetPerMinuteInOneMeterPerSecond { get; } - protected abstract double FeetPerSecondInOneMeterPerSecond { get; } - protected abstract double InchesPerHourInOneMeterPerSecond { get; } - protected abstract double InchesPerMinuteInOneMeterPerSecond { get; } - protected abstract double InchesPerSecondInOneMeterPerSecond { get; } - protected abstract double KilometersPerHourInOneMeterPerSecond { get; } - protected abstract double KilometersPerMinutesInOneMeterPerSecond { get; } - protected abstract double KilometersPerSecondInOneMeterPerSecond { get; } - protected abstract double KnotsInOneMeterPerSecond { get; } - protected abstract double MetersPerHourInOneMeterPerSecond { get; } - protected abstract double MetersPerMinutesInOneMeterPerSecond { get; } - protected abstract double MetersPerSecondInOneMeterPerSecond { get; } - protected abstract double MicrometersPerMinutesInOneMeterPerSecond { get; } - protected abstract double MicrometersPerSecondInOneMeterPerSecond { get; } - protected abstract double MilesPerHourInOneMeterPerSecond { get; } - protected abstract double MillimetersPerHourInOneMeterPerSecond { get; } - protected abstract double MillimetersPerMinutesInOneMeterPerSecond { get; } - protected abstract double MillimetersPerSecondInOneMeterPerSecond { get; } - protected abstract double NanometersPerMinutesInOneMeterPerSecond { get; } - protected abstract double NanometersPerSecondInOneMeterPerSecond { get; } - protected abstract double UsSurveyFeetPerHourInOneMeterPerSecond { get; } - protected abstract double UsSurveyFeetPerMinuteInOneMeterPerSecond { get; } - protected abstract double UsSurveyFeetPerSecondInOneMeterPerSecond { get; } - protected abstract double YardsPerHourInOneMeterPerSecond { get; } - protected abstract double YardsPerMinuteInOneMeterPerSecond { get; } - protected abstract double YardsPerSecondInOneMeterPerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentimetersPerHourTolerance { get { return 1e-5; } } - protected virtual double CentimetersPerMinutesTolerance { get { return 1e-5; } } - protected virtual double CentimetersPerSecondTolerance { get { return 1e-5; } } - protected virtual double DecimetersPerMinutesTolerance { get { return 1e-5; } } - protected virtual double DecimetersPerSecondTolerance { get { return 1e-5; } } - protected virtual double FeetPerHourTolerance { get { return 1e-5; } } - protected virtual double FeetPerMinuteTolerance { get { return 1e-5; } } - protected virtual double FeetPerSecondTolerance { get { return 1e-5; } } - protected virtual double InchesPerHourTolerance { get { return 1e-5; } } - protected virtual double InchesPerMinuteTolerance { get { return 1e-5; } } - protected virtual double InchesPerSecondTolerance { get { return 1e-5; } } - protected virtual double KilometersPerHourTolerance { get { return 1e-5; } } - protected virtual double KilometersPerMinutesTolerance { get { return 1e-5; } } - protected virtual double KilometersPerSecondTolerance { get { return 1e-5; } } - protected virtual double KnotsTolerance { get { return 1e-5; } } - protected virtual double MetersPerHourTolerance { get { return 1e-5; } } - protected virtual double MetersPerMinutesTolerance { get { return 1e-5; } } - protected virtual double MetersPerSecondTolerance { get { return 1e-5; } } - protected virtual double MicrometersPerMinutesTolerance { get { return 1e-5; } } - protected virtual double MicrometersPerSecondTolerance { get { return 1e-5; } } - protected virtual double MilesPerHourTolerance { get { return 1e-5; } } - protected virtual double MillimetersPerHourTolerance { get { return 1e-5; } } - protected virtual double MillimetersPerMinutesTolerance { get { return 1e-5; } } - protected virtual double MillimetersPerSecondTolerance { get { return 1e-5; } } - protected virtual double NanometersPerMinutesTolerance { get { return 1e-5; } } - protected virtual double NanometersPerSecondTolerance { get { return 1e-5; } } - protected virtual double UsSurveyFeetPerHourTolerance { get { return 1e-5; } } - protected virtual double UsSurveyFeetPerMinuteTolerance { get { return 1e-5; } } - protected virtual double UsSurveyFeetPerSecondTolerance { get { return 1e-5; } } - protected virtual double YardsPerHourTolerance { get { return 1e-5; } } - protected virtual double YardsPerMinuteTolerance { get { return 1e-5; } } - protected virtual double YardsPerSecondTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Speed((double)0.0, SpeedUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Speed(double.PositiveInfinity, SpeedUnit.MeterPerSecond)); - Assert.Throws(() => new Speed(double.NegativeInfinity, SpeedUnit.MeterPerSecond)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Speed(double.NaN, SpeedUnit.MeterPerSecond)); - } - - [Fact] - public void MeterPerSecondToSpeedUnits() - { - Speed meterpersecond = Speed.FromMetersPerSecond(1); - AssertEx.EqualTolerance(CentimetersPerHourInOneMeterPerSecond, meterpersecond.CentimetersPerHour, CentimetersPerHourTolerance); - AssertEx.EqualTolerance(CentimetersPerMinutesInOneMeterPerSecond, meterpersecond.CentimetersPerMinutes, CentimetersPerMinutesTolerance); - AssertEx.EqualTolerance(CentimetersPerSecondInOneMeterPerSecond, meterpersecond.CentimetersPerSecond, CentimetersPerSecondTolerance); - AssertEx.EqualTolerance(DecimetersPerMinutesInOneMeterPerSecond, meterpersecond.DecimetersPerMinutes, DecimetersPerMinutesTolerance); - AssertEx.EqualTolerance(DecimetersPerSecondInOneMeterPerSecond, meterpersecond.DecimetersPerSecond, DecimetersPerSecondTolerance); - AssertEx.EqualTolerance(FeetPerHourInOneMeterPerSecond, meterpersecond.FeetPerHour, FeetPerHourTolerance); - AssertEx.EqualTolerance(FeetPerMinuteInOneMeterPerSecond, meterpersecond.FeetPerMinute, FeetPerMinuteTolerance); - AssertEx.EqualTolerance(FeetPerSecondInOneMeterPerSecond, meterpersecond.FeetPerSecond, FeetPerSecondTolerance); - AssertEx.EqualTolerance(InchesPerHourInOneMeterPerSecond, meterpersecond.InchesPerHour, InchesPerHourTolerance); - AssertEx.EqualTolerance(InchesPerMinuteInOneMeterPerSecond, meterpersecond.InchesPerMinute, InchesPerMinuteTolerance); - AssertEx.EqualTolerance(InchesPerSecondInOneMeterPerSecond, meterpersecond.InchesPerSecond, InchesPerSecondTolerance); - AssertEx.EqualTolerance(KilometersPerHourInOneMeterPerSecond, meterpersecond.KilometersPerHour, KilometersPerHourTolerance); - AssertEx.EqualTolerance(KilometersPerMinutesInOneMeterPerSecond, meterpersecond.KilometersPerMinutes, KilometersPerMinutesTolerance); - AssertEx.EqualTolerance(KilometersPerSecondInOneMeterPerSecond, meterpersecond.KilometersPerSecond, KilometersPerSecondTolerance); - AssertEx.EqualTolerance(KnotsInOneMeterPerSecond, meterpersecond.Knots, KnotsTolerance); - AssertEx.EqualTolerance(MetersPerHourInOneMeterPerSecond, meterpersecond.MetersPerHour, MetersPerHourTolerance); - AssertEx.EqualTolerance(MetersPerMinutesInOneMeterPerSecond, meterpersecond.MetersPerMinutes, MetersPerMinutesTolerance); - AssertEx.EqualTolerance(MetersPerSecondInOneMeterPerSecond, meterpersecond.MetersPerSecond, MetersPerSecondTolerance); - AssertEx.EqualTolerance(MicrometersPerMinutesInOneMeterPerSecond, meterpersecond.MicrometersPerMinutes, MicrometersPerMinutesTolerance); - AssertEx.EqualTolerance(MicrometersPerSecondInOneMeterPerSecond, meterpersecond.MicrometersPerSecond, MicrometersPerSecondTolerance); - AssertEx.EqualTolerance(MilesPerHourInOneMeterPerSecond, meterpersecond.MilesPerHour, MilesPerHourTolerance); - AssertEx.EqualTolerance(MillimetersPerHourInOneMeterPerSecond, meterpersecond.MillimetersPerHour, MillimetersPerHourTolerance); - AssertEx.EqualTolerance(MillimetersPerMinutesInOneMeterPerSecond, meterpersecond.MillimetersPerMinutes, MillimetersPerMinutesTolerance); - AssertEx.EqualTolerance(MillimetersPerSecondInOneMeterPerSecond, meterpersecond.MillimetersPerSecond, MillimetersPerSecondTolerance); - AssertEx.EqualTolerance(NanometersPerMinutesInOneMeterPerSecond, meterpersecond.NanometersPerMinutes, NanometersPerMinutesTolerance); - AssertEx.EqualTolerance(NanometersPerSecondInOneMeterPerSecond, meterpersecond.NanometersPerSecond, NanometersPerSecondTolerance); - AssertEx.EqualTolerance(UsSurveyFeetPerHourInOneMeterPerSecond, meterpersecond.UsSurveyFeetPerHour, UsSurveyFeetPerHourTolerance); - AssertEx.EqualTolerance(UsSurveyFeetPerMinuteInOneMeterPerSecond, meterpersecond.UsSurveyFeetPerMinute, UsSurveyFeetPerMinuteTolerance); - AssertEx.EqualTolerance(UsSurveyFeetPerSecondInOneMeterPerSecond, meterpersecond.UsSurveyFeetPerSecond, UsSurveyFeetPerSecondTolerance); - AssertEx.EqualTolerance(YardsPerHourInOneMeterPerSecond, meterpersecond.YardsPerHour, YardsPerHourTolerance); - AssertEx.EqualTolerance(YardsPerMinuteInOneMeterPerSecond, meterpersecond.YardsPerMinute, YardsPerMinuteTolerance); - AssertEx.EqualTolerance(YardsPerSecondInOneMeterPerSecond, meterpersecond.YardsPerSecond, YardsPerSecondTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.CentimeterPerHour).CentimetersPerHour, CentimetersPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.CentimeterPerMinute).CentimetersPerMinutes, CentimetersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.CentimeterPerSecond).CentimetersPerSecond, CentimetersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.DecimeterPerMinute).DecimetersPerMinutes, DecimetersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.DecimeterPerSecond).DecimetersPerSecond, DecimetersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.FootPerHour).FeetPerHour, FeetPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.FootPerMinute).FeetPerMinute, FeetPerMinuteTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.FootPerSecond).FeetPerSecond, FeetPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.InchPerHour).InchesPerHour, InchesPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.InchPerMinute).InchesPerMinute, InchesPerMinuteTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.InchPerSecond).InchesPerSecond, InchesPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.KilometerPerHour).KilometersPerHour, KilometersPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.KilometerPerMinute).KilometersPerMinutes, KilometersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.KilometerPerSecond).KilometersPerSecond, KilometersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.Knot).Knots, KnotsTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.MeterPerHour).MetersPerHour, MetersPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.MeterPerMinute).MetersPerMinutes, MetersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.MeterPerSecond).MetersPerSecond, MetersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.MicrometerPerMinute).MicrometersPerMinutes, MicrometersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.MicrometerPerSecond).MicrometersPerSecond, MicrometersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.MilePerHour).MilesPerHour, MilesPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.MillimeterPerHour).MillimetersPerHour, MillimetersPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.MillimeterPerMinute).MillimetersPerMinutes, MillimetersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.MillimeterPerSecond).MillimetersPerSecond, MillimetersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.NanometerPerMinute).NanometersPerMinutes, NanometersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.NanometerPerSecond).NanometersPerSecond, NanometersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.UsSurveyFootPerHour).UsSurveyFeetPerHour, UsSurveyFeetPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.UsSurveyFootPerMinute).UsSurveyFeetPerMinute, UsSurveyFeetPerMinuteTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.UsSurveyFootPerSecond).UsSurveyFeetPerSecond, UsSurveyFeetPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.YardPerHour).YardsPerHour, YardsPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.YardPerMinute).YardsPerMinute, YardsPerMinuteTolerance); - AssertEx.EqualTolerance(1, Speed.From(1, SpeedUnit.YardPerSecond).YardsPerSecond, YardsPerSecondTolerance); - } - - [Fact] - public void FromMetersPerSecond_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Speed.FromMetersPerSecond(double.PositiveInfinity)); - Assert.Throws(() => Speed.FromMetersPerSecond(double.NegativeInfinity)); - } - - [Fact] - public void FromMetersPerSecond_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Speed.FromMetersPerSecond(double.NaN)); - } - - [Fact] - public void As() - { - var meterpersecond = Speed.FromMetersPerSecond(1); - AssertEx.EqualTolerance(CentimetersPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.CentimeterPerHour), CentimetersPerHourTolerance); - AssertEx.EqualTolerance(CentimetersPerMinutesInOneMeterPerSecond, meterpersecond.As(SpeedUnit.CentimeterPerMinute), CentimetersPerMinutesTolerance); - AssertEx.EqualTolerance(CentimetersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.CentimeterPerSecond), CentimetersPerSecondTolerance); - AssertEx.EqualTolerance(DecimetersPerMinutesInOneMeterPerSecond, meterpersecond.As(SpeedUnit.DecimeterPerMinute), DecimetersPerMinutesTolerance); - AssertEx.EqualTolerance(DecimetersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.DecimeterPerSecond), DecimetersPerSecondTolerance); - AssertEx.EqualTolerance(FeetPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.FootPerHour), FeetPerHourTolerance); - AssertEx.EqualTolerance(FeetPerMinuteInOneMeterPerSecond, meterpersecond.As(SpeedUnit.FootPerMinute), FeetPerMinuteTolerance); - AssertEx.EqualTolerance(FeetPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.FootPerSecond), FeetPerSecondTolerance); - AssertEx.EqualTolerance(InchesPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.InchPerHour), InchesPerHourTolerance); - AssertEx.EqualTolerance(InchesPerMinuteInOneMeterPerSecond, meterpersecond.As(SpeedUnit.InchPerMinute), InchesPerMinuteTolerance); - AssertEx.EqualTolerance(InchesPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.InchPerSecond), InchesPerSecondTolerance); - AssertEx.EqualTolerance(KilometersPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.KilometerPerHour), KilometersPerHourTolerance); - AssertEx.EqualTolerance(KilometersPerMinutesInOneMeterPerSecond, meterpersecond.As(SpeedUnit.KilometerPerMinute), KilometersPerMinutesTolerance); - AssertEx.EqualTolerance(KilometersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.KilometerPerSecond), KilometersPerSecondTolerance); - AssertEx.EqualTolerance(KnotsInOneMeterPerSecond, meterpersecond.As(SpeedUnit.Knot), KnotsTolerance); - AssertEx.EqualTolerance(MetersPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MeterPerHour), MetersPerHourTolerance); - AssertEx.EqualTolerance(MetersPerMinutesInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MeterPerMinute), MetersPerMinutesTolerance); - AssertEx.EqualTolerance(MetersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MeterPerSecond), MetersPerSecondTolerance); - AssertEx.EqualTolerance(MicrometersPerMinutesInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MicrometerPerMinute), MicrometersPerMinutesTolerance); - AssertEx.EqualTolerance(MicrometersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MicrometerPerSecond), MicrometersPerSecondTolerance); - AssertEx.EqualTolerance(MilesPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MilePerHour), MilesPerHourTolerance); - AssertEx.EqualTolerance(MillimetersPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MillimeterPerHour), MillimetersPerHourTolerance); - AssertEx.EqualTolerance(MillimetersPerMinutesInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MillimeterPerMinute), MillimetersPerMinutesTolerance); - AssertEx.EqualTolerance(MillimetersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.MillimeterPerSecond), MillimetersPerSecondTolerance); - AssertEx.EqualTolerance(NanometersPerMinutesInOneMeterPerSecond, meterpersecond.As(SpeedUnit.NanometerPerMinute), NanometersPerMinutesTolerance); - AssertEx.EqualTolerance(NanometersPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.NanometerPerSecond), NanometersPerSecondTolerance); - AssertEx.EqualTolerance(UsSurveyFeetPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.UsSurveyFootPerHour), UsSurveyFeetPerHourTolerance); - AssertEx.EqualTolerance(UsSurveyFeetPerMinuteInOneMeterPerSecond, meterpersecond.As(SpeedUnit.UsSurveyFootPerMinute), UsSurveyFeetPerMinuteTolerance); - AssertEx.EqualTolerance(UsSurveyFeetPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.UsSurveyFootPerSecond), UsSurveyFeetPerSecondTolerance); - AssertEx.EqualTolerance(YardsPerHourInOneMeterPerSecond, meterpersecond.As(SpeedUnit.YardPerHour), YardsPerHourTolerance); - AssertEx.EqualTolerance(YardsPerMinuteInOneMeterPerSecond, meterpersecond.As(SpeedUnit.YardPerMinute), YardsPerMinuteTolerance); - AssertEx.EqualTolerance(YardsPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.YardPerSecond), YardsPerSecondTolerance); - } - - [Fact] - public void ToUnit() - { - var meterpersecond = Speed.FromMetersPerSecond(1); - - var centimeterperhourQuantity = meterpersecond.ToUnit(SpeedUnit.CentimeterPerHour); - AssertEx.EqualTolerance(CentimetersPerHourInOneMeterPerSecond, (double)centimeterperhourQuantity.Value, CentimetersPerHourTolerance); - Assert.Equal(SpeedUnit.CentimeterPerHour, centimeterperhourQuantity.Unit); - - var centimeterperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.CentimeterPerMinute); - AssertEx.EqualTolerance(CentimetersPerMinutesInOneMeterPerSecond, (double)centimeterperminuteQuantity.Value, CentimetersPerMinutesTolerance); - Assert.Equal(SpeedUnit.CentimeterPerMinute, centimeterperminuteQuantity.Unit); - - var centimeterpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.CentimeterPerSecond); - AssertEx.EqualTolerance(CentimetersPerSecondInOneMeterPerSecond, (double)centimeterpersecondQuantity.Value, CentimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.CentimeterPerSecond, centimeterpersecondQuantity.Unit); - - var decimeterperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.DecimeterPerMinute); - AssertEx.EqualTolerance(DecimetersPerMinutesInOneMeterPerSecond, (double)decimeterperminuteQuantity.Value, DecimetersPerMinutesTolerance); - Assert.Equal(SpeedUnit.DecimeterPerMinute, decimeterperminuteQuantity.Unit); - - var decimeterpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.DecimeterPerSecond); - AssertEx.EqualTolerance(DecimetersPerSecondInOneMeterPerSecond, (double)decimeterpersecondQuantity.Value, DecimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.DecimeterPerSecond, decimeterpersecondQuantity.Unit); - - var footperhourQuantity = meterpersecond.ToUnit(SpeedUnit.FootPerHour); - AssertEx.EqualTolerance(FeetPerHourInOneMeterPerSecond, (double)footperhourQuantity.Value, FeetPerHourTolerance); - Assert.Equal(SpeedUnit.FootPerHour, footperhourQuantity.Unit); - - var footperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.FootPerMinute); - AssertEx.EqualTolerance(FeetPerMinuteInOneMeterPerSecond, (double)footperminuteQuantity.Value, FeetPerMinuteTolerance); - Assert.Equal(SpeedUnit.FootPerMinute, footperminuteQuantity.Unit); - - var footpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.FootPerSecond); - AssertEx.EqualTolerance(FeetPerSecondInOneMeterPerSecond, (double)footpersecondQuantity.Value, FeetPerSecondTolerance); - Assert.Equal(SpeedUnit.FootPerSecond, footpersecondQuantity.Unit); - - var inchperhourQuantity = meterpersecond.ToUnit(SpeedUnit.InchPerHour); - AssertEx.EqualTolerance(InchesPerHourInOneMeterPerSecond, (double)inchperhourQuantity.Value, InchesPerHourTolerance); - Assert.Equal(SpeedUnit.InchPerHour, inchperhourQuantity.Unit); - - var inchperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.InchPerMinute); - AssertEx.EqualTolerance(InchesPerMinuteInOneMeterPerSecond, (double)inchperminuteQuantity.Value, InchesPerMinuteTolerance); - Assert.Equal(SpeedUnit.InchPerMinute, inchperminuteQuantity.Unit); - - var inchpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.InchPerSecond); - AssertEx.EqualTolerance(InchesPerSecondInOneMeterPerSecond, (double)inchpersecondQuantity.Value, InchesPerSecondTolerance); - Assert.Equal(SpeedUnit.InchPerSecond, inchpersecondQuantity.Unit); - - var kilometerperhourQuantity = meterpersecond.ToUnit(SpeedUnit.KilometerPerHour); - AssertEx.EqualTolerance(KilometersPerHourInOneMeterPerSecond, (double)kilometerperhourQuantity.Value, KilometersPerHourTolerance); - Assert.Equal(SpeedUnit.KilometerPerHour, kilometerperhourQuantity.Unit); - - var kilometerperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.KilometerPerMinute); - AssertEx.EqualTolerance(KilometersPerMinutesInOneMeterPerSecond, (double)kilometerperminuteQuantity.Value, KilometersPerMinutesTolerance); - Assert.Equal(SpeedUnit.KilometerPerMinute, kilometerperminuteQuantity.Unit); - - var kilometerpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.KilometerPerSecond); - AssertEx.EqualTolerance(KilometersPerSecondInOneMeterPerSecond, (double)kilometerpersecondQuantity.Value, KilometersPerSecondTolerance); - Assert.Equal(SpeedUnit.KilometerPerSecond, kilometerpersecondQuantity.Unit); - - var knotQuantity = meterpersecond.ToUnit(SpeedUnit.Knot); - AssertEx.EqualTolerance(KnotsInOneMeterPerSecond, (double)knotQuantity.Value, KnotsTolerance); - Assert.Equal(SpeedUnit.Knot, knotQuantity.Unit); - - var meterperhourQuantity = meterpersecond.ToUnit(SpeedUnit.MeterPerHour); - AssertEx.EqualTolerance(MetersPerHourInOneMeterPerSecond, (double)meterperhourQuantity.Value, MetersPerHourTolerance); - Assert.Equal(SpeedUnit.MeterPerHour, meterperhourQuantity.Unit); - - var meterperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.MeterPerMinute); - AssertEx.EqualTolerance(MetersPerMinutesInOneMeterPerSecond, (double)meterperminuteQuantity.Value, MetersPerMinutesTolerance); - Assert.Equal(SpeedUnit.MeterPerMinute, meterperminuteQuantity.Unit); - - var meterpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.MeterPerSecond); - AssertEx.EqualTolerance(MetersPerSecondInOneMeterPerSecond, (double)meterpersecondQuantity.Value, MetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MeterPerSecond, meterpersecondQuantity.Unit); - - var micrometerperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.MicrometerPerMinute); - AssertEx.EqualTolerance(MicrometersPerMinutesInOneMeterPerSecond, (double)micrometerperminuteQuantity.Value, MicrometersPerMinutesTolerance); - Assert.Equal(SpeedUnit.MicrometerPerMinute, micrometerperminuteQuantity.Unit); - - var micrometerpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.MicrometerPerSecond); - AssertEx.EqualTolerance(MicrometersPerSecondInOneMeterPerSecond, (double)micrometerpersecondQuantity.Value, MicrometersPerSecondTolerance); - Assert.Equal(SpeedUnit.MicrometerPerSecond, micrometerpersecondQuantity.Unit); - - var mileperhourQuantity = meterpersecond.ToUnit(SpeedUnit.MilePerHour); - AssertEx.EqualTolerance(MilesPerHourInOneMeterPerSecond, (double)mileperhourQuantity.Value, MilesPerHourTolerance); - Assert.Equal(SpeedUnit.MilePerHour, mileperhourQuantity.Unit); - - var millimeterperhourQuantity = meterpersecond.ToUnit(SpeedUnit.MillimeterPerHour); - AssertEx.EqualTolerance(MillimetersPerHourInOneMeterPerSecond, (double)millimeterperhourQuantity.Value, MillimetersPerHourTolerance); - Assert.Equal(SpeedUnit.MillimeterPerHour, millimeterperhourQuantity.Unit); - - var millimeterperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.MillimeterPerMinute); - AssertEx.EqualTolerance(MillimetersPerMinutesInOneMeterPerSecond, (double)millimeterperminuteQuantity.Value, MillimetersPerMinutesTolerance); - Assert.Equal(SpeedUnit.MillimeterPerMinute, millimeterperminuteQuantity.Unit); - - var millimeterpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.MillimeterPerSecond); - AssertEx.EqualTolerance(MillimetersPerSecondInOneMeterPerSecond, (double)millimeterpersecondQuantity.Value, MillimetersPerSecondTolerance); - Assert.Equal(SpeedUnit.MillimeterPerSecond, millimeterpersecondQuantity.Unit); - - var nanometerperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.NanometerPerMinute); - AssertEx.EqualTolerance(NanometersPerMinutesInOneMeterPerSecond, (double)nanometerperminuteQuantity.Value, NanometersPerMinutesTolerance); - Assert.Equal(SpeedUnit.NanometerPerMinute, nanometerperminuteQuantity.Unit); - - var nanometerpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.NanometerPerSecond); - AssertEx.EqualTolerance(NanometersPerSecondInOneMeterPerSecond, (double)nanometerpersecondQuantity.Value, NanometersPerSecondTolerance); - Assert.Equal(SpeedUnit.NanometerPerSecond, nanometerpersecondQuantity.Unit); - - var ussurveyfootperhourQuantity = meterpersecond.ToUnit(SpeedUnit.UsSurveyFootPerHour); - AssertEx.EqualTolerance(UsSurveyFeetPerHourInOneMeterPerSecond, (double)ussurveyfootperhourQuantity.Value, UsSurveyFeetPerHourTolerance); - Assert.Equal(SpeedUnit.UsSurveyFootPerHour, ussurveyfootperhourQuantity.Unit); - - var ussurveyfootperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.UsSurveyFootPerMinute); - AssertEx.EqualTolerance(UsSurveyFeetPerMinuteInOneMeterPerSecond, (double)ussurveyfootperminuteQuantity.Value, UsSurveyFeetPerMinuteTolerance); - Assert.Equal(SpeedUnit.UsSurveyFootPerMinute, ussurveyfootperminuteQuantity.Unit); - - var ussurveyfootpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.UsSurveyFootPerSecond); - AssertEx.EqualTolerance(UsSurveyFeetPerSecondInOneMeterPerSecond, (double)ussurveyfootpersecondQuantity.Value, UsSurveyFeetPerSecondTolerance); - Assert.Equal(SpeedUnit.UsSurveyFootPerSecond, ussurveyfootpersecondQuantity.Unit); - - var yardperhourQuantity = meterpersecond.ToUnit(SpeedUnit.YardPerHour); - AssertEx.EqualTolerance(YardsPerHourInOneMeterPerSecond, (double)yardperhourQuantity.Value, YardsPerHourTolerance); - Assert.Equal(SpeedUnit.YardPerHour, yardperhourQuantity.Unit); - - var yardperminuteQuantity = meterpersecond.ToUnit(SpeedUnit.YardPerMinute); - AssertEx.EqualTolerance(YardsPerMinuteInOneMeterPerSecond, (double)yardperminuteQuantity.Value, YardsPerMinuteTolerance); - Assert.Equal(SpeedUnit.YardPerMinute, yardperminuteQuantity.Unit); - - var yardpersecondQuantity = meterpersecond.ToUnit(SpeedUnit.YardPerSecond); - AssertEx.EqualTolerance(YardsPerSecondInOneMeterPerSecond, (double)yardpersecondQuantity.Value, YardsPerSecondTolerance); - Assert.Equal(SpeedUnit.YardPerSecond, yardpersecondQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Speed meterpersecond = Speed.FromMetersPerSecond(1); - AssertEx.EqualTolerance(1, Speed.FromCentimetersPerHour(meterpersecond.CentimetersPerHour).MetersPerSecond, CentimetersPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.FromCentimetersPerMinutes(meterpersecond.CentimetersPerMinutes).MetersPerSecond, CentimetersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.FromCentimetersPerSecond(meterpersecond.CentimetersPerSecond).MetersPerSecond, CentimetersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromDecimetersPerMinutes(meterpersecond.DecimetersPerMinutes).MetersPerSecond, DecimetersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.FromDecimetersPerSecond(meterpersecond.DecimetersPerSecond).MetersPerSecond, DecimetersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromFeetPerHour(meterpersecond.FeetPerHour).MetersPerSecond, FeetPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.FromFeetPerMinute(meterpersecond.FeetPerMinute).MetersPerSecond, FeetPerMinuteTolerance); - AssertEx.EqualTolerance(1, Speed.FromFeetPerSecond(meterpersecond.FeetPerSecond).MetersPerSecond, FeetPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromInchesPerHour(meterpersecond.InchesPerHour).MetersPerSecond, InchesPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.FromInchesPerMinute(meterpersecond.InchesPerMinute).MetersPerSecond, InchesPerMinuteTolerance); - AssertEx.EqualTolerance(1, Speed.FromInchesPerSecond(meterpersecond.InchesPerSecond).MetersPerSecond, InchesPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromKilometersPerHour(meterpersecond.KilometersPerHour).MetersPerSecond, KilometersPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.FromKilometersPerMinutes(meterpersecond.KilometersPerMinutes).MetersPerSecond, KilometersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.FromKilometersPerSecond(meterpersecond.KilometersPerSecond).MetersPerSecond, KilometersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromKnots(meterpersecond.Knots).MetersPerSecond, KnotsTolerance); - AssertEx.EqualTolerance(1, Speed.FromMetersPerHour(meterpersecond.MetersPerHour).MetersPerSecond, MetersPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.FromMetersPerMinutes(meterpersecond.MetersPerMinutes).MetersPerSecond, MetersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.FromMetersPerSecond(meterpersecond.MetersPerSecond).MetersPerSecond, MetersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromMicrometersPerMinutes(meterpersecond.MicrometersPerMinutes).MetersPerSecond, MicrometersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.FromMicrometersPerSecond(meterpersecond.MicrometersPerSecond).MetersPerSecond, MicrometersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromMilesPerHour(meterpersecond.MilesPerHour).MetersPerSecond, MilesPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.FromMillimetersPerHour(meterpersecond.MillimetersPerHour).MetersPerSecond, MillimetersPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.FromMillimetersPerMinutes(meterpersecond.MillimetersPerMinutes).MetersPerSecond, MillimetersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.FromMillimetersPerSecond(meterpersecond.MillimetersPerSecond).MetersPerSecond, MillimetersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromNanometersPerMinutes(meterpersecond.NanometersPerMinutes).MetersPerSecond, NanometersPerMinutesTolerance); - AssertEx.EqualTolerance(1, Speed.FromNanometersPerSecond(meterpersecond.NanometersPerSecond).MetersPerSecond, NanometersPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromUsSurveyFeetPerHour(meterpersecond.UsSurveyFeetPerHour).MetersPerSecond, UsSurveyFeetPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.FromUsSurveyFeetPerMinute(meterpersecond.UsSurveyFeetPerMinute).MetersPerSecond, UsSurveyFeetPerMinuteTolerance); - AssertEx.EqualTolerance(1, Speed.FromUsSurveyFeetPerSecond(meterpersecond.UsSurveyFeetPerSecond).MetersPerSecond, UsSurveyFeetPerSecondTolerance); - AssertEx.EqualTolerance(1, Speed.FromYardsPerHour(meterpersecond.YardsPerHour).MetersPerSecond, YardsPerHourTolerance); - AssertEx.EqualTolerance(1, Speed.FromYardsPerMinute(meterpersecond.YardsPerMinute).MetersPerSecond, YardsPerMinuteTolerance); - AssertEx.EqualTolerance(1, Speed.FromYardsPerSecond(meterpersecond.YardsPerSecond).MetersPerSecond, YardsPerSecondTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Speed v = Speed.FromMetersPerSecond(1); - AssertEx.EqualTolerance(-1, -v.MetersPerSecond, MetersPerSecondTolerance); - AssertEx.EqualTolerance(2, (Speed.FromMetersPerSecond(3)-v).MetersPerSecond, MetersPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).MetersPerSecond, MetersPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).MetersPerSecond, MetersPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).MetersPerSecond, MetersPerSecondTolerance); - AssertEx.EqualTolerance(2, (Speed.FromMetersPerSecond(10)/5).MetersPerSecond, MetersPerSecondTolerance); - AssertEx.EqualTolerance(2, Speed.FromMetersPerSecond(10)/Speed.FromMetersPerSecond(5), MetersPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Speed oneMeterPerSecond = Speed.FromMetersPerSecond(1); - Speed twoMetersPerSecond = Speed.FromMetersPerSecond(2); - - Assert.True(oneMeterPerSecond < twoMetersPerSecond); - Assert.True(oneMeterPerSecond <= twoMetersPerSecond); - Assert.True(twoMetersPerSecond > oneMeterPerSecond); - Assert.True(twoMetersPerSecond >= oneMeterPerSecond); - - Assert.False(oneMeterPerSecond > twoMetersPerSecond); - Assert.False(oneMeterPerSecond >= twoMetersPerSecond); - Assert.False(twoMetersPerSecond < oneMeterPerSecond); - Assert.False(twoMetersPerSecond <= oneMeterPerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - Speed meterpersecond = Speed.FromMetersPerSecond(1); - Assert.Equal(0, meterpersecond.CompareTo(meterpersecond)); - Assert.True(meterpersecond.CompareTo(Speed.Zero) > 0); - Assert.True(Speed.Zero.CompareTo(meterpersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Speed meterpersecond = Speed.FromMetersPerSecond(1); - Assert.Throws(() => meterpersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Speed meterpersecond = Speed.FromMetersPerSecond(1); - Assert.Throws(() => meterpersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Speed v = Speed.FromMetersPerSecond(1); - Assert.True(v.Equals(Speed.FromMetersPerSecond(1), MetersPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Speed.Zero, MetersPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Speed meterpersecond = Speed.FromMetersPerSecond(1); - Assert.False(meterpersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Speed meterpersecond = Speed.FromMetersPerSecond(1); - Assert.False(meterpersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(SpeedUnit.Undefined, Speed.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(SpeedUnit)).Cast(); - foreach(var unit in units) - { - if(unit == SpeedUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/TemperatureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TemperatureChangeRateTestsBase.g.cs deleted file mode 100644 index 8e645c2a51..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TemperatureChangeRateTestsBase.g.cs +++ /dev/null @@ -1,314 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of TemperatureChangeRate. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TemperatureChangeRateTestsBase - { - protected abstract double CentidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } - protected abstract double DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } - protected abstract double DecidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } - protected abstract double DegreesCelsiusPerMinuteInOneDegreeCelsiusPerSecond { get; } - protected abstract double DegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } - protected abstract double HectodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } - protected abstract double KilodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } - protected abstract double MicrodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } - protected abstract double MillidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } - protected abstract double NanodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentidegreesCelsiusPerSecondTolerance { get { return 1e-5; } } - protected virtual double DecadegreesCelsiusPerSecondTolerance { get { return 1e-5; } } - protected virtual double DecidegreesCelsiusPerSecondTolerance { get { return 1e-5; } } - protected virtual double DegreesCelsiusPerMinuteTolerance { get { return 1e-5; } } - protected virtual double DegreesCelsiusPerSecondTolerance { get { return 1e-5; } } - protected virtual double HectodegreesCelsiusPerSecondTolerance { get { return 1e-5; } } - protected virtual double KilodegreesCelsiusPerSecondTolerance { get { return 1e-5; } } - protected virtual double MicrodegreesCelsiusPerSecondTolerance { get { return 1e-5; } } - protected virtual double MillidegreesCelsiusPerSecondTolerance { get { return 1e-5; } } - protected virtual double NanodegreesCelsiusPerSecondTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new TemperatureChangeRate((double)0.0, TemperatureChangeRateUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new TemperatureChangeRate(double.PositiveInfinity, TemperatureChangeRateUnit.DegreeCelsiusPerSecond)); - Assert.Throws(() => new TemperatureChangeRate(double.NegativeInfinity, TemperatureChangeRateUnit.DegreeCelsiusPerSecond)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new TemperatureChangeRate(double.NaN, TemperatureChangeRateUnit.DegreeCelsiusPerSecond)); - } - - [Fact] - public void DegreeCelsiusPerSecondToTemperatureChangeRateUnits() - { - TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - AssertEx.EqualTolerance(CentidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.CentidegreesCelsiusPerSecond, CentidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.DecadegreesCelsiusPerSecond, DecadegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(DecidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.DecidegreesCelsiusPerSecond, DecidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(DegreesCelsiusPerMinuteInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.DegreesCelsiusPerMinute, DegreesCelsiusPerMinuteTolerance); - AssertEx.EqualTolerance(DegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(HectodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.HectodegreesCelsiusPerSecond, HectodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(KilodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.KilodegreesCelsiusPerSecond, KilodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(MicrodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.MicrodegreesCelsiusPerSecond, MicrodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(MillidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.MillidegreesCelsiusPerSecond, MillidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(NanodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.NanodegreesCelsiusPerSecond, NanodegreesCelsiusPerSecondTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond).CentidegreesCelsiusPerSecond, CentidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond).DecadegreesCelsiusPerSecond, DecadegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond).DecidegreesCelsiusPerSecond, DecidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.DegreeCelsiusPerMinute).DegreesCelsiusPerMinute, DegreesCelsiusPerMinuteTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.DegreeCelsiusPerSecond).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond).HectodegreesCelsiusPerSecond, HectodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond).KilodegreesCelsiusPerSecond, KilodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond).MicrodegreesCelsiusPerSecond, MicrodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond).MillidegreesCelsiusPerSecond, MillidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.From(1, TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond).NanodegreesCelsiusPerSecond, NanodegreesCelsiusPerSecondTolerance); - } - - [Fact] - public void FromDegreesCelsiusPerSecond_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => TemperatureChangeRate.FromDegreesCelsiusPerSecond(double.PositiveInfinity)); - Assert.Throws(() => TemperatureChangeRate.FromDegreesCelsiusPerSecond(double.NegativeInfinity)); - } - - [Fact] - public void FromDegreesCelsiusPerSecond_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => TemperatureChangeRate.FromDegreesCelsiusPerSecond(double.NaN)); - } - - [Fact] - public void As() - { - var degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - AssertEx.EqualTolerance(CentidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond), CentidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond), DecadegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(DecidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond), DecidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(DegreesCelsiusPerMinuteInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.DegreeCelsiusPerMinute), DegreesCelsiusPerMinuteTolerance); - AssertEx.EqualTolerance(DegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.DegreeCelsiusPerSecond), DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(HectodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond), HectodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(KilodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond), KilodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(MicrodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond), MicrodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(MillidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond), MillidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(NanodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond), NanodegreesCelsiusPerSecondTolerance); - } - - [Fact] - public void ToUnit() - { - var degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - - var centidegreecelsiuspersecondQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond); - AssertEx.EqualTolerance(CentidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, (double)centidegreecelsiuspersecondQuantity.Value, CentidegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, centidegreecelsiuspersecondQuantity.Unit); - - var decadegreecelsiuspersecondQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond); - AssertEx.EqualTolerance(DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, (double)decadegreecelsiuspersecondQuantity.Value, DecadegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, decadegreecelsiuspersecondQuantity.Unit); - - var decidegreecelsiuspersecondQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond); - AssertEx.EqualTolerance(DecidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, (double)decidegreecelsiuspersecondQuantity.Value, DecidegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, decidegreecelsiuspersecondQuantity.Unit); - - var degreecelsiusperminuteQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.DegreeCelsiusPerMinute); - AssertEx.EqualTolerance(DegreesCelsiusPerMinuteInOneDegreeCelsiusPerSecond, (double)degreecelsiusperminuteQuantity.Value, DegreesCelsiusPerMinuteTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerMinute, degreecelsiusperminuteQuantity.Unit); - - var degreecelsiuspersecondQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.DegreeCelsiusPerSecond); - AssertEx.EqualTolerance(DegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, (double)degreecelsiuspersecondQuantity.Value, DegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerSecond, degreecelsiuspersecondQuantity.Unit); - - var hectodegreecelsiuspersecondQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond); - AssertEx.EqualTolerance(HectodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, (double)hectodegreecelsiuspersecondQuantity.Value, HectodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, hectodegreecelsiuspersecondQuantity.Unit); - - var kilodegreecelsiuspersecondQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond); - AssertEx.EqualTolerance(KilodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, (double)kilodegreecelsiuspersecondQuantity.Value, KilodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, kilodegreecelsiuspersecondQuantity.Unit); - - var microdegreecelsiuspersecondQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond); - AssertEx.EqualTolerance(MicrodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, (double)microdegreecelsiuspersecondQuantity.Value, MicrodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, microdegreecelsiuspersecondQuantity.Unit); - - var millidegreecelsiuspersecondQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond); - AssertEx.EqualTolerance(MillidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, (double)millidegreecelsiuspersecondQuantity.Value, MillidegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, millidegreecelsiuspersecondQuantity.Unit); - - var nanodegreecelsiuspersecondQuantity = degreecelsiuspersecond.ToUnit(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond); - AssertEx.EqualTolerance(NanodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, (double)nanodegreecelsiuspersecondQuantity.Value, NanodegreesCelsiusPerSecondTolerance); - Assert.Equal(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, nanodegreecelsiuspersecondQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromCentidegreesCelsiusPerSecond(degreecelsiuspersecond.CentidegreesCelsiusPerSecond).DegreesCelsiusPerSecond, CentidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromDecadegreesCelsiusPerSecond(degreecelsiuspersecond.DecadegreesCelsiusPerSecond).DegreesCelsiusPerSecond, DecadegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromDecidegreesCelsiusPerSecond(degreecelsiuspersecond.DecidegreesCelsiusPerSecond).DegreesCelsiusPerSecond, DecidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromDegreesCelsiusPerMinute(degreecelsiuspersecond.DegreesCelsiusPerMinute).DegreesCelsiusPerSecond, DegreesCelsiusPerMinuteTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromDegreesCelsiusPerSecond(degreecelsiuspersecond.DegreesCelsiusPerSecond).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromHectodegreesCelsiusPerSecond(degreecelsiuspersecond.HectodegreesCelsiusPerSecond).DegreesCelsiusPerSecond, HectodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromKilodegreesCelsiusPerSecond(degreecelsiuspersecond.KilodegreesCelsiusPerSecond).DegreesCelsiusPerSecond, KilodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromMicrodegreesCelsiusPerSecond(degreecelsiuspersecond.MicrodegreesCelsiusPerSecond).DegreesCelsiusPerSecond, MicrodegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromMillidegreesCelsiusPerSecond(degreecelsiuspersecond.MillidegreesCelsiusPerSecond).DegreesCelsiusPerSecond, MillidegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(1, TemperatureChangeRate.FromNanodegreesCelsiusPerSecond(degreecelsiuspersecond.NanodegreesCelsiusPerSecond).DegreesCelsiusPerSecond, NanodegreesCelsiusPerSecondTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - TemperatureChangeRate v = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - AssertEx.EqualTolerance(-1, -v.DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(2, (TemperatureChangeRate.FromDegreesCelsiusPerSecond(3)-v).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(2, (TemperatureChangeRate.FromDegreesCelsiusPerSecond(10)/5).DegreesCelsiusPerSecond, DegreesCelsiusPerSecondTolerance); - AssertEx.EqualTolerance(2, TemperatureChangeRate.FromDegreesCelsiusPerSecond(10)/TemperatureChangeRate.FromDegreesCelsiusPerSecond(5), DegreesCelsiusPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - TemperatureChangeRate oneDegreeCelsiusPerSecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - TemperatureChangeRate twoDegreesCelsiusPerSecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(2); - - Assert.True(oneDegreeCelsiusPerSecond < twoDegreesCelsiusPerSecond); - Assert.True(oneDegreeCelsiusPerSecond <= twoDegreesCelsiusPerSecond); - Assert.True(twoDegreesCelsiusPerSecond > oneDegreeCelsiusPerSecond); - Assert.True(twoDegreesCelsiusPerSecond >= oneDegreeCelsiusPerSecond); - - Assert.False(oneDegreeCelsiusPerSecond > twoDegreesCelsiusPerSecond); - Assert.False(oneDegreeCelsiusPerSecond >= twoDegreesCelsiusPerSecond); - Assert.False(twoDegreesCelsiusPerSecond < oneDegreeCelsiusPerSecond); - Assert.False(twoDegreesCelsiusPerSecond <= oneDegreeCelsiusPerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - Assert.Equal(0, degreecelsiuspersecond.CompareTo(degreecelsiuspersecond)); - Assert.True(degreecelsiuspersecond.CompareTo(TemperatureChangeRate.Zero) > 0); - Assert.True(TemperatureChangeRate.Zero.CompareTo(degreecelsiuspersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - Assert.Throws(() => degreecelsiuspersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - Assert.Throws(() => degreecelsiuspersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - TemperatureChangeRate v = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - Assert.True(v.Equals(TemperatureChangeRate.FromDegreesCelsiusPerSecond(1), DegreesCelsiusPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(TemperatureChangeRate.Zero, DegreesCelsiusPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - Assert.False(degreecelsiuspersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - TemperatureChangeRate degreecelsiuspersecond = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1); - Assert.False(degreecelsiuspersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(TemperatureChangeRateUnit.Undefined, TemperatureChangeRate.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(TemperatureChangeRateUnit)).Cast(); - foreach(var unit in units) - { - if(unit == TemperatureChangeRateUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/TemperatureDeltaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TemperatureDeltaTestsBase.g.cs deleted file mode 100644 index a5bcad847b..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TemperatureDeltaTestsBase.g.cs +++ /dev/null @@ -1,294 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of TemperatureDelta. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TemperatureDeltaTestsBase - { - protected abstract double DegreesCelsiusInOneKelvin { get; } - protected abstract double DegreesDelisleInOneKelvin { get; } - protected abstract double DegreesFahrenheitInOneKelvin { get; } - protected abstract double DegreesNewtonInOneKelvin { get; } - protected abstract double DegreesRankineInOneKelvin { get; } - protected abstract double DegreesReaumurInOneKelvin { get; } - protected abstract double DegreesRoemerInOneKelvin { get; } - protected abstract double KelvinsInOneKelvin { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DegreesCelsiusTolerance { get { return 1e-5; } } - protected virtual double DegreesDelisleTolerance { get { return 1e-5; } } - protected virtual double DegreesFahrenheitTolerance { get { return 1e-5; } } - protected virtual double DegreesNewtonTolerance { get { return 1e-5; } } - protected virtual double DegreesRankineTolerance { get { return 1e-5; } } - protected virtual double DegreesReaumurTolerance { get { return 1e-5; } } - protected virtual double DegreesRoemerTolerance { get { return 1e-5; } } - protected virtual double KelvinsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new TemperatureDelta((double)0.0, TemperatureDeltaUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new TemperatureDelta(double.PositiveInfinity, TemperatureDeltaUnit.Kelvin)); - Assert.Throws(() => new TemperatureDelta(double.NegativeInfinity, TemperatureDeltaUnit.Kelvin)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new TemperatureDelta(double.NaN, TemperatureDeltaUnit.Kelvin)); - } - - [Fact] - public void KelvinToTemperatureDeltaUnits() - { - TemperatureDelta kelvin = TemperatureDelta.FromKelvins(1); - AssertEx.EqualTolerance(DegreesCelsiusInOneKelvin, kelvin.DegreesCelsius, DegreesCelsiusTolerance); - AssertEx.EqualTolerance(DegreesDelisleInOneKelvin, kelvin.DegreesDelisle, DegreesDelisleTolerance); - AssertEx.EqualTolerance(DegreesFahrenheitInOneKelvin, kelvin.DegreesFahrenheit, DegreesFahrenheitTolerance); - AssertEx.EqualTolerance(DegreesNewtonInOneKelvin, kelvin.DegreesNewton, DegreesNewtonTolerance); - AssertEx.EqualTolerance(DegreesRankineInOneKelvin, kelvin.DegreesRankine, DegreesRankineTolerance); - AssertEx.EqualTolerance(DegreesReaumurInOneKelvin, kelvin.DegreesReaumur, DegreesReaumurTolerance); - AssertEx.EqualTolerance(DegreesRoemerInOneKelvin, kelvin.DegreesRoemer, DegreesRoemerTolerance); - AssertEx.EqualTolerance(KelvinsInOneKelvin, kelvin.Kelvins, KelvinsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeCelsius).DegreesCelsius, DegreesCelsiusTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeDelisle).DegreesDelisle, DegreesDelisleTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeFahrenheit).DegreesFahrenheit, DegreesFahrenheitTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeNewton).DegreesNewton, DegreesNewtonTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeRankine).DegreesRankine, DegreesRankineTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeReaumur).DegreesReaumur, DegreesReaumurTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.From(1, TemperatureDeltaUnit.DegreeRoemer).DegreesRoemer, DegreesRoemerTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.From(1, TemperatureDeltaUnit.Kelvin).Kelvins, KelvinsTolerance); - } - - [Fact] - public void FromKelvins_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => TemperatureDelta.FromKelvins(double.PositiveInfinity)); - Assert.Throws(() => TemperatureDelta.FromKelvins(double.NegativeInfinity)); - } - - [Fact] - public void FromKelvins_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => TemperatureDelta.FromKelvins(double.NaN)); - } - - [Fact] - public void As() - { - var kelvin = TemperatureDelta.FromKelvins(1); - AssertEx.EqualTolerance(DegreesCelsiusInOneKelvin, kelvin.As(TemperatureDeltaUnit.DegreeCelsius), DegreesCelsiusTolerance); - AssertEx.EqualTolerance(DegreesDelisleInOneKelvin, kelvin.As(TemperatureDeltaUnit.DegreeDelisle), DegreesDelisleTolerance); - AssertEx.EqualTolerance(DegreesFahrenheitInOneKelvin, kelvin.As(TemperatureDeltaUnit.DegreeFahrenheit), DegreesFahrenheitTolerance); - AssertEx.EqualTolerance(DegreesNewtonInOneKelvin, kelvin.As(TemperatureDeltaUnit.DegreeNewton), DegreesNewtonTolerance); - AssertEx.EqualTolerance(DegreesRankineInOneKelvin, kelvin.As(TemperatureDeltaUnit.DegreeRankine), DegreesRankineTolerance); - AssertEx.EqualTolerance(DegreesReaumurInOneKelvin, kelvin.As(TemperatureDeltaUnit.DegreeReaumur), DegreesReaumurTolerance); - AssertEx.EqualTolerance(DegreesRoemerInOneKelvin, kelvin.As(TemperatureDeltaUnit.DegreeRoemer), DegreesRoemerTolerance); - AssertEx.EqualTolerance(KelvinsInOneKelvin, kelvin.As(TemperatureDeltaUnit.Kelvin), KelvinsTolerance); - } - - [Fact] - public void ToUnit() - { - var kelvin = TemperatureDelta.FromKelvins(1); - - var degreecelsiusQuantity = kelvin.ToUnit(TemperatureDeltaUnit.DegreeCelsius); - AssertEx.EqualTolerance(DegreesCelsiusInOneKelvin, (double)degreecelsiusQuantity.Value, DegreesCelsiusTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeCelsius, degreecelsiusQuantity.Unit); - - var degreedelisleQuantity = kelvin.ToUnit(TemperatureDeltaUnit.DegreeDelisle); - AssertEx.EqualTolerance(DegreesDelisleInOneKelvin, (double)degreedelisleQuantity.Value, DegreesDelisleTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeDelisle, degreedelisleQuantity.Unit); - - var degreefahrenheitQuantity = kelvin.ToUnit(TemperatureDeltaUnit.DegreeFahrenheit); - AssertEx.EqualTolerance(DegreesFahrenheitInOneKelvin, (double)degreefahrenheitQuantity.Value, DegreesFahrenheitTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeFahrenheit, degreefahrenheitQuantity.Unit); - - var degreenewtonQuantity = kelvin.ToUnit(TemperatureDeltaUnit.DegreeNewton); - AssertEx.EqualTolerance(DegreesNewtonInOneKelvin, (double)degreenewtonQuantity.Value, DegreesNewtonTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeNewton, degreenewtonQuantity.Unit); - - var degreerankineQuantity = kelvin.ToUnit(TemperatureDeltaUnit.DegreeRankine); - AssertEx.EqualTolerance(DegreesRankineInOneKelvin, (double)degreerankineQuantity.Value, DegreesRankineTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeRankine, degreerankineQuantity.Unit); - - var degreereaumurQuantity = kelvin.ToUnit(TemperatureDeltaUnit.DegreeReaumur); - AssertEx.EqualTolerance(DegreesReaumurInOneKelvin, (double)degreereaumurQuantity.Value, DegreesReaumurTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeReaumur, degreereaumurQuantity.Unit); - - var degreeroemerQuantity = kelvin.ToUnit(TemperatureDeltaUnit.DegreeRoemer); - AssertEx.EqualTolerance(DegreesRoemerInOneKelvin, (double)degreeroemerQuantity.Value, DegreesRoemerTolerance); - Assert.Equal(TemperatureDeltaUnit.DegreeRoemer, degreeroemerQuantity.Unit); - - var kelvinQuantity = kelvin.ToUnit(TemperatureDeltaUnit.Kelvin); - AssertEx.EqualTolerance(KelvinsInOneKelvin, (double)kelvinQuantity.Value, KelvinsTolerance); - Assert.Equal(TemperatureDeltaUnit.Kelvin, kelvinQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - TemperatureDelta kelvin = TemperatureDelta.FromKelvins(1); - AssertEx.EqualTolerance(1, TemperatureDelta.FromDegreesCelsius(kelvin.DegreesCelsius).Kelvins, DegreesCelsiusTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.FromDegreesDelisle(kelvin.DegreesDelisle).Kelvins, DegreesDelisleTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.FromDegreesFahrenheit(kelvin.DegreesFahrenheit).Kelvins, DegreesFahrenheitTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.FromDegreesNewton(kelvin.DegreesNewton).Kelvins, DegreesNewtonTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.FromDegreesRankine(kelvin.DegreesRankine).Kelvins, DegreesRankineTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.FromDegreesReaumur(kelvin.DegreesReaumur).Kelvins, DegreesReaumurTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.FromDegreesRoemer(kelvin.DegreesRoemer).Kelvins, DegreesRoemerTolerance); - AssertEx.EqualTolerance(1, TemperatureDelta.FromKelvins(kelvin.Kelvins).Kelvins, KelvinsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - TemperatureDelta v = TemperatureDelta.FromKelvins(1); - AssertEx.EqualTolerance(-1, -v.Kelvins, KelvinsTolerance); - AssertEx.EqualTolerance(2, (TemperatureDelta.FromKelvins(3)-v).Kelvins, KelvinsTolerance); - AssertEx.EqualTolerance(2, (v + v).Kelvins, KelvinsTolerance); - AssertEx.EqualTolerance(10, (v*10).Kelvins, KelvinsTolerance); - AssertEx.EqualTolerance(10, (10*v).Kelvins, KelvinsTolerance); - AssertEx.EqualTolerance(2, (TemperatureDelta.FromKelvins(10)/5).Kelvins, KelvinsTolerance); - AssertEx.EqualTolerance(2, TemperatureDelta.FromKelvins(10)/TemperatureDelta.FromKelvins(5), KelvinsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - TemperatureDelta oneKelvin = TemperatureDelta.FromKelvins(1); - TemperatureDelta twoKelvins = TemperatureDelta.FromKelvins(2); - - Assert.True(oneKelvin < twoKelvins); - Assert.True(oneKelvin <= twoKelvins); - Assert.True(twoKelvins > oneKelvin); - Assert.True(twoKelvins >= oneKelvin); - - Assert.False(oneKelvin > twoKelvins); - Assert.False(oneKelvin >= twoKelvins); - Assert.False(twoKelvins < oneKelvin); - Assert.False(twoKelvins <= oneKelvin); - } - - [Fact] - public void CompareToIsImplemented() - { - TemperatureDelta kelvin = TemperatureDelta.FromKelvins(1); - Assert.Equal(0, kelvin.CompareTo(kelvin)); - Assert.True(kelvin.CompareTo(TemperatureDelta.Zero) > 0); - Assert.True(TemperatureDelta.Zero.CompareTo(kelvin) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - TemperatureDelta kelvin = TemperatureDelta.FromKelvins(1); - Assert.Throws(() => kelvin.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - TemperatureDelta kelvin = TemperatureDelta.FromKelvins(1); - Assert.Throws(() => kelvin.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - TemperatureDelta v = TemperatureDelta.FromKelvins(1); - Assert.True(v.Equals(TemperatureDelta.FromKelvins(1), KelvinsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(TemperatureDelta.Zero, KelvinsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - TemperatureDelta kelvin = TemperatureDelta.FromKelvins(1); - Assert.False(kelvin.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - TemperatureDelta kelvin = TemperatureDelta.FromKelvins(1); - Assert.False(kelvin.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(TemperatureDeltaUnit.Undefined, TemperatureDelta.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(TemperatureDeltaUnit)).Cast(); - foreach(var unit in units) - { - if(unit == TemperatureDeltaUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/TemperatureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TemperatureTestsBase.g.cs deleted file mode 100644 index d16929aaa9..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TemperatureTestsBase.g.cs +++ /dev/null @@ -1,282 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Temperature. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TemperatureTestsBase - { - protected abstract double DegreesCelsiusInOneKelvin { get; } - protected abstract double DegreesDelisleInOneKelvin { get; } - protected abstract double DegreesFahrenheitInOneKelvin { get; } - protected abstract double DegreesNewtonInOneKelvin { get; } - protected abstract double DegreesRankineInOneKelvin { get; } - protected abstract double DegreesReaumurInOneKelvin { get; } - protected abstract double DegreesRoemerInOneKelvin { get; } - protected abstract double KelvinsInOneKelvin { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double DegreesCelsiusTolerance { get { return 1e-5; } } - protected virtual double DegreesDelisleTolerance { get { return 1e-5; } } - protected virtual double DegreesFahrenheitTolerance { get { return 1e-5; } } - protected virtual double DegreesNewtonTolerance { get { return 1e-5; } } - protected virtual double DegreesRankineTolerance { get { return 1e-5; } } - protected virtual double DegreesReaumurTolerance { get { return 1e-5; } } - protected virtual double DegreesRoemerTolerance { get { return 1e-5; } } - protected virtual double KelvinsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Temperature((double)0.0, TemperatureUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Temperature(double.PositiveInfinity, TemperatureUnit.Kelvin)); - Assert.Throws(() => new Temperature(double.NegativeInfinity, TemperatureUnit.Kelvin)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Temperature(double.NaN, TemperatureUnit.Kelvin)); - } - - [Fact] - public void KelvinToTemperatureUnits() - { - Temperature kelvin = Temperature.FromKelvins(1); - AssertEx.EqualTolerance(DegreesCelsiusInOneKelvin, kelvin.DegreesCelsius, DegreesCelsiusTolerance); - AssertEx.EqualTolerance(DegreesDelisleInOneKelvin, kelvin.DegreesDelisle, DegreesDelisleTolerance); - AssertEx.EqualTolerance(DegreesFahrenheitInOneKelvin, kelvin.DegreesFahrenheit, DegreesFahrenheitTolerance); - AssertEx.EqualTolerance(DegreesNewtonInOneKelvin, kelvin.DegreesNewton, DegreesNewtonTolerance); - AssertEx.EqualTolerance(DegreesRankineInOneKelvin, kelvin.DegreesRankine, DegreesRankineTolerance); - AssertEx.EqualTolerance(DegreesReaumurInOneKelvin, kelvin.DegreesReaumur, DegreesReaumurTolerance); - AssertEx.EqualTolerance(DegreesRoemerInOneKelvin, kelvin.DegreesRoemer, DegreesRoemerTolerance); - AssertEx.EqualTolerance(KelvinsInOneKelvin, kelvin.Kelvins, KelvinsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Temperature.From(1, TemperatureUnit.DegreeCelsius).DegreesCelsius, DegreesCelsiusTolerance); - AssertEx.EqualTolerance(1, Temperature.From(1, TemperatureUnit.DegreeDelisle).DegreesDelisle, DegreesDelisleTolerance); - AssertEx.EqualTolerance(1, Temperature.From(1, TemperatureUnit.DegreeFahrenheit).DegreesFahrenheit, DegreesFahrenheitTolerance); - AssertEx.EqualTolerance(1, Temperature.From(1, TemperatureUnit.DegreeNewton).DegreesNewton, DegreesNewtonTolerance); - AssertEx.EqualTolerance(1, Temperature.From(1, TemperatureUnit.DegreeRankine).DegreesRankine, DegreesRankineTolerance); - AssertEx.EqualTolerance(1, Temperature.From(1, TemperatureUnit.DegreeReaumur).DegreesReaumur, DegreesReaumurTolerance); - AssertEx.EqualTolerance(1, Temperature.From(1, TemperatureUnit.DegreeRoemer).DegreesRoemer, DegreesRoemerTolerance); - AssertEx.EqualTolerance(1, Temperature.From(1, TemperatureUnit.Kelvin).Kelvins, KelvinsTolerance); - } - - [Fact] - public void FromKelvins_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Temperature.FromKelvins(double.PositiveInfinity)); - Assert.Throws(() => Temperature.FromKelvins(double.NegativeInfinity)); - } - - [Fact] - public void FromKelvins_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Temperature.FromKelvins(double.NaN)); - } - - [Fact] - public void As() - { - var kelvin = Temperature.FromKelvins(1); - AssertEx.EqualTolerance(DegreesCelsiusInOneKelvin, kelvin.As(TemperatureUnit.DegreeCelsius), DegreesCelsiusTolerance); - AssertEx.EqualTolerance(DegreesDelisleInOneKelvin, kelvin.As(TemperatureUnit.DegreeDelisle), DegreesDelisleTolerance); - AssertEx.EqualTolerance(DegreesFahrenheitInOneKelvin, kelvin.As(TemperatureUnit.DegreeFahrenheit), DegreesFahrenheitTolerance); - AssertEx.EqualTolerance(DegreesNewtonInOneKelvin, kelvin.As(TemperatureUnit.DegreeNewton), DegreesNewtonTolerance); - AssertEx.EqualTolerance(DegreesRankineInOneKelvin, kelvin.As(TemperatureUnit.DegreeRankine), DegreesRankineTolerance); - AssertEx.EqualTolerance(DegreesReaumurInOneKelvin, kelvin.As(TemperatureUnit.DegreeReaumur), DegreesReaumurTolerance); - AssertEx.EqualTolerance(DegreesRoemerInOneKelvin, kelvin.As(TemperatureUnit.DegreeRoemer), DegreesRoemerTolerance); - AssertEx.EqualTolerance(KelvinsInOneKelvin, kelvin.As(TemperatureUnit.Kelvin), KelvinsTolerance); - } - - [Fact] - public void ToUnit() - { - var kelvin = Temperature.FromKelvins(1); - - var degreecelsiusQuantity = kelvin.ToUnit(TemperatureUnit.DegreeCelsius); - AssertEx.EqualTolerance(DegreesCelsiusInOneKelvin, (double)degreecelsiusQuantity.Value, DegreesCelsiusTolerance); - Assert.Equal(TemperatureUnit.DegreeCelsius, degreecelsiusQuantity.Unit); - - var degreedelisleQuantity = kelvin.ToUnit(TemperatureUnit.DegreeDelisle); - AssertEx.EqualTolerance(DegreesDelisleInOneKelvin, (double)degreedelisleQuantity.Value, DegreesDelisleTolerance); - Assert.Equal(TemperatureUnit.DegreeDelisle, degreedelisleQuantity.Unit); - - var degreefahrenheitQuantity = kelvin.ToUnit(TemperatureUnit.DegreeFahrenheit); - AssertEx.EqualTolerance(DegreesFahrenheitInOneKelvin, (double)degreefahrenheitQuantity.Value, DegreesFahrenheitTolerance); - Assert.Equal(TemperatureUnit.DegreeFahrenheit, degreefahrenheitQuantity.Unit); - - var degreenewtonQuantity = kelvin.ToUnit(TemperatureUnit.DegreeNewton); - AssertEx.EqualTolerance(DegreesNewtonInOneKelvin, (double)degreenewtonQuantity.Value, DegreesNewtonTolerance); - Assert.Equal(TemperatureUnit.DegreeNewton, degreenewtonQuantity.Unit); - - var degreerankineQuantity = kelvin.ToUnit(TemperatureUnit.DegreeRankine); - AssertEx.EqualTolerance(DegreesRankineInOneKelvin, (double)degreerankineQuantity.Value, DegreesRankineTolerance); - Assert.Equal(TemperatureUnit.DegreeRankine, degreerankineQuantity.Unit); - - var degreereaumurQuantity = kelvin.ToUnit(TemperatureUnit.DegreeReaumur); - AssertEx.EqualTolerance(DegreesReaumurInOneKelvin, (double)degreereaumurQuantity.Value, DegreesReaumurTolerance); - Assert.Equal(TemperatureUnit.DegreeReaumur, degreereaumurQuantity.Unit); - - var degreeroemerQuantity = kelvin.ToUnit(TemperatureUnit.DegreeRoemer); - AssertEx.EqualTolerance(DegreesRoemerInOneKelvin, (double)degreeroemerQuantity.Value, DegreesRoemerTolerance); - Assert.Equal(TemperatureUnit.DegreeRoemer, degreeroemerQuantity.Unit); - - var kelvinQuantity = kelvin.ToUnit(TemperatureUnit.Kelvin); - AssertEx.EqualTolerance(KelvinsInOneKelvin, (double)kelvinQuantity.Value, KelvinsTolerance); - Assert.Equal(TemperatureUnit.Kelvin, kelvinQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Temperature kelvin = Temperature.FromKelvins(1); - AssertEx.EqualTolerance(1, Temperature.FromDegreesCelsius(kelvin.DegreesCelsius).Kelvins, DegreesCelsiusTolerance); - AssertEx.EqualTolerance(1, Temperature.FromDegreesDelisle(kelvin.DegreesDelisle).Kelvins, DegreesDelisleTolerance); - AssertEx.EqualTolerance(1, Temperature.FromDegreesFahrenheit(kelvin.DegreesFahrenheit).Kelvins, DegreesFahrenheitTolerance); - AssertEx.EqualTolerance(1, Temperature.FromDegreesNewton(kelvin.DegreesNewton).Kelvins, DegreesNewtonTolerance); - AssertEx.EqualTolerance(1, Temperature.FromDegreesRankine(kelvin.DegreesRankine).Kelvins, DegreesRankineTolerance); - AssertEx.EqualTolerance(1, Temperature.FromDegreesReaumur(kelvin.DegreesReaumur).Kelvins, DegreesReaumurTolerance); - AssertEx.EqualTolerance(1, Temperature.FromDegreesRoemer(kelvin.DegreesRoemer).Kelvins, DegreesRoemerTolerance); - AssertEx.EqualTolerance(1, Temperature.FromKelvins(kelvin.Kelvins).Kelvins, KelvinsTolerance); - } - - - [Fact] - public void ComparisonOperators() - { - Temperature oneKelvin = Temperature.FromKelvins(1); - Temperature twoKelvins = Temperature.FromKelvins(2); - - Assert.True(oneKelvin < twoKelvins); - Assert.True(oneKelvin <= twoKelvins); - Assert.True(twoKelvins > oneKelvin); - Assert.True(twoKelvins >= oneKelvin); - - Assert.False(oneKelvin > twoKelvins); - Assert.False(oneKelvin >= twoKelvins); - Assert.False(twoKelvins < oneKelvin); - Assert.False(twoKelvins <= oneKelvin); - } - - [Fact] - public void CompareToIsImplemented() - { - Temperature kelvin = Temperature.FromKelvins(1); - Assert.Equal(0, kelvin.CompareTo(kelvin)); - Assert.True(kelvin.CompareTo(Temperature.Zero) > 0); - Assert.True(Temperature.Zero.CompareTo(kelvin) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Temperature kelvin = Temperature.FromKelvins(1); - Assert.Throws(() => kelvin.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Temperature kelvin = Temperature.FromKelvins(1); - Assert.Throws(() => kelvin.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Temperature v = Temperature.FromKelvins(1); - Assert.True(v.Equals(Temperature.FromKelvins(1), KelvinsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Temperature.Zero, KelvinsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Temperature kelvin = Temperature.FromKelvins(1); - Assert.False(kelvin.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Temperature kelvin = Temperature.FromKelvins(1); - Assert.False(kelvin.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(TemperatureUnit.Undefined, Temperature.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(TemperatureUnit)).Cast(); - foreach(var unit in units) - { - if(unit == TemperatureUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ThermalConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ThermalConductivityTestsBase.g.cs deleted file mode 100644 index e7c5d0d8ab..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ThermalConductivityTestsBase.g.cs +++ /dev/null @@ -1,234 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ThermalConductivity. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ThermalConductivityTestsBase - { - protected abstract double BtusPerHourFootFahrenheitInOneWattPerMeterKelvin { get; } - protected abstract double WattsPerMeterKelvinInOneWattPerMeterKelvin { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double BtusPerHourFootFahrenheitTolerance { get { return 1e-5; } } - protected virtual double WattsPerMeterKelvinTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ThermalConductivity((double)0.0, ThermalConductivityUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ThermalConductivity(double.PositiveInfinity, ThermalConductivityUnit.WattPerMeterKelvin)); - Assert.Throws(() => new ThermalConductivity(double.NegativeInfinity, ThermalConductivityUnit.WattPerMeterKelvin)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ThermalConductivity(double.NaN, ThermalConductivityUnit.WattPerMeterKelvin)); - } - - [Fact] - public void WattPerMeterKelvinToThermalConductivityUnits() - { - ThermalConductivity wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - AssertEx.EqualTolerance(BtusPerHourFootFahrenheitInOneWattPerMeterKelvin, wattpermeterkelvin.BtusPerHourFootFahrenheit, BtusPerHourFootFahrenheitTolerance); - AssertEx.EqualTolerance(WattsPerMeterKelvinInOneWattPerMeterKelvin, wattpermeterkelvin.WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ThermalConductivity.From(1, ThermalConductivityUnit.BtuPerHourFootFahrenheit).BtusPerHourFootFahrenheit, BtusPerHourFootFahrenheitTolerance); - AssertEx.EqualTolerance(1, ThermalConductivity.From(1, ThermalConductivityUnit.WattPerMeterKelvin).WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - } - - [Fact] - public void FromWattsPerMeterKelvin_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ThermalConductivity.FromWattsPerMeterKelvin(double.PositiveInfinity)); - Assert.Throws(() => ThermalConductivity.FromWattsPerMeterKelvin(double.NegativeInfinity)); - } - - [Fact] - public void FromWattsPerMeterKelvin_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ThermalConductivity.FromWattsPerMeterKelvin(double.NaN)); - } - - [Fact] - public void As() - { - var wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - AssertEx.EqualTolerance(BtusPerHourFootFahrenheitInOneWattPerMeterKelvin, wattpermeterkelvin.As(ThermalConductivityUnit.BtuPerHourFootFahrenheit), BtusPerHourFootFahrenheitTolerance); - AssertEx.EqualTolerance(WattsPerMeterKelvinInOneWattPerMeterKelvin, wattpermeterkelvin.As(ThermalConductivityUnit.WattPerMeterKelvin), WattsPerMeterKelvinTolerance); - } - - [Fact] - public void ToUnit() - { - var wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - - var btuperhourfootfahrenheitQuantity = wattpermeterkelvin.ToUnit(ThermalConductivityUnit.BtuPerHourFootFahrenheit); - AssertEx.EqualTolerance(BtusPerHourFootFahrenheitInOneWattPerMeterKelvin, (double)btuperhourfootfahrenheitQuantity.Value, BtusPerHourFootFahrenheitTolerance); - Assert.Equal(ThermalConductivityUnit.BtuPerHourFootFahrenheit, btuperhourfootfahrenheitQuantity.Unit); - - var wattpermeterkelvinQuantity = wattpermeterkelvin.ToUnit(ThermalConductivityUnit.WattPerMeterKelvin); - AssertEx.EqualTolerance(WattsPerMeterKelvinInOneWattPerMeterKelvin, (double)wattpermeterkelvinQuantity.Value, WattsPerMeterKelvinTolerance); - Assert.Equal(ThermalConductivityUnit.WattPerMeterKelvin, wattpermeterkelvinQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ThermalConductivity wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - AssertEx.EqualTolerance(1, ThermalConductivity.FromBtusPerHourFootFahrenheit(wattpermeterkelvin.BtusPerHourFootFahrenheit).WattsPerMeterKelvin, BtusPerHourFootFahrenheitTolerance); - AssertEx.EqualTolerance(1, ThermalConductivity.FromWattsPerMeterKelvin(wattpermeterkelvin.WattsPerMeterKelvin).WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ThermalConductivity v = ThermalConductivity.FromWattsPerMeterKelvin(1); - AssertEx.EqualTolerance(-1, -v.WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - AssertEx.EqualTolerance(2, (ThermalConductivity.FromWattsPerMeterKelvin(3)-v).WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - AssertEx.EqualTolerance(2, (v + v).WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - AssertEx.EqualTolerance(10, (v*10).WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - AssertEx.EqualTolerance(10, (10*v).WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - AssertEx.EqualTolerance(2, (ThermalConductivity.FromWattsPerMeterKelvin(10)/5).WattsPerMeterKelvin, WattsPerMeterKelvinTolerance); - AssertEx.EqualTolerance(2, ThermalConductivity.FromWattsPerMeterKelvin(10)/ThermalConductivity.FromWattsPerMeterKelvin(5), WattsPerMeterKelvinTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ThermalConductivity oneWattPerMeterKelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - ThermalConductivity twoWattsPerMeterKelvin = ThermalConductivity.FromWattsPerMeterKelvin(2); - - Assert.True(oneWattPerMeterKelvin < twoWattsPerMeterKelvin); - Assert.True(oneWattPerMeterKelvin <= twoWattsPerMeterKelvin); - Assert.True(twoWattsPerMeterKelvin > oneWattPerMeterKelvin); - Assert.True(twoWattsPerMeterKelvin >= oneWattPerMeterKelvin); - - Assert.False(oneWattPerMeterKelvin > twoWattsPerMeterKelvin); - Assert.False(oneWattPerMeterKelvin >= twoWattsPerMeterKelvin); - Assert.False(twoWattsPerMeterKelvin < oneWattPerMeterKelvin); - Assert.False(twoWattsPerMeterKelvin <= oneWattPerMeterKelvin); - } - - [Fact] - public void CompareToIsImplemented() - { - ThermalConductivity wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - Assert.Equal(0, wattpermeterkelvin.CompareTo(wattpermeterkelvin)); - Assert.True(wattpermeterkelvin.CompareTo(ThermalConductivity.Zero) > 0); - Assert.True(ThermalConductivity.Zero.CompareTo(wattpermeterkelvin) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ThermalConductivity wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - Assert.Throws(() => wattpermeterkelvin.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ThermalConductivity wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - Assert.Throws(() => wattpermeterkelvin.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ThermalConductivity v = ThermalConductivity.FromWattsPerMeterKelvin(1); - Assert.True(v.Equals(ThermalConductivity.FromWattsPerMeterKelvin(1), WattsPerMeterKelvinTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ThermalConductivity.Zero, WattsPerMeterKelvinTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ThermalConductivity wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - Assert.False(wattpermeterkelvin.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ThermalConductivity wattpermeterkelvin = ThermalConductivity.FromWattsPerMeterKelvin(1); - Assert.False(wattpermeterkelvin.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ThermalConductivityUnit.Undefined, ThermalConductivity.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ThermalConductivityUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ThermalConductivityUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/ThermalResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ThermalResistanceTestsBase.g.cs deleted file mode 100644 index 12b4acc98b..0000000000 --- a/UnitsNet.Tests/GeneratedCode/ThermalResistanceTestsBase.g.cs +++ /dev/null @@ -1,264 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of ThermalResistance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ThermalResistanceTestsBase - { - protected abstract double HourSquareFeetDegreesFahrenheitPerBtuInOneSquareMeterKelvinPerKilowatt { get; } - protected abstract double SquareCentimeterHourDegreesCelsiusPerKilocalorieInOneSquareMeterKelvinPerKilowatt { get; } - protected abstract double SquareCentimeterKelvinsPerWattInOneSquareMeterKelvinPerKilowatt { get; } - protected abstract double SquareMeterDegreesCelsiusPerWattInOneSquareMeterKelvinPerKilowatt { get; } - protected abstract double SquareMeterKelvinsPerKilowattInOneSquareMeterKelvinPerKilowatt { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double HourSquareFeetDegreesFahrenheitPerBtuTolerance { get { return 1e-5; } } - protected virtual double SquareCentimeterHourDegreesCelsiusPerKilocalorieTolerance { get { return 1e-5; } } - protected virtual double SquareCentimeterKelvinsPerWattTolerance { get { return 1e-5; } } - protected virtual double SquareMeterDegreesCelsiusPerWattTolerance { get { return 1e-5; } } - protected virtual double SquareMeterKelvinsPerKilowattTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new ThermalResistance((double)0.0, ThermalResistanceUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ThermalResistance(double.PositiveInfinity, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt)); - Assert.Throws(() => new ThermalResistance(double.NegativeInfinity, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ThermalResistance(double.NaN, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt)); - } - - [Fact] - public void SquareMeterKelvinPerKilowattToThermalResistanceUnits() - { - ThermalResistance squaremeterkelvinperkilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - AssertEx.EqualTolerance(HourSquareFeetDegreesFahrenheitPerBtuInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.HourSquareFeetDegreesFahrenheitPerBtu, HourSquareFeetDegreesFahrenheitPerBtuTolerance); - AssertEx.EqualTolerance(SquareCentimeterHourDegreesCelsiusPerKilocalorieInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.SquareCentimeterHourDegreesCelsiusPerKilocalorie, SquareCentimeterHourDegreesCelsiusPerKilocalorieTolerance); - AssertEx.EqualTolerance(SquareCentimeterKelvinsPerWattInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.SquareCentimeterKelvinsPerWatt, SquareCentimeterKelvinsPerWattTolerance); - AssertEx.EqualTolerance(SquareMeterDegreesCelsiusPerWattInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.SquareMeterDegreesCelsiusPerWatt, SquareMeterDegreesCelsiusPerWattTolerance); - AssertEx.EqualTolerance(SquareMeterKelvinsPerKilowattInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, ThermalResistance.From(1, ThermalResistanceUnit.HourSquareFeetDegreeFahrenheitPerBtu).HourSquareFeetDegreesFahrenheitPerBtu, HourSquareFeetDegreesFahrenheitPerBtuTolerance); - AssertEx.EqualTolerance(1, ThermalResistance.From(1, ThermalResistanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie).SquareCentimeterHourDegreesCelsiusPerKilocalorie, SquareCentimeterHourDegreesCelsiusPerKilocalorieTolerance); - AssertEx.EqualTolerance(1, ThermalResistance.From(1, ThermalResistanceUnit.SquareCentimeterKelvinPerWatt).SquareCentimeterKelvinsPerWatt, SquareCentimeterKelvinsPerWattTolerance); - AssertEx.EqualTolerance(1, ThermalResistance.From(1, ThermalResistanceUnit.SquareMeterDegreeCelsiusPerWatt).SquareMeterDegreesCelsiusPerWatt, SquareMeterDegreesCelsiusPerWattTolerance); - AssertEx.EqualTolerance(1, ThermalResistance.From(1, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt).SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - } - - [Fact] - public void FromSquareMeterKelvinsPerKilowatt_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ThermalResistance.FromSquareMeterKelvinsPerKilowatt(double.PositiveInfinity)); - Assert.Throws(() => ThermalResistance.FromSquareMeterKelvinsPerKilowatt(double.NegativeInfinity)); - } - - [Fact] - public void FromSquareMeterKelvinsPerKilowatt_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ThermalResistance.FromSquareMeterKelvinsPerKilowatt(double.NaN)); - } - - [Fact] - public void As() - { - var squaremeterkelvinperkilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - AssertEx.EqualTolerance(HourSquareFeetDegreesFahrenheitPerBtuInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.As(ThermalResistanceUnit.HourSquareFeetDegreeFahrenheitPerBtu), HourSquareFeetDegreesFahrenheitPerBtuTolerance); - AssertEx.EqualTolerance(SquareCentimeterHourDegreesCelsiusPerKilocalorieInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.As(ThermalResistanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie), SquareCentimeterHourDegreesCelsiusPerKilocalorieTolerance); - AssertEx.EqualTolerance(SquareCentimeterKelvinsPerWattInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.As(ThermalResistanceUnit.SquareCentimeterKelvinPerWatt), SquareCentimeterKelvinsPerWattTolerance); - AssertEx.EqualTolerance(SquareMeterDegreesCelsiusPerWattInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.As(ThermalResistanceUnit.SquareMeterDegreeCelsiusPerWatt), SquareMeterDegreesCelsiusPerWattTolerance); - AssertEx.EqualTolerance(SquareMeterKelvinsPerKilowattInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.As(ThermalResistanceUnit.SquareMeterKelvinPerKilowatt), SquareMeterKelvinsPerKilowattTolerance); - } - - [Fact] - public void ToUnit() - { - var squaremeterkelvinperkilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - - var hoursquarefeetdegreefahrenheitperbtuQuantity = squaremeterkelvinperkilowatt.ToUnit(ThermalResistanceUnit.HourSquareFeetDegreeFahrenheitPerBtu); - AssertEx.EqualTolerance(HourSquareFeetDegreesFahrenheitPerBtuInOneSquareMeterKelvinPerKilowatt, (double)hoursquarefeetdegreefahrenheitperbtuQuantity.Value, HourSquareFeetDegreesFahrenheitPerBtuTolerance); - Assert.Equal(ThermalResistanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, hoursquarefeetdegreefahrenheitperbtuQuantity.Unit); - - var squarecentimeterhourdegreecelsiusperkilocalorieQuantity = squaremeterkelvinperkilowatt.ToUnit(ThermalResistanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie); - AssertEx.EqualTolerance(SquareCentimeterHourDegreesCelsiusPerKilocalorieInOneSquareMeterKelvinPerKilowatt, (double)squarecentimeterhourdegreecelsiusperkilocalorieQuantity.Value, SquareCentimeterHourDegreesCelsiusPerKilocalorieTolerance); - Assert.Equal(ThermalResistanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, squarecentimeterhourdegreecelsiusperkilocalorieQuantity.Unit); - - var squarecentimeterkelvinperwattQuantity = squaremeterkelvinperkilowatt.ToUnit(ThermalResistanceUnit.SquareCentimeterKelvinPerWatt); - AssertEx.EqualTolerance(SquareCentimeterKelvinsPerWattInOneSquareMeterKelvinPerKilowatt, (double)squarecentimeterkelvinperwattQuantity.Value, SquareCentimeterKelvinsPerWattTolerance); - Assert.Equal(ThermalResistanceUnit.SquareCentimeterKelvinPerWatt, squarecentimeterkelvinperwattQuantity.Unit); - - var squaremeterdegreecelsiusperwattQuantity = squaremeterkelvinperkilowatt.ToUnit(ThermalResistanceUnit.SquareMeterDegreeCelsiusPerWatt); - AssertEx.EqualTolerance(SquareMeterDegreesCelsiusPerWattInOneSquareMeterKelvinPerKilowatt, (double)squaremeterdegreecelsiusperwattQuantity.Value, SquareMeterDegreesCelsiusPerWattTolerance); - Assert.Equal(ThermalResistanceUnit.SquareMeterDegreeCelsiusPerWatt, squaremeterdegreecelsiusperwattQuantity.Unit); - - var squaremeterkelvinperkilowattQuantity = squaremeterkelvinperkilowatt.ToUnit(ThermalResistanceUnit.SquareMeterKelvinPerKilowatt); - AssertEx.EqualTolerance(SquareMeterKelvinsPerKilowattInOneSquareMeterKelvinPerKilowatt, (double)squaremeterkelvinperkilowattQuantity.Value, SquareMeterKelvinsPerKilowattTolerance); - Assert.Equal(ThermalResistanceUnit.SquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowattQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ThermalResistance squaremeterkelvinperkilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - AssertEx.EqualTolerance(1, ThermalResistance.FromHourSquareFeetDegreesFahrenheitPerBtu(squaremeterkelvinperkilowatt.HourSquareFeetDegreesFahrenheitPerBtu).SquareMeterKelvinsPerKilowatt, HourSquareFeetDegreesFahrenheitPerBtuTolerance); - AssertEx.EqualTolerance(1, ThermalResistance.FromSquareCentimeterHourDegreesCelsiusPerKilocalorie(squaremeterkelvinperkilowatt.SquareCentimeterHourDegreesCelsiusPerKilocalorie).SquareMeterKelvinsPerKilowatt, SquareCentimeterHourDegreesCelsiusPerKilocalorieTolerance); - AssertEx.EqualTolerance(1, ThermalResistance.FromSquareCentimeterKelvinsPerWatt(squaremeterkelvinperkilowatt.SquareCentimeterKelvinsPerWatt).SquareMeterKelvinsPerKilowatt, SquareCentimeterKelvinsPerWattTolerance); - AssertEx.EqualTolerance(1, ThermalResistance.FromSquareMeterDegreesCelsiusPerWatt(squaremeterkelvinperkilowatt.SquareMeterDegreesCelsiusPerWatt).SquareMeterKelvinsPerKilowatt, SquareMeterDegreesCelsiusPerWattTolerance); - AssertEx.EqualTolerance(1, ThermalResistance.FromSquareMeterKelvinsPerKilowatt(squaremeterkelvinperkilowatt.SquareMeterKelvinsPerKilowatt).SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ThermalResistance v = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - AssertEx.EqualTolerance(-1, -v.SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - AssertEx.EqualTolerance(2, (ThermalResistance.FromSquareMeterKelvinsPerKilowatt(3)-v).SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - AssertEx.EqualTolerance(2, (v + v).SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - AssertEx.EqualTolerance(10, (v*10).SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - AssertEx.EqualTolerance(10, (10*v).SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - AssertEx.EqualTolerance(2, (ThermalResistance.FromSquareMeterKelvinsPerKilowatt(10)/5).SquareMeterKelvinsPerKilowatt, SquareMeterKelvinsPerKilowattTolerance); - AssertEx.EqualTolerance(2, ThermalResistance.FromSquareMeterKelvinsPerKilowatt(10)/ThermalResistance.FromSquareMeterKelvinsPerKilowatt(5), SquareMeterKelvinsPerKilowattTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ThermalResistance oneSquareMeterKelvinPerKilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - ThermalResistance twoSquareMeterKelvinsPerKilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(2); - - Assert.True(oneSquareMeterKelvinPerKilowatt < twoSquareMeterKelvinsPerKilowatt); - Assert.True(oneSquareMeterKelvinPerKilowatt <= twoSquareMeterKelvinsPerKilowatt); - Assert.True(twoSquareMeterKelvinsPerKilowatt > oneSquareMeterKelvinPerKilowatt); - Assert.True(twoSquareMeterKelvinsPerKilowatt >= oneSquareMeterKelvinPerKilowatt); - - Assert.False(oneSquareMeterKelvinPerKilowatt > twoSquareMeterKelvinsPerKilowatt); - Assert.False(oneSquareMeterKelvinPerKilowatt >= twoSquareMeterKelvinsPerKilowatt); - Assert.False(twoSquareMeterKelvinsPerKilowatt < oneSquareMeterKelvinPerKilowatt); - Assert.False(twoSquareMeterKelvinsPerKilowatt <= oneSquareMeterKelvinPerKilowatt); - } - - [Fact] - public void CompareToIsImplemented() - { - ThermalResistance squaremeterkelvinperkilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - Assert.Equal(0, squaremeterkelvinperkilowatt.CompareTo(squaremeterkelvinperkilowatt)); - Assert.True(squaremeterkelvinperkilowatt.CompareTo(ThermalResistance.Zero) > 0); - Assert.True(ThermalResistance.Zero.CompareTo(squaremeterkelvinperkilowatt) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ThermalResistance squaremeterkelvinperkilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - Assert.Throws(() => squaremeterkelvinperkilowatt.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ThermalResistance squaremeterkelvinperkilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - Assert.Throws(() => squaremeterkelvinperkilowatt.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - ThermalResistance v = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - Assert.True(v.Equals(ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1), SquareMeterKelvinsPerKilowattTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ThermalResistance.Zero, SquareMeterKelvinsPerKilowattTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ThermalResistance squaremeterkelvinperkilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - Assert.False(squaremeterkelvinperkilowatt.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ThermalResistance squaremeterkelvinperkilowatt = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1); - Assert.False(squaremeterkelvinperkilowatt.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(ThermalResistanceUnit.Undefined, ThermalResistance.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ThermalResistanceUnit)).Cast(); - foreach(var unit in units) - { - if(unit == ThermalResistanceUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/TorqueTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TorqueTestsBase.g.cs deleted file mode 100644 index 3bba357325..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TorqueTestsBase.g.cs +++ /dev/null @@ -1,424 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Torque. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TorqueTestsBase - { - protected abstract double KilogramForceCentimetersInOneNewtonMeter { get; } - protected abstract double KilogramForceMetersInOneNewtonMeter { get; } - protected abstract double KilogramForceMillimetersInOneNewtonMeter { get; } - protected abstract double KilonewtonCentimetersInOneNewtonMeter { get; } - protected abstract double KilonewtonMetersInOneNewtonMeter { get; } - protected abstract double KilonewtonMillimetersInOneNewtonMeter { get; } - protected abstract double KilopoundForceFeetInOneNewtonMeter { get; } - protected abstract double KilopoundForceInchesInOneNewtonMeter { get; } - protected abstract double MeganewtonCentimetersInOneNewtonMeter { get; } - protected abstract double MeganewtonMetersInOneNewtonMeter { get; } - protected abstract double MeganewtonMillimetersInOneNewtonMeter { get; } - protected abstract double MegapoundForceFeetInOneNewtonMeter { get; } - protected abstract double MegapoundForceInchesInOneNewtonMeter { get; } - protected abstract double NewtonCentimetersInOneNewtonMeter { get; } - protected abstract double NewtonMetersInOneNewtonMeter { get; } - protected abstract double NewtonMillimetersInOneNewtonMeter { get; } - protected abstract double PoundForceFeetInOneNewtonMeter { get; } - protected abstract double PoundForceInchesInOneNewtonMeter { get; } - protected abstract double TonneForceCentimetersInOneNewtonMeter { get; } - protected abstract double TonneForceMetersInOneNewtonMeter { get; } - protected abstract double TonneForceMillimetersInOneNewtonMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilogramForceCentimetersTolerance { get { return 1e-5; } } - protected virtual double KilogramForceMetersTolerance { get { return 1e-5; } } - protected virtual double KilogramForceMillimetersTolerance { get { return 1e-5; } } - protected virtual double KilonewtonCentimetersTolerance { get { return 1e-5; } } - protected virtual double KilonewtonMetersTolerance { get { return 1e-5; } } - protected virtual double KilonewtonMillimetersTolerance { get { return 1e-5; } } - protected virtual double KilopoundForceFeetTolerance { get { return 1e-5; } } - protected virtual double KilopoundForceInchesTolerance { get { return 1e-5; } } - protected virtual double MeganewtonCentimetersTolerance { get { return 1e-5; } } - protected virtual double MeganewtonMetersTolerance { get { return 1e-5; } } - protected virtual double MeganewtonMillimetersTolerance { get { return 1e-5; } } - protected virtual double MegapoundForceFeetTolerance { get { return 1e-5; } } - protected virtual double MegapoundForceInchesTolerance { get { return 1e-5; } } - protected virtual double NewtonCentimetersTolerance { get { return 1e-5; } } - protected virtual double NewtonMetersTolerance { get { return 1e-5; } } - protected virtual double NewtonMillimetersTolerance { get { return 1e-5; } } - protected virtual double PoundForceFeetTolerance { get { return 1e-5; } } - protected virtual double PoundForceInchesTolerance { get { return 1e-5; } } - protected virtual double TonneForceCentimetersTolerance { get { return 1e-5; } } - protected virtual double TonneForceMetersTolerance { get { return 1e-5; } } - protected virtual double TonneForceMillimetersTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Torque((double)0.0, TorqueUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Torque(double.PositiveInfinity, TorqueUnit.NewtonMeter)); - Assert.Throws(() => new Torque(double.NegativeInfinity, TorqueUnit.NewtonMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Torque(double.NaN, TorqueUnit.NewtonMeter)); - } - - [Fact] - public void NewtonMeterToTorqueUnits() - { - Torque newtonmeter = Torque.FromNewtonMeters(1); - AssertEx.EqualTolerance(KilogramForceCentimetersInOneNewtonMeter, newtonmeter.KilogramForceCentimeters, KilogramForceCentimetersTolerance); - AssertEx.EqualTolerance(KilogramForceMetersInOneNewtonMeter, newtonmeter.KilogramForceMeters, KilogramForceMetersTolerance); - AssertEx.EqualTolerance(KilogramForceMillimetersInOneNewtonMeter, newtonmeter.KilogramForceMillimeters, KilogramForceMillimetersTolerance); - AssertEx.EqualTolerance(KilonewtonCentimetersInOneNewtonMeter, newtonmeter.KilonewtonCentimeters, KilonewtonCentimetersTolerance); - AssertEx.EqualTolerance(KilonewtonMetersInOneNewtonMeter, newtonmeter.KilonewtonMeters, KilonewtonMetersTolerance); - AssertEx.EqualTolerance(KilonewtonMillimetersInOneNewtonMeter, newtonmeter.KilonewtonMillimeters, KilonewtonMillimetersTolerance); - AssertEx.EqualTolerance(KilopoundForceFeetInOneNewtonMeter, newtonmeter.KilopoundForceFeet, KilopoundForceFeetTolerance); - AssertEx.EqualTolerance(KilopoundForceInchesInOneNewtonMeter, newtonmeter.KilopoundForceInches, KilopoundForceInchesTolerance); - AssertEx.EqualTolerance(MeganewtonCentimetersInOneNewtonMeter, newtonmeter.MeganewtonCentimeters, MeganewtonCentimetersTolerance); - AssertEx.EqualTolerance(MeganewtonMetersInOneNewtonMeter, newtonmeter.MeganewtonMeters, MeganewtonMetersTolerance); - AssertEx.EqualTolerance(MeganewtonMillimetersInOneNewtonMeter, newtonmeter.MeganewtonMillimeters, MeganewtonMillimetersTolerance); - AssertEx.EqualTolerance(MegapoundForceFeetInOneNewtonMeter, newtonmeter.MegapoundForceFeet, MegapoundForceFeetTolerance); - AssertEx.EqualTolerance(MegapoundForceInchesInOneNewtonMeter, newtonmeter.MegapoundForceInches, MegapoundForceInchesTolerance); - AssertEx.EqualTolerance(NewtonCentimetersInOneNewtonMeter, newtonmeter.NewtonCentimeters, NewtonCentimetersTolerance); - AssertEx.EqualTolerance(NewtonMetersInOneNewtonMeter, newtonmeter.NewtonMeters, NewtonMetersTolerance); - AssertEx.EqualTolerance(NewtonMillimetersInOneNewtonMeter, newtonmeter.NewtonMillimeters, NewtonMillimetersTolerance); - AssertEx.EqualTolerance(PoundForceFeetInOneNewtonMeter, newtonmeter.PoundForceFeet, PoundForceFeetTolerance); - AssertEx.EqualTolerance(PoundForceInchesInOneNewtonMeter, newtonmeter.PoundForceInches, PoundForceInchesTolerance); - AssertEx.EqualTolerance(TonneForceCentimetersInOneNewtonMeter, newtonmeter.TonneForceCentimeters, TonneForceCentimetersTolerance); - AssertEx.EqualTolerance(TonneForceMetersInOneNewtonMeter, newtonmeter.TonneForceMeters, TonneForceMetersTolerance); - AssertEx.EqualTolerance(TonneForceMillimetersInOneNewtonMeter, newtonmeter.TonneForceMillimeters, TonneForceMillimetersTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.KilogramForceCentimeter).KilogramForceCentimeters, KilogramForceCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.KilogramForceMeter).KilogramForceMeters, KilogramForceMetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.KilogramForceMillimeter).KilogramForceMillimeters, KilogramForceMillimetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.KilonewtonCentimeter).KilonewtonCentimeters, KilonewtonCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.KilonewtonMeter).KilonewtonMeters, KilonewtonMetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.KilonewtonMillimeter).KilonewtonMillimeters, KilonewtonMillimetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.KilopoundForceFoot).KilopoundForceFeet, KilopoundForceFeetTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.KilopoundForceInch).KilopoundForceInches, KilopoundForceInchesTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.MeganewtonCentimeter).MeganewtonCentimeters, MeganewtonCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.MeganewtonMeter).MeganewtonMeters, MeganewtonMetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.MeganewtonMillimeter).MeganewtonMillimeters, MeganewtonMillimetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.MegapoundForceFoot).MegapoundForceFeet, MegapoundForceFeetTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.MegapoundForceInch).MegapoundForceInches, MegapoundForceInchesTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.NewtonCentimeter).NewtonCentimeters, NewtonCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.NewtonMeter).NewtonMeters, NewtonMetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.NewtonMillimeter).NewtonMillimeters, NewtonMillimetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.PoundForceFoot).PoundForceFeet, PoundForceFeetTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.PoundForceInch).PoundForceInches, PoundForceInchesTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.TonneForceCentimeter).TonneForceCentimeters, TonneForceCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.TonneForceMeter).TonneForceMeters, TonneForceMetersTolerance); - AssertEx.EqualTolerance(1, Torque.From(1, TorqueUnit.TonneForceMillimeter).TonneForceMillimeters, TonneForceMillimetersTolerance); - } - - [Fact] - public void FromNewtonMeters_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Torque.FromNewtonMeters(double.PositiveInfinity)); - Assert.Throws(() => Torque.FromNewtonMeters(double.NegativeInfinity)); - } - - [Fact] - public void FromNewtonMeters_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Torque.FromNewtonMeters(double.NaN)); - } - - [Fact] - public void As() - { - var newtonmeter = Torque.FromNewtonMeters(1); - AssertEx.EqualTolerance(KilogramForceCentimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.KilogramForceCentimeter), KilogramForceCentimetersTolerance); - AssertEx.EqualTolerance(KilogramForceMetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.KilogramForceMeter), KilogramForceMetersTolerance); - AssertEx.EqualTolerance(KilogramForceMillimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.KilogramForceMillimeter), KilogramForceMillimetersTolerance); - AssertEx.EqualTolerance(KilonewtonCentimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.KilonewtonCentimeter), KilonewtonCentimetersTolerance); - AssertEx.EqualTolerance(KilonewtonMetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.KilonewtonMeter), KilonewtonMetersTolerance); - AssertEx.EqualTolerance(KilonewtonMillimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.KilonewtonMillimeter), KilonewtonMillimetersTolerance); - AssertEx.EqualTolerance(KilopoundForceFeetInOneNewtonMeter, newtonmeter.As(TorqueUnit.KilopoundForceFoot), KilopoundForceFeetTolerance); - AssertEx.EqualTolerance(KilopoundForceInchesInOneNewtonMeter, newtonmeter.As(TorqueUnit.KilopoundForceInch), KilopoundForceInchesTolerance); - AssertEx.EqualTolerance(MeganewtonCentimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.MeganewtonCentimeter), MeganewtonCentimetersTolerance); - AssertEx.EqualTolerance(MeganewtonMetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.MeganewtonMeter), MeganewtonMetersTolerance); - AssertEx.EqualTolerance(MeganewtonMillimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.MeganewtonMillimeter), MeganewtonMillimetersTolerance); - AssertEx.EqualTolerance(MegapoundForceFeetInOneNewtonMeter, newtonmeter.As(TorqueUnit.MegapoundForceFoot), MegapoundForceFeetTolerance); - AssertEx.EqualTolerance(MegapoundForceInchesInOneNewtonMeter, newtonmeter.As(TorqueUnit.MegapoundForceInch), MegapoundForceInchesTolerance); - AssertEx.EqualTolerance(NewtonCentimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.NewtonCentimeter), NewtonCentimetersTolerance); - AssertEx.EqualTolerance(NewtonMetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.NewtonMeter), NewtonMetersTolerance); - AssertEx.EqualTolerance(NewtonMillimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.NewtonMillimeter), NewtonMillimetersTolerance); - AssertEx.EqualTolerance(PoundForceFeetInOneNewtonMeter, newtonmeter.As(TorqueUnit.PoundForceFoot), PoundForceFeetTolerance); - AssertEx.EqualTolerance(PoundForceInchesInOneNewtonMeter, newtonmeter.As(TorqueUnit.PoundForceInch), PoundForceInchesTolerance); - AssertEx.EqualTolerance(TonneForceCentimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.TonneForceCentimeter), TonneForceCentimetersTolerance); - AssertEx.EqualTolerance(TonneForceMetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.TonneForceMeter), TonneForceMetersTolerance); - AssertEx.EqualTolerance(TonneForceMillimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.TonneForceMillimeter), TonneForceMillimetersTolerance); - } - - [Fact] - public void ToUnit() - { - var newtonmeter = Torque.FromNewtonMeters(1); - - var kilogramforcecentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilogramForceCentimeter); - AssertEx.EqualTolerance(KilogramForceCentimetersInOneNewtonMeter, (double)kilogramforcecentimeterQuantity.Value, KilogramForceCentimetersTolerance); - Assert.Equal(TorqueUnit.KilogramForceCentimeter, kilogramforcecentimeterQuantity.Unit); - - var kilogramforcemeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilogramForceMeter); - AssertEx.EqualTolerance(KilogramForceMetersInOneNewtonMeter, (double)kilogramforcemeterQuantity.Value, KilogramForceMetersTolerance); - Assert.Equal(TorqueUnit.KilogramForceMeter, kilogramforcemeterQuantity.Unit); - - var kilogramforcemillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilogramForceMillimeter); - AssertEx.EqualTolerance(KilogramForceMillimetersInOneNewtonMeter, (double)kilogramforcemillimeterQuantity.Value, KilogramForceMillimetersTolerance); - Assert.Equal(TorqueUnit.KilogramForceMillimeter, kilogramforcemillimeterQuantity.Unit); - - var kilonewtoncentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilonewtonCentimeter); - AssertEx.EqualTolerance(KilonewtonCentimetersInOneNewtonMeter, (double)kilonewtoncentimeterQuantity.Value, KilonewtonCentimetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonCentimeter, kilonewtoncentimeterQuantity.Unit); - - var kilonewtonmeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilonewtonMeter); - AssertEx.EqualTolerance(KilonewtonMetersInOneNewtonMeter, (double)kilonewtonmeterQuantity.Value, KilonewtonMetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonMeter, kilonewtonmeterQuantity.Unit); - - var kilonewtonmillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilonewtonMillimeter); - AssertEx.EqualTolerance(KilonewtonMillimetersInOneNewtonMeter, (double)kilonewtonmillimeterQuantity.Value, KilonewtonMillimetersTolerance); - Assert.Equal(TorqueUnit.KilonewtonMillimeter, kilonewtonmillimeterQuantity.Unit); - - var kilopoundforcefootQuantity = newtonmeter.ToUnit(TorqueUnit.KilopoundForceFoot); - AssertEx.EqualTolerance(KilopoundForceFeetInOneNewtonMeter, (double)kilopoundforcefootQuantity.Value, KilopoundForceFeetTolerance); - Assert.Equal(TorqueUnit.KilopoundForceFoot, kilopoundforcefootQuantity.Unit); - - var kilopoundforceinchQuantity = newtonmeter.ToUnit(TorqueUnit.KilopoundForceInch); - AssertEx.EqualTolerance(KilopoundForceInchesInOneNewtonMeter, (double)kilopoundforceinchQuantity.Value, KilopoundForceInchesTolerance); - Assert.Equal(TorqueUnit.KilopoundForceInch, kilopoundforceinchQuantity.Unit); - - var meganewtoncentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.MeganewtonCentimeter); - AssertEx.EqualTolerance(MeganewtonCentimetersInOneNewtonMeter, (double)meganewtoncentimeterQuantity.Value, MeganewtonCentimetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonCentimeter, meganewtoncentimeterQuantity.Unit); - - var meganewtonmeterQuantity = newtonmeter.ToUnit(TorqueUnit.MeganewtonMeter); - AssertEx.EqualTolerance(MeganewtonMetersInOneNewtonMeter, (double)meganewtonmeterQuantity.Value, MeganewtonMetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonMeter, meganewtonmeterQuantity.Unit); - - var meganewtonmillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.MeganewtonMillimeter); - AssertEx.EqualTolerance(MeganewtonMillimetersInOneNewtonMeter, (double)meganewtonmillimeterQuantity.Value, MeganewtonMillimetersTolerance); - Assert.Equal(TorqueUnit.MeganewtonMillimeter, meganewtonmillimeterQuantity.Unit); - - var megapoundforcefootQuantity = newtonmeter.ToUnit(TorqueUnit.MegapoundForceFoot); - AssertEx.EqualTolerance(MegapoundForceFeetInOneNewtonMeter, (double)megapoundforcefootQuantity.Value, MegapoundForceFeetTolerance); - Assert.Equal(TorqueUnit.MegapoundForceFoot, megapoundforcefootQuantity.Unit); - - var megapoundforceinchQuantity = newtonmeter.ToUnit(TorqueUnit.MegapoundForceInch); - AssertEx.EqualTolerance(MegapoundForceInchesInOneNewtonMeter, (double)megapoundforceinchQuantity.Value, MegapoundForceInchesTolerance); - Assert.Equal(TorqueUnit.MegapoundForceInch, megapoundforceinchQuantity.Unit); - - var newtoncentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.NewtonCentimeter); - AssertEx.EqualTolerance(NewtonCentimetersInOneNewtonMeter, (double)newtoncentimeterQuantity.Value, NewtonCentimetersTolerance); - Assert.Equal(TorqueUnit.NewtonCentimeter, newtoncentimeterQuantity.Unit); - - var newtonmeterQuantity = newtonmeter.ToUnit(TorqueUnit.NewtonMeter); - AssertEx.EqualTolerance(NewtonMetersInOneNewtonMeter, (double)newtonmeterQuantity.Value, NewtonMetersTolerance); - Assert.Equal(TorqueUnit.NewtonMeter, newtonmeterQuantity.Unit); - - var newtonmillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.NewtonMillimeter); - AssertEx.EqualTolerance(NewtonMillimetersInOneNewtonMeter, (double)newtonmillimeterQuantity.Value, NewtonMillimetersTolerance); - Assert.Equal(TorqueUnit.NewtonMillimeter, newtonmillimeterQuantity.Unit); - - var poundforcefootQuantity = newtonmeter.ToUnit(TorqueUnit.PoundForceFoot); - AssertEx.EqualTolerance(PoundForceFeetInOneNewtonMeter, (double)poundforcefootQuantity.Value, PoundForceFeetTolerance); - Assert.Equal(TorqueUnit.PoundForceFoot, poundforcefootQuantity.Unit); - - var poundforceinchQuantity = newtonmeter.ToUnit(TorqueUnit.PoundForceInch); - AssertEx.EqualTolerance(PoundForceInchesInOneNewtonMeter, (double)poundforceinchQuantity.Value, PoundForceInchesTolerance); - Assert.Equal(TorqueUnit.PoundForceInch, poundforceinchQuantity.Unit); - - var tonneforcecentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.TonneForceCentimeter); - AssertEx.EqualTolerance(TonneForceCentimetersInOneNewtonMeter, (double)tonneforcecentimeterQuantity.Value, TonneForceCentimetersTolerance); - Assert.Equal(TorqueUnit.TonneForceCentimeter, tonneforcecentimeterQuantity.Unit); - - var tonneforcemeterQuantity = newtonmeter.ToUnit(TorqueUnit.TonneForceMeter); - AssertEx.EqualTolerance(TonneForceMetersInOneNewtonMeter, (double)tonneforcemeterQuantity.Value, TonneForceMetersTolerance); - Assert.Equal(TorqueUnit.TonneForceMeter, tonneforcemeterQuantity.Unit); - - var tonneforcemillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.TonneForceMillimeter); - AssertEx.EqualTolerance(TonneForceMillimetersInOneNewtonMeter, (double)tonneforcemillimeterQuantity.Value, TonneForceMillimetersTolerance); - Assert.Equal(TorqueUnit.TonneForceMillimeter, tonneforcemillimeterQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Torque newtonmeter = Torque.FromNewtonMeters(1); - AssertEx.EqualTolerance(1, Torque.FromKilogramForceCentimeters(newtonmeter.KilogramForceCentimeters).NewtonMeters, KilogramForceCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromKilogramForceMeters(newtonmeter.KilogramForceMeters).NewtonMeters, KilogramForceMetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromKilogramForceMillimeters(newtonmeter.KilogramForceMillimeters).NewtonMeters, KilogramForceMillimetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromKilonewtonCentimeters(newtonmeter.KilonewtonCentimeters).NewtonMeters, KilonewtonCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromKilonewtonMeters(newtonmeter.KilonewtonMeters).NewtonMeters, KilonewtonMetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromKilonewtonMillimeters(newtonmeter.KilonewtonMillimeters).NewtonMeters, KilonewtonMillimetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromKilopoundForceFeet(newtonmeter.KilopoundForceFeet).NewtonMeters, KilopoundForceFeetTolerance); - AssertEx.EqualTolerance(1, Torque.FromKilopoundForceInches(newtonmeter.KilopoundForceInches).NewtonMeters, KilopoundForceInchesTolerance); - AssertEx.EqualTolerance(1, Torque.FromMeganewtonCentimeters(newtonmeter.MeganewtonCentimeters).NewtonMeters, MeganewtonCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromMeganewtonMeters(newtonmeter.MeganewtonMeters).NewtonMeters, MeganewtonMetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromMeganewtonMillimeters(newtonmeter.MeganewtonMillimeters).NewtonMeters, MeganewtonMillimetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromMegapoundForceFeet(newtonmeter.MegapoundForceFeet).NewtonMeters, MegapoundForceFeetTolerance); - AssertEx.EqualTolerance(1, Torque.FromMegapoundForceInches(newtonmeter.MegapoundForceInches).NewtonMeters, MegapoundForceInchesTolerance); - AssertEx.EqualTolerance(1, Torque.FromNewtonCentimeters(newtonmeter.NewtonCentimeters).NewtonMeters, NewtonCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromNewtonMeters(newtonmeter.NewtonMeters).NewtonMeters, NewtonMetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromNewtonMillimeters(newtonmeter.NewtonMillimeters).NewtonMeters, NewtonMillimetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromPoundForceFeet(newtonmeter.PoundForceFeet).NewtonMeters, PoundForceFeetTolerance); - AssertEx.EqualTolerance(1, Torque.FromPoundForceInches(newtonmeter.PoundForceInches).NewtonMeters, PoundForceInchesTolerance); - AssertEx.EqualTolerance(1, Torque.FromTonneForceCentimeters(newtonmeter.TonneForceCentimeters).NewtonMeters, TonneForceCentimetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromTonneForceMeters(newtonmeter.TonneForceMeters).NewtonMeters, TonneForceMetersTolerance); - AssertEx.EqualTolerance(1, Torque.FromTonneForceMillimeters(newtonmeter.TonneForceMillimeters).NewtonMeters, TonneForceMillimetersTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Torque v = Torque.FromNewtonMeters(1); - AssertEx.EqualTolerance(-1, -v.NewtonMeters, NewtonMetersTolerance); - AssertEx.EqualTolerance(2, (Torque.FromNewtonMeters(3)-v).NewtonMeters, NewtonMetersTolerance); - AssertEx.EqualTolerance(2, (v + v).NewtonMeters, NewtonMetersTolerance); - AssertEx.EqualTolerance(10, (v*10).NewtonMeters, NewtonMetersTolerance); - AssertEx.EqualTolerance(10, (10*v).NewtonMeters, NewtonMetersTolerance); - AssertEx.EqualTolerance(2, (Torque.FromNewtonMeters(10)/5).NewtonMeters, NewtonMetersTolerance); - AssertEx.EqualTolerance(2, Torque.FromNewtonMeters(10)/Torque.FromNewtonMeters(5), NewtonMetersTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Torque oneNewtonMeter = Torque.FromNewtonMeters(1); - Torque twoNewtonMeters = Torque.FromNewtonMeters(2); - - Assert.True(oneNewtonMeter < twoNewtonMeters); - Assert.True(oneNewtonMeter <= twoNewtonMeters); - Assert.True(twoNewtonMeters > oneNewtonMeter); - Assert.True(twoNewtonMeters >= oneNewtonMeter); - - Assert.False(oneNewtonMeter > twoNewtonMeters); - Assert.False(oneNewtonMeter >= twoNewtonMeters); - Assert.False(twoNewtonMeters < oneNewtonMeter); - Assert.False(twoNewtonMeters <= oneNewtonMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Torque newtonmeter = Torque.FromNewtonMeters(1); - Assert.Equal(0, newtonmeter.CompareTo(newtonmeter)); - Assert.True(newtonmeter.CompareTo(Torque.Zero) > 0); - Assert.True(Torque.Zero.CompareTo(newtonmeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Torque newtonmeter = Torque.FromNewtonMeters(1); - Assert.Throws(() => newtonmeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Torque newtonmeter = Torque.FromNewtonMeters(1); - Assert.Throws(() => newtonmeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Torque v = Torque.FromNewtonMeters(1); - Assert.True(v.Equals(Torque.FromNewtonMeters(1), NewtonMetersTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Torque.Zero, NewtonMetersTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Torque newtonmeter = Torque.FromNewtonMeters(1); - Assert.False(newtonmeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Torque newtonmeter = Torque.FromNewtonMeters(1); - Assert.False(newtonmeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(TorqueUnit.Undefined, Torque.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(TorqueUnit)).Cast(); - foreach(var unit in units) - { - if(unit == TorqueUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/VitaminATestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/VitaminATestsBase.g.cs deleted file mode 100644 index 8558740f27..0000000000 --- a/UnitsNet.Tests/GeneratedCode/VitaminATestsBase.g.cs +++ /dev/null @@ -1,224 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of VitaminA. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class VitaminATestsBase - { - protected abstract double InternationalUnitsInOneInternationalUnit { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double InternationalUnitsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new VitaminA((double)0.0, VitaminAUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new VitaminA(double.PositiveInfinity, VitaminAUnit.InternationalUnit)); - Assert.Throws(() => new VitaminA(double.NegativeInfinity, VitaminAUnit.InternationalUnit)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new VitaminA(double.NaN, VitaminAUnit.InternationalUnit)); - } - - [Fact] - public void InternationalUnitToVitaminAUnits() - { - VitaminA internationalunit = VitaminA.FromInternationalUnits(1); - AssertEx.EqualTolerance(InternationalUnitsInOneInternationalUnit, internationalunit.InternationalUnits, InternationalUnitsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, VitaminA.From(1, VitaminAUnit.InternationalUnit).InternationalUnits, InternationalUnitsTolerance); - } - - [Fact] - public void FromInternationalUnits_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => VitaminA.FromInternationalUnits(double.PositiveInfinity)); - Assert.Throws(() => VitaminA.FromInternationalUnits(double.NegativeInfinity)); - } - - [Fact] - public void FromInternationalUnits_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => VitaminA.FromInternationalUnits(double.NaN)); - } - - [Fact] - public void As() - { - var internationalunit = VitaminA.FromInternationalUnits(1); - AssertEx.EqualTolerance(InternationalUnitsInOneInternationalUnit, internationalunit.As(VitaminAUnit.InternationalUnit), InternationalUnitsTolerance); - } - - [Fact] - public void ToUnit() - { - var internationalunit = VitaminA.FromInternationalUnits(1); - - var internationalunitQuantity = internationalunit.ToUnit(VitaminAUnit.InternationalUnit); - AssertEx.EqualTolerance(InternationalUnitsInOneInternationalUnit, (double)internationalunitQuantity.Value, InternationalUnitsTolerance); - Assert.Equal(VitaminAUnit.InternationalUnit, internationalunitQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - VitaminA internationalunit = VitaminA.FromInternationalUnits(1); - AssertEx.EqualTolerance(1, VitaminA.FromInternationalUnits(internationalunit.InternationalUnits).InternationalUnits, InternationalUnitsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - VitaminA v = VitaminA.FromInternationalUnits(1); - AssertEx.EqualTolerance(-1, -v.InternationalUnits, InternationalUnitsTolerance); - AssertEx.EqualTolerance(2, (VitaminA.FromInternationalUnits(3)-v).InternationalUnits, InternationalUnitsTolerance); - AssertEx.EqualTolerance(2, (v + v).InternationalUnits, InternationalUnitsTolerance); - AssertEx.EqualTolerance(10, (v*10).InternationalUnits, InternationalUnitsTolerance); - AssertEx.EqualTolerance(10, (10*v).InternationalUnits, InternationalUnitsTolerance); - AssertEx.EqualTolerance(2, (VitaminA.FromInternationalUnits(10)/5).InternationalUnits, InternationalUnitsTolerance); - AssertEx.EqualTolerance(2, VitaminA.FromInternationalUnits(10)/VitaminA.FromInternationalUnits(5), InternationalUnitsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - VitaminA oneInternationalUnit = VitaminA.FromInternationalUnits(1); - VitaminA twoInternationalUnits = VitaminA.FromInternationalUnits(2); - - Assert.True(oneInternationalUnit < twoInternationalUnits); - Assert.True(oneInternationalUnit <= twoInternationalUnits); - Assert.True(twoInternationalUnits > oneInternationalUnit); - Assert.True(twoInternationalUnits >= oneInternationalUnit); - - Assert.False(oneInternationalUnit > twoInternationalUnits); - Assert.False(oneInternationalUnit >= twoInternationalUnits); - Assert.False(twoInternationalUnits < oneInternationalUnit); - Assert.False(twoInternationalUnits <= oneInternationalUnit); - } - - [Fact] - public void CompareToIsImplemented() - { - VitaminA internationalunit = VitaminA.FromInternationalUnits(1); - Assert.Equal(0, internationalunit.CompareTo(internationalunit)); - Assert.True(internationalunit.CompareTo(VitaminA.Zero) > 0); - Assert.True(VitaminA.Zero.CompareTo(internationalunit) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - VitaminA internationalunit = VitaminA.FromInternationalUnits(1); - Assert.Throws(() => internationalunit.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - VitaminA internationalunit = VitaminA.FromInternationalUnits(1); - Assert.Throws(() => internationalunit.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - VitaminA v = VitaminA.FromInternationalUnits(1); - Assert.True(v.Equals(VitaminA.FromInternationalUnits(1), InternationalUnitsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(VitaminA.Zero, InternationalUnitsTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - VitaminA internationalunit = VitaminA.FromInternationalUnits(1); - Assert.False(internationalunit.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - VitaminA internationalunit = VitaminA.FromInternationalUnits(1); - Assert.False(internationalunit.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(VitaminAUnit.Undefined, VitaminA.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(VitaminAUnit)).Cast(); - foreach(var unit in units) - { - if(unit == VitaminAUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/VolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/VolumeFlowTestsBase.g.cs deleted file mode 100644 index 918bfb736d..0000000000 --- a/UnitsNet.Tests/GeneratedCode/VolumeFlowTestsBase.g.cs +++ /dev/null @@ -1,474 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of VolumeFlow. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class VolumeFlowTestsBase - { - protected abstract double CentilitersPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double CubicDecimetersPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double CubicFeetPerHourInOneCubicMeterPerSecond { get; } - protected abstract double CubicFeetPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double CubicFeetPerSecondInOneCubicMeterPerSecond { get; } - protected abstract double CubicMetersPerHourInOneCubicMeterPerSecond { get; } - protected abstract double CubicMetersPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double CubicMetersPerSecondInOneCubicMeterPerSecond { get; } - protected abstract double CubicYardsPerHourInOneCubicMeterPerSecond { get; } - protected abstract double CubicYardsPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double CubicYardsPerSecondInOneCubicMeterPerSecond { get; } - protected abstract double DecilitersPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double KilolitersPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double LitersPerHourInOneCubicMeterPerSecond { get; } - protected abstract double LitersPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double LitersPerSecondInOneCubicMeterPerSecond { get; } - protected abstract double MicrolitersPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double MillilitersPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double MillionUsGallonsPerDayInOneCubicMeterPerSecond { get; } - protected abstract double NanolitersPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double OilBarrelsPerDayInOneCubicMeterPerSecond { get; } - protected abstract double OilBarrelsPerHourInOneCubicMeterPerSecond { get; } - protected abstract double OilBarrelsPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double UsGallonsPerHourInOneCubicMeterPerSecond { get; } - protected abstract double UsGallonsPerMinuteInOneCubicMeterPerSecond { get; } - protected abstract double UsGallonsPerSecondInOneCubicMeterPerSecond { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double CentilitersPerMinuteTolerance { get { return 1e-5; } } - protected virtual double CubicDecimetersPerMinuteTolerance { get { return 1e-5; } } - protected virtual double CubicFeetPerHourTolerance { get { return 1e-5; } } - protected virtual double CubicFeetPerMinuteTolerance { get { return 1e-5; } } - protected virtual double CubicFeetPerSecondTolerance { get { return 1e-5; } } - protected virtual double CubicMetersPerHourTolerance { get { return 1e-5; } } - protected virtual double CubicMetersPerMinuteTolerance { get { return 1e-5; } } - protected virtual double CubicMetersPerSecondTolerance { get { return 1e-5; } } - protected virtual double CubicYardsPerHourTolerance { get { return 1e-5; } } - protected virtual double CubicYardsPerMinuteTolerance { get { return 1e-5; } } - protected virtual double CubicYardsPerSecondTolerance { get { return 1e-5; } } - protected virtual double DecilitersPerMinuteTolerance { get { return 1e-5; } } - protected virtual double KilolitersPerMinuteTolerance { get { return 1e-5; } } - protected virtual double LitersPerHourTolerance { get { return 1e-5; } } - protected virtual double LitersPerMinuteTolerance { get { return 1e-5; } } - protected virtual double LitersPerSecondTolerance { get { return 1e-5; } } - protected virtual double MicrolitersPerMinuteTolerance { get { return 1e-5; } } - protected virtual double MillilitersPerMinuteTolerance { get { return 1e-5; } } - protected virtual double MillionUsGallonsPerDayTolerance { get { return 1e-5; } } - protected virtual double NanolitersPerMinuteTolerance { get { return 1e-5; } } - protected virtual double OilBarrelsPerDayTolerance { get { return 1e-5; } } - protected virtual double OilBarrelsPerHourTolerance { get { return 1e-5; } } - protected virtual double OilBarrelsPerMinuteTolerance { get { return 1e-5; } } - protected virtual double UsGallonsPerHourTolerance { get { return 1e-5; } } - protected virtual double UsGallonsPerMinuteTolerance { get { return 1e-5; } } - protected virtual double UsGallonsPerSecondTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new VolumeFlow((double)0.0, VolumeFlowUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new VolumeFlow(double.PositiveInfinity, VolumeFlowUnit.CubicMeterPerSecond)); - Assert.Throws(() => new VolumeFlow(double.NegativeInfinity, VolumeFlowUnit.CubicMeterPerSecond)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new VolumeFlow(double.NaN, VolumeFlowUnit.CubicMeterPerSecond)); - } - - [Fact] - public void CubicMeterPerSecondToVolumeFlowUnits() - { - VolumeFlow cubicmeterpersecond = VolumeFlow.FromCubicMetersPerSecond(1); - AssertEx.EqualTolerance(CentilitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.CentilitersPerMinute, CentilitersPerMinuteTolerance); - AssertEx.EqualTolerance(CubicDecimetersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.CubicDecimetersPerMinute, CubicDecimetersPerMinuteTolerance); - AssertEx.EqualTolerance(CubicFeetPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.CubicFeetPerHour, CubicFeetPerHourTolerance); - AssertEx.EqualTolerance(CubicFeetPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.CubicFeetPerMinute, CubicFeetPerMinuteTolerance); - AssertEx.EqualTolerance(CubicFeetPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.CubicFeetPerSecond, CubicFeetPerSecondTolerance); - AssertEx.EqualTolerance(CubicMetersPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.CubicMetersPerHour, CubicMetersPerHourTolerance); - AssertEx.EqualTolerance(CubicMetersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.CubicMetersPerMinute, CubicMetersPerMinuteTolerance); - AssertEx.EqualTolerance(CubicMetersPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.CubicMetersPerSecond, CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(CubicYardsPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.CubicYardsPerHour, CubicYardsPerHourTolerance); - AssertEx.EqualTolerance(CubicYardsPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.CubicYardsPerMinute, CubicYardsPerMinuteTolerance); - AssertEx.EqualTolerance(CubicYardsPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.CubicYardsPerSecond, CubicYardsPerSecondTolerance); - AssertEx.EqualTolerance(DecilitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.DecilitersPerMinute, DecilitersPerMinuteTolerance); - AssertEx.EqualTolerance(KilolitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.KilolitersPerMinute, KilolitersPerMinuteTolerance); - AssertEx.EqualTolerance(LitersPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.LitersPerHour, LitersPerHourTolerance); - AssertEx.EqualTolerance(LitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.LitersPerMinute, LitersPerMinuteTolerance); - AssertEx.EqualTolerance(LitersPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.LitersPerSecond, LitersPerSecondTolerance); - AssertEx.EqualTolerance(MicrolitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.MicrolitersPerMinute, MicrolitersPerMinuteTolerance); - AssertEx.EqualTolerance(MillilitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.MillilitersPerMinute, MillilitersPerMinuteTolerance); - AssertEx.EqualTolerance(MillionUsGallonsPerDayInOneCubicMeterPerSecond, cubicmeterpersecond.MillionUsGallonsPerDay, MillionUsGallonsPerDayTolerance); - AssertEx.EqualTolerance(NanolitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.NanolitersPerMinute, NanolitersPerMinuteTolerance); - AssertEx.EqualTolerance(OilBarrelsPerDayInOneCubicMeterPerSecond, cubicmeterpersecond.OilBarrelsPerDay, OilBarrelsPerDayTolerance); - AssertEx.EqualTolerance(OilBarrelsPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.OilBarrelsPerHour, OilBarrelsPerHourTolerance); - AssertEx.EqualTolerance(OilBarrelsPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.OilBarrelsPerMinute, OilBarrelsPerMinuteTolerance); - AssertEx.EqualTolerance(UsGallonsPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.UsGallonsPerHour, UsGallonsPerHourTolerance); - AssertEx.EqualTolerance(UsGallonsPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.UsGallonsPerMinute, UsGallonsPerMinuteTolerance); - AssertEx.EqualTolerance(UsGallonsPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.UsGallonsPerSecond, UsGallonsPerSecondTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CentiliterPerMinute).CentilitersPerMinute, CentilitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicDecimeterPerMinute).CubicDecimetersPerMinute, CubicDecimetersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicFootPerHour).CubicFeetPerHour, CubicFeetPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicFootPerMinute).CubicFeetPerMinute, CubicFeetPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicFootPerSecond).CubicFeetPerSecond, CubicFeetPerSecondTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicMeterPerHour).CubicMetersPerHour, CubicMetersPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicMeterPerMinute).CubicMetersPerMinute, CubicMetersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicMeterPerSecond).CubicMetersPerSecond, CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicYardPerHour).CubicYardsPerHour, CubicYardsPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicYardPerMinute).CubicYardsPerMinute, CubicYardsPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.CubicYardPerSecond).CubicYardsPerSecond, CubicYardsPerSecondTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.DeciliterPerMinute).DecilitersPerMinute, DecilitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.KiloliterPerMinute).KilolitersPerMinute, KilolitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.LiterPerHour).LitersPerHour, LitersPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.LiterPerMinute).LitersPerMinute, LitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.LiterPerSecond).LitersPerSecond, LitersPerSecondTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.MicroliterPerMinute).MicrolitersPerMinute, MicrolitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.MilliliterPerMinute).MillilitersPerMinute, MillilitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.MillionUsGallonsPerDay).MillionUsGallonsPerDay, MillionUsGallonsPerDayTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.NanoliterPerMinute).NanolitersPerMinute, NanolitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.OilBarrelPerDay).OilBarrelsPerDay, OilBarrelsPerDayTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.OilBarrelPerHour).OilBarrelsPerHour, OilBarrelsPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.OilBarrelPerMinute).OilBarrelsPerMinute, OilBarrelsPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.UsGallonPerHour).UsGallonsPerHour, UsGallonsPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.UsGallonPerMinute).UsGallonsPerMinute, UsGallonsPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.From(1, VolumeFlowUnit.UsGallonPerSecond).UsGallonsPerSecond, UsGallonsPerSecondTolerance); - } - - [Fact] - public void FromCubicMetersPerSecond_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => VolumeFlow.FromCubicMetersPerSecond(double.PositiveInfinity)); - Assert.Throws(() => VolumeFlow.FromCubicMetersPerSecond(double.NegativeInfinity)); - } - - [Fact] - public void FromCubicMetersPerSecond_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => VolumeFlow.FromCubicMetersPerSecond(double.NaN)); - } - - [Fact] - public void As() - { - var cubicmeterpersecond = VolumeFlow.FromCubicMetersPerSecond(1); - AssertEx.EqualTolerance(CentilitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CentiliterPerMinute), CentilitersPerMinuteTolerance); - AssertEx.EqualTolerance(CubicDecimetersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicDecimeterPerMinute), CubicDecimetersPerMinuteTolerance); - AssertEx.EqualTolerance(CubicFeetPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicFootPerHour), CubicFeetPerHourTolerance); - AssertEx.EqualTolerance(CubicFeetPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicFootPerMinute), CubicFeetPerMinuteTolerance); - AssertEx.EqualTolerance(CubicFeetPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicFootPerSecond), CubicFeetPerSecondTolerance); - AssertEx.EqualTolerance(CubicMetersPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicMeterPerHour), CubicMetersPerHourTolerance); - AssertEx.EqualTolerance(CubicMetersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicMeterPerMinute), CubicMetersPerMinuteTolerance); - AssertEx.EqualTolerance(CubicMetersPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicMeterPerSecond), CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(CubicYardsPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicYardPerHour), CubicYardsPerHourTolerance); - AssertEx.EqualTolerance(CubicYardsPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicYardPerMinute), CubicYardsPerMinuteTolerance); - AssertEx.EqualTolerance(CubicYardsPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.CubicYardPerSecond), CubicYardsPerSecondTolerance); - AssertEx.EqualTolerance(DecilitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.DeciliterPerMinute), DecilitersPerMinuteTolerance); - AssertEx.EqualTolerance(KilolitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.KiloliterPerMinute), KilolitersPerMinuteTolerance); - AssertEx.EqualTolerance(LitersPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.LiterPerHour), LitersPerHourTolerance); - AssertEx.EqualTolerance(LitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.LiterPerMinute), LitersPerMinuteTolerance); - AssertEx.EqualTolerance(LitersPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.LiterPerSecond), LitersPerSecondTolerance); - AssertEx.EqualTolerance(MicrolitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.MicroliterPerMinute), MicrolitersPerMinuteTolerance); - AssertEx.EqualTolerance(MillilitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.MilliliterPerMinute), MillilitersPerMinuteTolerance); - AssertEx.EqualTolerance(MillionUsGallonsPerDayInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.MillionUsGallonsPerDay), MillionUsGallonsPerDayTolerance); - AssertEx.EqualTolerance(NanolitersPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.NanoliterPerMinute), NanolitersPerMinuteTolerance); - AssertEx.EqualTolerance(OilBarrelsPerDayInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.OilBarrelPerDay), OilBarrelsPerDayTolerance); - AssertEx.EqualTolerance(OilBarrelsPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.OilBarrelPerHour), OilBarrelsPerHourTolerance); - AssertEx.EqualTolerance(OilBarrelsPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.OilBarrelPerMinute), OilBarrelsPerMinuteTolerance); - AssertEx.EqualTolerance(UsGallonsPerHourInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.UsGallonPerHour), UsGallonsPerHourTolerance); - AssertEx.EqualTolerance(UsGallonsPerMinuteInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.UsGallonPerMinute), UsGallonsPerMinuteTolerance); - AssertEx.EqualTolerance(UsGallonsPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.UsGallonPerSecond), UsGallonsPerSecondTolerance); - } - - [Fact] - public void ToUnit() - { - var cubicmeterpersecond = VolumeFlow.FromCubicMetersPerSecond(1); - - var centiliterperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CentiliterPerMinute); - AssertEx.EqualTolerance(CentilitersPerMinuteInOneCubicMeterPerSecond, (double)centiliterperminuteQuantity.Value, CentilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, centiliterperminuteQuantity.Unit); - - var cubicdecimeterperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicDecimeterPerMinute); - AssertEx.EqualTolerance(CubicDecimetersPerMinuteInOneCubicMeterPerSecond, (double)cubicdecimeterperminuteQuantity.Value, CubicDecimetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicDecimeterPerMinute, cubicdecimeterperminuteQuantity.Unit); - - var cubicfootperhourQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicFootPerHour); - AssertEx.EqualTolerance(CubicFeetPerHourInOneCubicMeterPerSecond, (double)cubicfootperhourQuantity.Value, CubicFeetPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerHour, cubicfootperhourQuantity.Unit); - - var cubicfootperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicFootPerMinute); - AssertEx.EqualTolerance(CubicFeetPerMinuteInOneCubicMeterPerSecond, (double)cubicfootperminuteQuantity.Value, CubicFeetPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerMinute, cubicfootperminuteQuantity.Unit); - - var cubicfootpersecondQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicFootPerSecond); - AssertEx.EqualTolerance(CubicFeetPerSecondInOneCubicMeterPerSecond, (double)cubicfootpersecondQuantity.Value, CubicFeetPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicFootPerSecond, cubicfootpersecondQuantity.Unit); - - var cubicmeterperhourQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicMeterPerHour); - AssertEx.EqualTolerance(CubicMetersPerHourInOneCubicMeterPerSecond, (double)cubicmeterperhourQuantity.Value, CubicMetersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerHour, cubicmeterperhourQuantity.Unit); - - var cubicmeterperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicMeterPerMinute); - AssertEx.EqualTolerance(CubicMetersPerMinuteInOneCubicMeterPerSecond, (double)cubicmeterperminuteQuantity.Value, CubicMetersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerMinute, cubicmeterperminuteQuantity.Unit); - - var cubicmeterpersecondQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicMeterPerSecond); - AssertEx.EqualTolerance(CubicMetersPerSecondInOneCubicMeterPerSecond, (double)cubicmeterpersecondQuantity.Value, CubicMetersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicMeterPerSecond, cubicmeterpersecondQuantity.Unit); - - var cubicyardperhourQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicYardPerHour); - AssertEx.EqualTolerance(CubicYardsPerHourInOneCubicMeterPerSecond, (double)cubicyardperhourQuantity.Value, CubicYardsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerHour, cubicyardperhourQuantity.Unit); - - var cubicyardperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicYardPerMinute); - AssertEx.EqualTolerance(CubicYardsPerMinuteInOneCubicMeterPerSecond, (double)cubicyardperminuteQuantity.Value, CubicYardsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerMinute, cubicyardperminuteQuantity.Unit); - - var cubicyardpersecondQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.CubicYardPerSecond); - AssertEx.EqualTolerance(CubicYardsPerSecondInOneCubicMeterPerSecond, (double)cubicyardpersecondQuantity.Value, CubicYardsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.CubicYardPerSecond, cubicyardpersecondQuantity.Unit); - - var deciliterperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.DeciliterPerMinute); - AssertEx.EqualTolerance(DecilitersPerMinuteInOneCubicMeterPerSecond, (double)deciliterperminuteQuantity.Value, DecilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, deciliterperminuteQuantity.Unit); - - var kiloliterperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.KiloliterPerMinute); - AssertEx.EqualTolerance(KilolitersPerMinuteInOneCubicMeterPerSecond, (double)kiloliterperminuteQuantity.Value, KilolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, kiloliterperminuteQuantity.Unit); - - var literperhourQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.LiterPerHour); - AssertEx.EqualTolerance(LitersPerHourInOneCubicMeterPerSecond, (double)literperhourQuantity.Value, LitersPerHourTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerHour, literperhourQuantity.Unit); - - var literperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.LiterPerMinute); - AssertEx.EqualTolerance(LitersPerMinuteInOneCubicMeterPerSecond, (double)literperminuteQuantity.Value, LitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, literperminuteQuantity.Unit); - - var literpersecondQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.LiterPerSecond); - AssertEx.EqualTolerance(LitersPerSecondInOneCubicMeterPerSecond, (double)literpersecondQuantity.Value, LitersPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, literpersecondQuantity.Unit); - - var microliterperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.MicroliterPerMinute); - AssertEx.EqualTolerance(MicrolitersPerMinuteInOneCubicMeterPerSecond, (double)microliterperminuteQuantity.Value, MicrolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, microliterperminuteQuantity.Unit); - - var milliliterperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.MilliliterPerMinute); - AssertEx.EqualTolerance(MillilitersPerMinuteInOneCubicMeterPerSecond, (double)milliliterperminuteQuantity.Value, MillilitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.MilliliterPerMinute, milliliterperminuteQuantity.Unit); - - var millionusgallonsperdayQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.MillionUsGallonsPerDay); - AssertEx.EqualTolerance(MillionUsGallonsPerDayInOneCubicMeterPerSecond, (double)millionusgallonsperdayQuantity.Value, MillionUsGallonsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.MillionUsGallonsPerDay, millionusgallonsperdayQuantity.Unit); - - var nanoliterperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.NanoliterPerMinute); - AssertEx.EqualTolerance(NanolitersPerMinuteInOneCubicMeterPerSecond, (double)nanoliterperminuteQuantity.Value, NanolitersPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, nanoliterperminuteQuantity.Unit); - - var oilbarrelperdayQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.OilBarrelPerDay); - AssertEx.EqualTolerance(OilBarrelsPerDayInOneCubicMeterPerSecond, (double)oilbarrelperdayQuantity.Value, OilBarrelsPerDayTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerDay, oilbarrelperdayQuantity.Unit); - - var oilbarrelperhourQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.OilBarrelPerHour); - AssertEx.EqualTolerance(OilBarrelsPerHourInOneCubicMeterPerSecond, (double)oilbarrelperhourQuantity.Value, OilBarrelsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerHour, oilbarrelperhourQuantity.Unit); - - var oilbarrelperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.OilBarrelPerMinute); - AssertEx.EqualTolerance(OilBarrelsPerMinuteInOneCubicMeterPerSecond, (double)oilbarrelperminuteQuantity.Value, OilBarrelsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.OilBarrelPerMinute, oilbarrelperminuteQuantity.Unit); - - var usgallonperhourQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.UsGallonPerHour); - AssertEx.EqualTolerance(UsGallonsPerHourInOneCubicMeterPerSecond, (double)usgallonperhourQuantity.Value, UsGallonsPerHourTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerHour, usgallonperhourQuantity.Unit); - - var usgallonperminuteQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.UsGallonPerMinute); - AssertEx.EqualTolerance(UsGallonsPerMinuteInOneCubicMeterPerSecond, (double)usgallonperminuteQuantity.Value, UsGallonsPerMinuteTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerMinute, usgallonperminuteQuantity.Unit); - - var usgallonpersecondQuantity = cubicmeterpersecond.ToUnit(VolumeFlowUnit.UsGallonPerSecond); - AssertEx.EqualTolerance(UsGallonsPerSecondInOneCubicMeterPerSecond, (double)usgallonpersecondQuantity.Value, UsGallonsPerSecondTolerance); - Assert.Equal(VolumeFlowUnit.UsGallonPerSecond, usgallonpersecondQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - VolumeFlow cubicmeterpersecond = VolumeFlow.FromCubicMetersPerSecond(1); - AssertEx.EqualTolerance(1, VolumeFlow.FromCentilitersPerMinute(cubicmeterpersecond.CentilitersPerMinute).CubicMetersPerSecond, CentilitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicDecimetersPerMinute(cubicmeterpersecond.CubicDecimetersPerMinute).CubicMetersPerSecond, CubicDecimetersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicFeetPerHour(cubicmeterpersecond.CubicFeetPerHour).CubicMetersPerSecond, CubicFeetPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicFeetPerMinute(cubicmeterpersecond.CubicFeetPerMinute).CubicMetersPerSecond, CubicFeetPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicFeetPerSecond(cubicmeterpersecond.CubicFeetPerSecond).CubicMetersPerSecond, CubicFeetPerSecondTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicMetersPerHour(cubicmeterpersecond.CubicMetersPerHour).CubicMetersPerSecond, CubicMetersPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicMetersPerMinute(cubicmeterpersecond.CubicMetersPerMinute).CubicMetersPerSecond, CubicMetersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicMetersPerSecond(cubicmeterpersecond.CubicMetersPerSecond).CubicMetersPerSecond, CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicYardsPerHour(cubicmeterpersecond.CubicYardsPerHour).CubicMetersPerSecond, CubicYardsPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicYardsPerMinute(cubicmeterpersecond.CubicYardsPerMinute).CubicMetersPerSecond, CubicYardsPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromCubicYardsPerSecond(cubicmeterpersecond.CubicYardsPerSecond).CubicMetersPerSecond, CubicYardsPerSecondTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromDecilitersPerMinute(cubicmeterpersecond.DecilitersPerMinute).CubicMetersPerSecond, DecilitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromKilolitersPerMinute(cubicmeterpersecond.KilolitersPerMinute).CubicMetersPerSecond, KilolitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromLitersPerHour(cubicmeterpersecond.LitersPerHour).CubicMetersPerSecond, LitersPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromLitersPerMinute(cubicmeterpersecond.LitersPerMinute).CubicMetersPerSecond, LitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromLitersPerSecond(cubicmeterpersecond.LitersPerSecond).CubicMetersPerSecond, LitersPerSecondTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromMicrolitersPerMinute(cubicmeterpersecond.MicrolitersPerMinute).CubicMetersPerSecond, MicrolitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromMillilitersPerMinute(cubicmeterpersecond.MillilitersPerMinute).CubicMetersPerSecond, MillilitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromMillionUsGallonsPerDay(cubicmeterpersecond.MillionUsGallonsPerDay).CubicMetersPerSecond, MillionUsGallonsPerDayTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromNanolitersPerMinute(cubicmeterpersecond.NanolitersPerMinute).CubicMetersPerSecond, NanolitersPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromOilBarrelsPerDay(cubicmeterpersecond.OilBarrelsPerDay).CubicMetersPerSecond, OilBarrelsPerDayTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromOilBarrelsPerHour(cubicmeterpersecond.OilBarrelsPerHour).CubicMetersPerSecond, OilBarrelsPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromOilBarrelsPerMinute(cubicmeterpersecond.OilBarrelsPerMinute).CubicMetersPerSecond, OilBarrelsPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromUsGallonsPerHour(cubicmeterpersecond.UsGallonsPerHour).CubicMetersPerSecond, UsGallonsPerHourTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromUsGallonsPerMinute(cubicmeterpersecond.UsGallonsPerMinute).CubicMetersPerSecond, UsGallonsPerMinuteTolerance); - AssertEx.EqualTolerance(1, VolumeFlow.FromUsGallonsPerSecond(cubicmeterpersecond.UsGallonsPerSecond).CubicMetersPerSecond, UsGallonsPerSecondTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - VolumeFlow v = VolumeFlow.FromCubicMetersPerSecond(1); - AssertEx.EqualTolerance(-1, -v.CubicMetersPerSecond, CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(2, (VolumeFlow.FromCubicMetersPerSecond(3)-v).CubicMetersPerSecond, CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(2, (v + v).CubicMetersPerSecond, CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(10, (v*10).CubicMetersPerSecond, CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(10, (10*v).CubicMetersPerSecond, CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(2, (VolumeFlow.FromCubicMetersPerSecond(10)/5).CubicMetersPerSecond, CubicMetersPerSecondTolerance); - AssertEx.EqualTolerance(2, VolumeFlow.FromCubicMetersPerSecond(10)/VolumeFlow.FromCubicMetersPerSecond(5), CubicMetersPerSecondTolerance); - } - - [Fact] - public void ComparisonOperators() - { - VolumeFlow oneCubicMeterPerSecond = VolumeFlow.FromCubicMetersPerSecond(1); - VolumeFlow twoCubicMetersPerSecond = VolumeFlow.FromCubicMetersPerSecond(2); - - Assert.True(oneCubicMeterPerSecond < twoCubicMetersPerSecond); - Assert.True(oneCubicMeterPerSecond <= twoCubicMetersPerSecond); - Assert.True(twoCubicMetersPerSecond > oneCubicMeterPerSecond); - Assert.True(twoCubicMetersPerSecond >= oneCubicMeterPerSecond); - - Assert.False(oneCubicMeterPerSecond > twoCubicMetersPerSecond); - Assert.False(oneCubicMeterPerSecond >= twoCubicMetersPerSecond); - Assert.False(twoCubicMetersPerSecond < oneCubicMeterPerSecond); - Assert.False(twoCubicMetersPerSecond <= oneCubicMeterPerSecond); - } - - [Fact] - public void CompareToIsImplemented() - { - VolumeFlow cubicmeterpersecond = VolumeFlow.FromCubicMetersPerSecond(1); - Assert.Equal(0, cubicmeterpersecond.CompareTo(cubicmeterpersecond)); - Assert.True(cubicmeterpersecond.CompareTo(VolumeFlow.Zero) > 0); - Assert.True(VolumeFlow.Zero.CompareTo(cubicmeterpersecond) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - VolumeFlow cubicmeterpersecond = VolumeFlow.FromCubicMetersPerSecond(1); - Assert.Throws(() => cubicmeterpersecond.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - VolumeFlow cubicmeterpersecond = VolumeFlow.FromCubicMetersPerSecond(1); - Assert.Throws(() => cubicmeterpersecond.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - VolumeFlow v = VolumeFlow.FromCubicMetersPerSecond(1); - Assert.True(v.Equals(VolumeFlow.FromCubicMetersPerSecond(1), CubicMetersPerSecondTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(VolumeFlow.Zero, CubicMetersPerSecondTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - VolumeFlow cubicmeterpersecond = VolumeFlow.FromCubicMetersPerSecond(1); - Assert.False(cubicmeterpersecond.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - VolumeFlow cubicmeterpersecond = VolumeFlow.FromCubicMetersPerSecond(1); - Assert.False(cubicmeterpersecond.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(VolumeFlowUnit.Undefined, VolumeFlow.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(VolumeFlowUnit)).Cast(); - foreach(var unit in units) - { - if(unit == VolumeFlowUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/VolumeTestsBase.g.cs deleted file mode 100644 index bd480669ff..0000000000 --- a/UnitsNet.Tests/GeneratedCode/VolumeTestsBase.g.cs +++ /dev/null @@ -1,634 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// 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. - -using System; -using System.Linq; -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 -{ - /// - /// Test of Volume. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class VolumeTestsBase - { - protected abstract double AuTablespoonsInOneCubicMeter { get; } - protected abstract double CentilitersInOneCubicMeter { get; } - protected abstract double CubicCentimetersInOneCubicMeter { get; } - protected abstract double CubicDecimetersInOneCubicMeter { get; } - protected abstract double CubicFeetInOneCubicMeter { get; } - protected abstract double CubicInchesInOneCubicMeter { get; } - protected abstract double CubicKilometersInOneCubicMeter { get; } - protected abstract double CubicMetersInOneCubicMeter { get; } - protected abstract double CubicMicrometersInOneCubicMeter { get; } - protected abstract double CubicMilesInOneCubicMeter { get; } - protected abstract double CubicMillimetersInOneCubicMeter { get; } - protected abstract double CubicYardsInOneCubicMeter { get; } - protected abstract double DecilitersInOneCubicMeter { get; } - protected abstract double HectocubicFeetInOneCubicMeter { get; } - protected abstract double HectocubicMetersInOneCubicMeter { get; } - protected abstract double HectolitersInOneCubicMeter { get; } - protected abstract double ImperialBeerBarrelsInOneCubicMeter { get; } - protected abstract double ImperialGallonsInOneCubicMeter { get; } - protected abstract double ImperialOuncesInOneCubicMeter { get; } - protected abstract double KilocubicFeetInOneCubicMeter { get; } - protected abstract double KilocubicMetersInOneCubicMeter { get; } - protected abstract double KiloimperialGallonsInOneCubicMeter { get; } - protected abstract double KilousGallonsInOneCubicMeter { get; } - protected abstract double LitersInOneCubicMeter { get; } - protected abstract double MegacubicFeetInOneCubicMeter { get; } - protected abstract double MegaimperialGallonsInOneCubicMeter { get; } - protected abstract double MegausGallonsInOneCubicMeter { get; } - protected abstract double MetricCupsInOneCubicMeter { get; } - protected abstract double MetricTeaspoonsInOneCubicMeter { get; } - protected abstract double MicrolitersInOneCubicMeter { get; } - protected abstract double MillilitersInOneCubicMeter { get; } - protected abstract double OilBarrelsInOneCubicMeter { get; } - protected abstract double UkTablespoonsInOneCubicMeter { get; } - protected abstract double UsBeerBarrelsInOneCubicMeter { get; } - protected abstract double UsCustomaryCupsInOneCubicMeter { get; } - protected abstract double UsGallonsInOneCubicMeter { get; } - protected abstract double UsLegalCupsInOneCubicMeter { get; } - protected abstract double UsOuncesInOneCubicMeter { get; } - protected abstract double UsPintsInOneCubicMeter { get; } - protected abstract double UsQuartsInOneCubicMeter { get; } - protected abstract double UsTablespoonsInOneCubicMeter { get; } - protected abstract double UsTeaspoonsInOneCubicMeter { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double AuTablespoonsTolerance { get { return 1e-5; } } - protected virtual double CentilitersTolerance { get { return 1e-5; } } - protected virtual double CubicCentimetersTolerance { get { return 1e-5; } } - protected virtual double CubicDecimetersTolerance { get { return 1e-5; } } - protected virtual double CubicFeetTolerance { get { return 1e-5; } } - protected virtual double CubicInchesTolerance { get { return 1e-5; } } - protected virtual double CubicKilometersTolerance { get { return 1e-5; } } - protected virtual double CubicMetersTolerance { get { return 1e-5; } } - protected virtual double CubicMicrometersTolerance { get { return 1e-5; } } - protected virtual double CubicMilesTolerance { get { return 1e-5; } } - protected virtual double CubicMillimetersTolerance { get { return 1e-5; } } - protected virtual double CubicYardsTolerance { get { return 1e-5; } } - protected virtual double DecilitersTolerance { get { return 1e-5; } } - protected virtual double HectocubicFeetTolerance { get { return 1e-5; } } - protected virtual double HectocubicMetersTolerance { get { return 1e-5; } } - protected virtual double HectolitersTolerance { get { return 1e-5; } } - protected virtual double ImperialBeerBarrelsTolerance { get { return 1e-5; } } - protected virtual double ImperialGallonsTolerance { get { return 1e-5; } } - protected virtual double ImperialOuncesTolerance { get { return 1e-5; } } - protected virtual double KilocubicFeetTolerance { get { return 1e-5; } } - protected virtual double KilocubicMetersTolerance { get { return 1e-5; } } - protected virtual double KiloimperialGallonsTolerance { get { return 1e-5; } } - protected virtual double KilousGallonsTolerance { get { return 1e-5; } } - protected virtual double LitersTolerance { get { return 1e-5; } } - protected virtual double MegacubicFeetTolerance { get { return 1e-5; } } - protected virtual double MegaimperialGallonsTolerance { get { return 1e-5; } } - protected virtual double MegausGallonsTolerance { get { return 1e-5; } } - protected virtual double MetricCupsTolerance { get { return 1e-5; } } - protected virtual double MetricTeaspoonsTolerance { get { return 1e-5; } } - protected virtual double MicrolitersTolerance { get { return 1e-5; } } - protected virtual double MillilitersTolerance { get { return 1e-5; } } - protected virtual double OilBarrelsTolerance { get { return 1e-5; } } - protected virtual double UkTablespoonsTolerance { get { return 1e-5; } } - protected virtual double UsBeerBarrelsTolerance { get { return 1e-5; } } - protected virtual double UsCustomaryCupsTolerance { get { return 1e-5; } } - protected virtual double UsGallonsTolerance { get { return 1e-5; } } - protected virtual double UsLegalCupsTolerance { get { return 1e-5; } } - protected virtual double UsOuncesTolerance { get { return 1e-5; } } - protected virtual double UsPintsTolerance { get { return 1e-5; } } - protected virtual double UsQuartsTolerance { get { return 1e-5; } } - protected virtual double UsTablespoonsTolerance { get { return 1e-5; } } - protected virtual double UsTeaspoonsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - [Fact] - public void Ctor_WithUndefinedUnit_ThrowsArgumentException() - { - Assert.Throws(() => new Volume((double)0.0, VolumeUnit.Undefined)); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new Volume(double.PositiveInfinity, VolumeUnit.CubicMeter)); - Assert.Throws(() => new Volume(double.NegativeInfinity, VolumeUnit.CubicMeter)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new Volume(double.NaN, VolumeUnit.CubicMeter)); - } - - [Fact] - public void CubicMeterToVolumeUnits() - { - Volume cubicmeter = Volume.FromCubicMeters(1); - AssertEx.EqualTolerance(AuTablespoonsInOneCubicMeter, cubicmeter.AuTablespoons, AuTablespoonsTolerance); - AssertEx.EqualTolerance(CentilitersInOneCubicMeter, cubicmeter.Centiliters, CentilitersTolerance); - AssertEx.EqualTolerance(CubicCentimetersInOneCubicMeter, cubicmeter.CubicCentimeters, CubicCentimetersTolerance); - AssertEx.EqualTolerance(CubicDecimetersInOneCubicMeter, cubicmeter.CubicDecimeters, CubicDecimetersTolerance); - AssertEx.EqualTolerance(CubicFeetInOneCubicMeter, cubicmeter.CubicFeet, CubicFeetTolerance); - AssertEx.EqualTolerance(CubicInchesInOneCubicMeter, cubicmeter.CubicInches, CubicInchesTolerance); - AssertEx.EqualTolerance(CubicKilometersInOneCubicMeter, cubicmeter.CubicKilometers, CubicKilometersTolerance); - AssertEx.EqualTolerance(CubicMetersInOneCubicMeter, cubicmeter.CubicMeters, CubicMetersTolerance); - AssertEx.EqualTolerance(CubicMicrometersInOneCubicMeter, cubicmeter.CubicMicrometers, CubicMicrometersTolerance); - AssertEx.EqualTolerance(CubicMilesInOneCubicMeter, cubicmeter.CubicMiles, CubicMilesTolerance); - AssertEx.EqualTolerance(CubicMillimetersInOneCubicMeter, cubicmeter.CubicMillimeters, CubicMillimetersTolerance); - AssertEx.EqualTolerance(CubicYardsInOneCubicMeter, cubicmeter.CubicYards, CubicYardsTolerance); - AssertEx.EqualTolerance(DecilitersInOneCubicMeter, cubicmeter.Deciliters, DecilitersTolerance); - AssertEx.EqualTolerance(HectocubicFeetInOneCubicMeter, cubicmeter.HectocubicFeet, HectocubicFeetTolerance); - AssertEx.EqualTolerance(HectocubicMetersInOneCubicMeter, cubicmeter.HectocubicMeters, HectocubicMetersTolerance); - AssertEx.EqualTolerance(HectolitersInOneCubicMeter, cubicmeter.Hectoliters, HectolitersTolerance); - AssertEx.EqualTolerance(ImperialBeerBarrelsInOneCubicMeter, cubicmeter.ImperialBeerBarrels, ImperialBeerBarrelsTolerance); - AssertEx.EqualTolerance(ImperialGallonsInOneCubicMeter, cubicmeter.ImperialGallons, ImperialGallonsTolerance); - AssertEx.EqualTolerance(ImperialOuncesInOneCubicMeter, cubicmeter.ImperialOunces, ImperialOuncesTolerance); - AssertEx.EqualTolerance(KilocubicFeetInOneCubicMeter, cubicmeter.KilocubicFeet, KilocubicFeetTolerance); - AssertEx.EqualTolerance(KilocubicMetersInOneCubicMeter, cubicmeter.KilocubicMeters, KilocubicMetersTolerance); - AssertEx.EqualTolerance(KiloimperialGallonsInOneCubicMeter, cubicmeter.KiloimperialGallons, KiloimperialGallonsTolerance); - AssertEx.EqualTolerance(KilousGallonsInOneCubicMeter, cubicmeter.KilousGallons, KilousGallonsTolerance); - AssertEx.EqualTolerance(LitersInOneCubicMeter, cubicmeter.Liters, LitersTolerance); - AssertEx.EqualTolerance(MegacubicFeetInOneCubicMeter, cubicmeter.MegacubicFeet, MegacubicFeetTolerance); - AssertEx.EqualTolerance(MegaimperialGallonsInOneCubicMeter, cubicmeter.MegaimperialGallons, MegaimperialGallonsTolerance); - AssertEx.EqualTolerance(MegausGallonsInOneCubicMeter, cubicmeter.MegausGallons, MegausGallonsTolerance); - AssertEx.EqualTolerance(MetricCupsInOneCubicMeter, cubicmeter.MetricCups, MetricCupsTolerance); - AssertEx.EqualTolerance(MetricTeaspoonsInOneCubicMeter, cubicmeter.MetricTeaspoons, MetricTeaspoonsTolerance); - AssertEx.EqualTolerance(MicrolitersInOneCubicMeter, cubicmeter.Microliters, MicrolitersTolerance); - AssertEx.EqualTolerance(MillilitersInOneCubicMeter, cubicmeter.Milliliters, MillilitersTolerance); - AssertEx.EqualTolerance(OilBarrelsInOneCubicMeter, cubicmeter.OilBarrels, OilBarrelsTolerance); - AssertEx.EqualTolerance(UkTablespoonsInOneCubicMeter, cubicmeter.UkTablespoons, UkTablespoonsTolerance); - AssertEx.EqualTolerance(UsBeerBarrelsInOneCubicMeter, cubicmeter.UsBeerBarrels, UsBeerBarrelsTolerance); - AssertEx.EqualTolerance(UsCustomaryCupsInOneCubicMeter, cubicmeter.UsCustomaryCups, UsCustomaryCupsTolerance); - AssertEx.EqualTolerance(UsGallonsInOneCubicMeter, cubicmeter.UsGallons, UsGallonsTolerance); - AssertEx.EqualTolerance(UsLegalCupsInOneCubicMeter, cubicmeter.UsLegalCups, UsLegalCupsTolerance); - AssertEx.EqualTolerance(UsOuncesInOneCubicMeter, cubicmeter.UsOunces, UsOuncesTolerance); - AssertEx.EqualTolerance(UsPintsInOneCubicMeter, cubicmeter.UsPints, UsPintsTolerance); - AssertEx.EqualTolerance(UsQuartsInOneCubicMeter, cubicmeter.UsQuarts, UsQuartsTolerance); - AssertEx.EqualTolerance(UsTablespoonsInOneCubicMeter, cubicmeter.UsTablespoons, UsTablespoonsTolerance); - AssertEx.EqualTolerance(UsTeaspoonsInOneCubicMeter, cubicmeter.UsTeaspoons, UsTeaspoonsTolerance); - } - - [Fact] - public void FromValueAndUnit() - { - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.AuTablespoon).AuTablespoons, AuTablespoonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.Centiliter).Centiliters, CentilitersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicCentimeter).CubicCentimeters, CubicCentimetersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicDecimeter).CubicDecimeters, CubicDecimetersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicFoot).CubicFeet, CubicFeetTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicInch).CubicInches, CubicInchesTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicKilometer).CubicKilometers, CubicKilometersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicMeter).CubicMeters, CubicMetersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicMicrometer).CubicMicrometers, CubicMicrometersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicMile).CubicMiles, CubicMilesTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicMillimeter).CubicMillimeters, CubicMillimetersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.CubicYard).CubicYards, CubicYardsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.Deciliter).Deciliters, DecilitersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.HectocubicFoot).HectocubicFeet, HectocubicFeetTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.HectocubicMeter).HectocubicMeters, HectocubicMetersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.Hectoliter).Hectoliters, HectolitersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.ImperialBeerBarrel).ImperialBeerBarrels, ImperialBeerBarrelsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.ImperialGallon).ImperialGallons, ImperialGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.ImperialOunce).ImperialOunces, ImperialOuncesTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.KilocubicFoot).KilocubicFeet, KilocubicFeetTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.KilocubicMeter).KilocubicMeters, KilocubicMetersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.KiloimperialGallon).KiloimperialGallons, KiloimperialGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.KilousGallon).KilousGallons, KilousGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.Liter).Liters, LitersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.MegacubicFoot).MegacubicFeet, MegacubicFeetTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.MegaimperialGallon).MegaimperialGallons, MegaimperialGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.MegausGallon).MegausGallons, MegausGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.MetricCup).MetricCups, MetricCupsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.MetricTeaspoon).MetricTeaspoons, MetricTeaspoonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.Microliter).Microliters, MicrolitersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.Milliliter).Milliliters, MillilitersTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.OilBarrel).OilBarrels, OilBarrelsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UkTablespoon).UkTablespoons, UkTablespoonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UsBeerBarrel).UsBeerBarrels, UsBeerBarrelsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UsCustomaryCup).UsCustomaryCups, UsCustomaryCupsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UsGallon).UsGallons, UsGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UsLegalCup).UsLegalCups, UsLegalCupsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UsOunce).UsOunces, UsOuncesTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UsPint).UsPints, UsPintsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UsQuart).UsQuarts, UsQuartsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UsTablespoon).UsTablespoons, UsTablespoonsTolerance); - AssertEx.EqualTolerance(1, Volume.From(1, VolumeUnit.UsTeaspoon).UsTeaspoons, UsTeaspoonsTolerance); - } - - [Fact] - public void FromCubicMeters_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => Volume.FromCubicMeters(double.PositiveInfinity)); - Assert.Throws(() => Volume.FromCubicMeters(double.NegativeInfinity)); - } - - [Fact] - public void FromCubicMeters_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => Volume.FromCubicMeters(double.NaN)); - } - - [Fact] - public void As() - { - var cubicmeter = Volume.FromCubicMeters(1); - AssertEx.EqualTolerance(AuTablespoonsInOneCubicMeter, cubicmeter.As(VolumeUnit.AuTablespoon), AuTablespoonsTolerance); - AssertEx.EqualTolerance(CentilitersInOneCubicMeter, cubicmeter.As(VolumeUnit.Centiliter), CentilitersTolerance); - AssertEx.EqualTolerance(CubicCentimetersInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicCentimeter), CubicCentimetersTolerance); - AssertEx.EqualTolerance(CubicDecimetersInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicDecimeter), CubicDecimetersTolerance); - AssertEx.EqualTolerance(CubicFeetInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicFoot), CubicFeetTolerance); - AssertEx.EqualTolerance(CubicInchesInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicInch), CubicInchesTolerance); - AssertEx.EqualTolerance(CubicKilometersInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicKilometer), CubicKilometersTolerance); - AssertEx.EqualTolerance(CubicMetersInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicMeter), CubicMetersTolerance); - AssertEx.EqualTolerance(CubicMicrometersInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicMicrometer), CubicMicrometersTolerance); - AssertEx.EqualTolerance(CubicMilesInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicMile), CubicMilesTolerance); - AssertEx.EqualTolerance(CubicMillimetersInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicMillimeter), CubicMillimetersTolerance); - AssertEx.EqualTolerance(CubicYardsInOneCubicMeter, cubicmeter.As(VolumeUnit.CubicYard), CubicYardsTolerance); - AssertEx.EqualTolerance(DecilitersInOneCubicMeter, cubicmeter.As(VolumeUnit.Deciliter), DecilitersTolerance); - AssertEx.EqualTolerance(HectocubicFeetInOneCubicMeter, cubicmeter.As(VolumeUnit.HectocubicFoot), HectocubicFeetTolerance); - AssertEx.EqualTolerance(HectocubicMetersInOneCubicMeter, cubicmeter.As(VolumeUnit.HectocubicMeter), HectocubicMetersTolerance); - AssertEx.EqualTolerance(HectolitersInOneCubicMeter, cubicmeter.As(VolumeUnit.Hectoliter), HectolitersTolerance); - AssertEx.EqualTolerance(ImperialBeerBarrelsInOneCubicMeter, cubicmeter.As(VolumeUnit.ImperialBeerBarrel), ImperialBeerBarrelsTolerance); - AssertEx.EqualTolerance(ImperialGallonsInOneCubicMeter, cubicmeter.As(VolumeUnit.ImperialGallon), ImperialGallonsTolerance); - AssertEx.EqualTolerance(ImperialOuncesInOneCubicMeter, cubicmeter.As(VolumeUnit.ImperialOunce), ImperialOuncesTolerance); - AssertEx.EqualTolerance(KilocubicFeetInOneCubicMeter, cubicmeter.As(VolumeUnit.KilocubicFoot), KilocubicFeetTolerance); - AssertEx.EqualTolerance(KilocubicMetersInOneCubicMeter, cubicmeter.As(VolumeUnit.KilocubicMeter), KilocubicMetersTolerance); - AssertEx.EqualTolerance(KiloimperialGallonsInOneCubicMeter, cubicmeter.As(VolumeUnit.KiloimperialGallon), KiloimperialGallonsTolerance); - AssertEx.EqualTolerance(KilousGallonsInOneCubicMeter, cubicmeter.As(VolumeUnit.KilousGallon), KilousGallonsTolerance); - AssertEx.EqualTolerance(LitersInOneCubicMeter, cubicmeter.As(VolumeUnit.Liter), LitersTolerance); - AssertEx.EqualTolerance(MegacubicFeetInOneCubicMeter, cubicmeter.As(VolumeUnit.MegacubicFoot), MegacubicFeetTolerance); - AssertEx.EqualTolerance(MegaimperialGallonsInOneCubicMeter, cubicmeter.As(VolumeUnit.MegaimperialGallon), MegaimperialGallonsTolerance); - AssertEx.EqualTolerance(MegausGallonsInOneCubicMeter, cubicmeter.As(VolumeUnit.MegausGallon), MegausGallonsTolerance); - AssertEx.EqualTolerance(MetricCupsInOneCubicMeter, cubicmeter.As(VolumeUnit.MetricCup), MetricCupsTolerance); - AssertEx.EqualTolerance(MetricTeaspoonsInOneCubicMeter, cubicmeter.As(VolumeUnit.MetricTeaspoon), MetricTeaspoonsTolerance); - AssertEx.EqualTolerance(MicrolitersInOneCubicMeter, cubicmeter.As(VolumeUnit.Microliter), MicrolitersTolerance); - AssertEx.EqualTolerance(MillilitersInOneCubicMeter, cubicmeter.As(VolumeUnit.Milliliter), MillilitersTolerance); - AssertEx.EqualTolerance(OilBarrelsInOneCubicMeter, cubicmeter.As(VolumeUnit.OilBarrel), OilBarrelsTolerance); - AssertEx.EqualTolerance(UkTablespoonsInOneCubicMeter, cubicmeter.As(VolumeUnit.UkTablespoon), UkTablespoonsTolerance); - AssertEx.EqualTolerance(UsBeerBarrelsInOneCubicMeter, cubicmeter.As(VolumeUnit.UsBeerBarrel), UsBeerBarrelsTolerance); - AssertEx.EqualTolerance(UsCustomaryCupsInOneCubicMeter, cubicmeter.As(VolumeUnit.UsCustomaryCup), UsCustomaryCupsTolerance); - AssertEx.EqualTolerance(UsGallonsInOneCubicMeter, cubicmeter.As(VolumeUnit.UsGallon), UsGallonsTolerance); - AssertEx.EqualTolerance(UsLegalCupsInOneCubicMeter, cubicmeter.As(VolumeUnit.UsLegalCup), UsLegalCupsTolerance); - AssertEx.EqualTolerance(UsOuncesInOneCubicMeter, cubicmeter.As(VolumeUnit.UsOunce), UsOuncesTolerance); - AssertEx.EqualTolerance(UsPintsInOneCubicMeter, cubicmeter.As(VolumeUnit.UsPint), UsPintsTolerance); - AssertEx.EqualTolerance(UsQuartsInOneCubicMeter, cubicmeter.As(VolumeUnit.UsQuart), UsQuartsTolerance); - AssertEx.EqualTolerance(UsTablespoonsInOneCubicMeter, cubicmeter.As(VolumeUnit.UsTablespoon), UsTablespoonsTolerance); - AssertEx.EqualTolerance(UsTeaspoonsInOneCubicMeter, cubicmeter.As(VolumeUnit.UsTeaspoon), UsTeaspoonsTolerance); - } - - [Fact] - public void ToUnit() - { - var cubicmeter = Volume.FromCubicMeters(1); - - var autablespoonQuantity = cubicmeter.ToUnit(VolumeUnit.AuTablespoon); - AssertEx.EqualTolerance(AuTablespoonsInOneCubicMeter, (double)autablespoonQuantity.Value, AuTablespoonsTolerance); - Assert.Equal(VolumeUnit.AuTablespoon, autablespoonQuantity.Unit); - - var centiliterQuantity = cubicmeter.ToUnit(VolumeUnit.Centiliter); - AssertEx.EqualTolerance(CentilitersInOneCubicMeter, (double)centiliterQuantity.Value, CentilitersTolerance); - Assert.Equal(VolumeUnit.Centiliter, centiliterQuantity.Unit); - - var cubiccentimeterQuantity = cubicmeter.ToUnit(VolumeUnit.CubicCentimeter); - AssertEx.EqualTolerance(CubicCentimetersInOneCubicMeter, (double)cubiccentimeterQuantity.Value, CubicCentimetersTolerance); - Assert.Equal(VolumeUnit.CubicCentimeter, cubiccentimeterQuantity.Unit); - - var cubicdecimeterQuantity = cubicmeter.ToUnit(VolumeUnit.CubicDecimeter); - AssertEx.EqualTolerance(CubicDecimetersInOneCubicMeter, (double)cubicdecimeterQuantity.Value, CubicDecimetersTolerance); - Assert.Equal(VolumeUnit.CubicDecimeter, cubicdecimeterQuantity.Unit); - - var cubicfootQuantity = cubicmeter.ToUnit(VolumeUnit.CubicFoot); - AssertEx.EqualTolerance(CubicFeetInOneCubicMeter, (double)cubicfootQuantity.Value, CubicFeetTolerance); - Assert.Equal(VolumeUnit.CubicFoot, cubicfootQuantity.Unit); - - var cubicinchQuantity = cubicmeter.ToUnit(VolumeUnit.CubicInch); - AssertEx.EqualTolerance(CubicInchesInOneCubicMeter, (double)cubicinchQuantity.Value, CubicInchesTolerance); - Assert.Equal(VolumeUnit.CubicInch, cubicinchQuantity.Unit); - - var cubickilometerQuantity = cubicmeter.ToUnit(VolumeUnit.CubicKilometer); - AssertEx.EqualTolerance(CubicKilometersInOneCubicMeter, (double)cubickilometerQuantity.Value, CubicKilometersTolerance); - Assert.Equal(VolumeUnit.CubicKilometer, cubickilometerQuantity.Unit); - - var cubicmeterQuantity = cubicmeter.ToUnit(VolumeUnit.CubicMeter); - AssertEx.EqualTolerance(CubicMetersInOneCubicMeter, (double)cubicmeterQuantity.Value, CubicMetersTolerance); - Assert.Equal(VolumeUnit.CubicMeter, cubicmeterQuantity.Unit); - - var cubicmicrometerQuantity = cubicmeter.ToUnit(VolumeUnit.CubicMicrometer); - AssertEx.EqualTolerance(CubicMicrometersInOneCubicMeter, (double)cubicmicrometerQuantity.Value, CubicMicrometersTolerance); - Assert.Equal(VolumeUnit.CubicMicrometer, cubicmicrometerQuantity.Unit); - - var cubicmileQuantity = cubicmeter.ToUnit(VolumeUnit.CubicMile); - AssertEx.EqualTolerance(CubicMilesInOneCubicMeter, (double)cubicmileQuantity.Value, CubicMilesTolerance); - Assert.Equal(VolumeUnit.CubicMile, cubicmileQuantity.Unit); - - var cubicmillimeterQuantity = cubicmeter.ToUnit(VolumeUnit.CubicMillimeter); - AssertEx.EqualTolerance(CubicMillimetersInOneCubicMeter, (double)cubicmillimeterQuantity.Value, CubicMillimetersTolerance); - Assert.Equal(VolumeUnit.CubicMillimeter, cubicmillimeterQuantity.Unit); - - var cubicyardQuantity = cubicmeter.ToUnit(VolumeUnit.CubicYard); - AssertEx.EqualTolerance(CubicYardsInOneCubicMeter, (double)cubicyardQuantity.Value, CubicYardsTolerance); - Assert.Equal(VolumeUnit.CubicYard, cubicyardQuantity.Unit); - - var deciliterQuantity = cubicmeter.ToUnit(VolumeUnit.Deciliter); - AssertEx.EqualTolerance(DecilitersInOneCubicMeter, (double)deciliterQuantity.Value, DecilitersTolerance); - Assert.Equal(VolumeUnit.Deciliter, deciliterQuantity.Unit); - - var hectocubicfootQuantity = cubicmeter.ToUnit(VolumeUnit.HectocubicFoot); - AssertEx.EqualTolerance(HectocubicFeetInOneCubicMeter, (double)hectocubicfootQuantity.Value, HectocubicFeetTolerance); - Assert.Equal(VolumeUnit.HectocubicFoot, hectocubicfootQuantity.Unit); - - var hectocubicmeterQuantity = cubicmeter.ToUnit(VolumeUnit.HectocubicMeter); - AssertEx.EqualTolerance(HectocubicMetersInOneCubicMeter, (double)hectocubicmeterQuantity.Value, HectocubicMetersTolerance); - Assert.Equal(VolumeUnit.HectocubicMeter, hectocubicmeterQuantity.Unit); - - var hectoliterQuantity = cubicmeter.ToUnit(VolumeUnit.Hectoliter); - AssertEx.EqualTolerance(HectolitersInOneCubicMeter, (double)hectoliterQuantity.Value, HectolitersTolerance); - Assert.Equal(VolumeUnit.Hectoliter, hectoliterQuantity.Unit); - - var imperialbeerbarrelQuantity = cubicmeter.ToUnit(VolumeUnit.ImperialBeerBarrel); - AssertEx.EqualTolerance(ImperialBeerBarrelsInOneCubicMeter, (double)imperialbeerbarrelQuantity.Value, ImperialBeerBarrelsTolerance); - Assert.Equal(VolumeUnit.ImperialBeerBarrel, imperialbeerbarrelQuantity.Unit); - - var imperialgallonQuantity = cubicmeter.ToUnit(VolumeUnit.ImperialGallon); - AssertEx.EqualTolerance(ImperialGallonsInOneCubicMeter, (double)imperialgallonQuantity.Value, ImperialGallonsTolerance); - Assert.Equal(VolumeUnit.ImperialGallon, imperialgallonQuantity.Unit); - - var imperialounceQuantity = cubicmeter.ToUnit(VolumeUnit.ImperialOunce); - AssertEx.EqualTolerance(ImperialOuncesInOneCubicMeter, (double)imperialounceQuantity.Value, ImperialOuncesTolerance); - Assert.Equal(VolumeUnit.ImperialOunce, imperialounceQuantity.Unit); - - var kilocubicfootQuantity = cubicmeter.ToUnit(VolumeUnit.KilocubicFoot); - AssertEx.EqualTolerance(KilocubicFeetInOneCubicMeter, (double)kilocubicfootQuantity.Value, KilocubicFeetTolerance); - Assert.Equal(VolumeUnit.KilocubicFoot, kilocubicfootQuantity.Unit); - - var kilocubicmeterQuantity = cubicmeter.ToUnit(VolumeUnit.KilocubicMeter); - AssertEx.EqualTolerance(KilocubicMetersInOneCubicMeter, (double)kilocubicmeterQuantity.Value, KilocubicMetersTolerance); - Assert.Equal(VolumeUnit.KilocubicMeter, kilocubicmeterQuantity.Unit); - - var kiloimperialgallonQuantity = cubicmeter.ToUnit(VolumeUnit.KiloimperialGallon); - AssertEx.EqualTolerance(KiloimperialGallonsInOneCubicMeter, (double)kiloimperialgallonQuantity.Value, KiloimperialGallonsTolerance); - Assert.Equal(VolumeUnit.KiloimperialGallon, kiloimperialgallonQuantity.Unit); - - var kilousgallonQuantity = cubicmeter.ToUnit(VolumeUnit.KilousGallon); - AssertEx.EqualTolerance(KilousGallonsInOneCubicMeter, (double)kilousgallonQuantity.Value, KilousGallonsTolerance); - Assert.Equal(VolumeUnit.KilousGallon, kilousgallonQuantity.Unit); - - var literQuantity = cubicmeter.ToUnit(VolumeUnit.Liter); - AssertEx.EqualTolerance(LitersInOneCubicMeter, (double)literQuantity.Value, LitersTolerance); - Assert.Equal(VolumeUnit.Liter, literQuantity.Unit); - - var megacubicfootQuantity = cubicmeter.ToUnit(VolumeUnit.MegacubicFoot); - AssertEx.EqualTolerance(MegacubicFeetInOneCubicMeter, (double)megacubicfootQuantity.Value, MegacubicFeetTolerance); - Assert.Equal(VolumeUnit.MegacubicFoot, megacubicfootQuantity.Unit); - - var megaimperialgallonQuantity = cubicmeter.ToUnit(VolumeUnit.MegaimperialGallon); - AssertEx.EqualTolerance(MegaimperialGallonsInOneCubicMeter, (double)megaimperialgallonQuantity.Value, MegaimperialGallonsTolerance); - Assert.Equal(VolumeUnit.MegaimperialGallon, megaimperialgallonQuantity.Unit); - - var megausgallonQuantity = cubicmeter.ToUnit(VolumeUnit.MegausGallon); - AssertEx.EqualTolerance(MegausGallonsInOneCubicMeter, (double)megausgallonQuantity.Value, MegausGallonsTolerance); - Assert.Equal(VolumeUnit.MegausGallon, megausgallonQuantity.Unit); - - var metriccupQuantity = cubicmeter.ToUnit(VolumeUnit.MetricCup); - AssertEx.EqualTolerance(MetricCupsInOneCubicMeter, (double)metriccupQuantity.Value, MetricCupsTolerance); - Assert.Equal(VolumeUnit.MetricCup, metriccupQuantity.Unit); - - var metricteaspoonQuantity = cubicmeter.ToUnit(VolumeUnit.MetricTeaspoon); - AssertEx.EqualTolerance(MetricTeaspoonsInOneCubicMeter, (double)metricteaspoonQuantity.Value, MetricTeaspoonsTolerance); - Assert.Equal(VolumeUnit.MetricTeaspoon, metricteaspoonQuantity.Unit); - - var microliterQuantity = cubicmeter.ToUnit(VolumeUnit.Microliter); - AssertEx.EqualTolerance(MicrolitersInOneCubicMeter, (double)microliterQuantity.Value, MicrolitersTolerance); - Assert.Equal(VolumeUnit.Microliter, microliterQuantity.Unit); - - var milliliterQuantity = cubicmeter.ToUnit(VolumeUnit.Milliliter); - AssertEx.EqualTolerance(MillilitersInOneCubicMeter, (double)milliliterQuantity.Value, MillilitersTolerance); - Assert.Equal(VolumeUnit.Milliliter, milliliterQuantity.Unit); - - var oilbarrelQuantity = cubicmeter.ToUnit(VolumeUnit.OilBarrel); - AssertEx.EqualTolerance(OilBarrelsInOneCubicMeter, (double)oilbarrelQuantity.Value, OilBarrelsTolerance); - Assert.Equal(VolumeUnit.OilBarrel, oilbarrelQuantity.Unit); - - var uktablespoonQuantity = cubicmeter.ToUnit(VolumeUnit.UkTablespoon); - AssertEx.EqualTolerance(UkTablespoonsInOneCubicMeter, (double)uktablespoonQuantity.Value, UkTablespoonsTolerance); - Assert.Equal(VolumeUnit.UkTablespoon, uktablespoonQuantity.Unit); - - var usbeerbarrelQuantity = cubicmeter.ToUnit(VolumeUnit.UsBeerBarrel); - AssertEx.EqualTolerance(UsBeerBarrelsInOneCubicMeter, (double)usbeerbarrelQuantity.Value, UsBeerBarrelsTolerance); - Assert.Equal(VolumeUnit.UsBeerBarrel, usbeerbarrelQuantity.Unit); - - var uscustomarycupQuantity = cubicmeter.ToUnit(VolumeUnit.UsCustomaryCup); - AssertEx.EqualTolerance(UsCustomaryCupsInOneCubicMeter, (double)uscustomarycupQuantity.Value, UsCustomaryCupsTolerance); - Assert.Equal(VolumeUnit.UsCustomaryCup, uscustomarycupQuantity.Unit); - - var usgallonQuantity = cubicmeter.ToUnit(VolumeUnit.UsGallon); - AssertEx.EqualTolerance(UsGallonsInOneCubicMeter, (double)usgallonQuantity.Value, UsGallonsTolerance); - Assert.Equal(VolumeUnit.UsGallon, usgallonQuantity.Unit); - - var uslegalcupQuantity = cubicmeter.ToUnit(VolumeUnit.UsLegalCup); - AssertEx.EqualTolerance(UsLegalCupsInOneCubicMeter, (double)uslegalcupQuantity.Value, UsLegalCupsTolerance); - Assert.Equal(VolumeUnit.UsLegalCup, uslegalcupQuantity.Unit); - - var usounceQuantity = cubicmeter.ToUnit(VolumeUnit.UsOunce); - AssertEx.EqualTolerance(UsOuncesInOneCubicMeter, (double)usounceQuantity.Value, UsOuncesTolerance); - Assert.Equal(VolumeUnit.UsOunce, usounceQuantity.Unit); - - var uspintQuantity = cubicmeter.ToUnit(VolumeUnit.UsPint); - AssertEx.EqualTolerance(UsPintsInOneCubicMeter, (double)uspintQuantity.Value, UsPintsTolerance); - Assert.Equal(VolumeUnit.UsPint, uspintQuantity.Unit); - - var usquartQuantity = cubicmeter.ToUnit(VolumeUnit.UsQuart); - AssertEx.EqualTolerance(UsQuartsInOneCubicMeter, (double)usquartQuantity.Value, UsQuartsTolerance); - Assert.Equal(VolumeUnit.UsQuart, usquartQuantity.Unit); - - var ustablespoonQuantity = cubicmeter.ToUnit(VolumeUnit.UsTablespoon); - AssertEx.EqualTolerance(UsTablespoonsInOneCubicMeter, (double)ustablespoonQuantity.Value, UsTablespoonsTolerance); - Assert.Equal(VolumeUnit.UsTablespoon, ustablespoonQuantity.Unit); - - var usteaspoonQuantity = cubicmeter.ToUnit(VolumeUnit.UsTeaspoon); - AssertEx.EqualTolerance(UsTeaspoonsInOneCubicMeter, (double)usteaspoonQuantity.Value, UsTeaspoonsTolerance); - Assert.Equal(VolumeUnit.UsTeaspoon, usteaspoonQuantity.Unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Volume cubicmeter = Volume.FromCubicMeters(1); - AssertEx.EqualTolerance(1, Volume.FromAuTablespoons(cubicmeter.AuTablespoons).CubicMeters, AuTablespoonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromCentiliters(cubicmeter.Centiliters).CubicMeters, CentilitersTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicCentimeters(cubicmeter.CubicCentimeters).CubicMeters, CubicCentimetersTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicDecimeters(cubicmeter.CubicDecimeters).CubicMeters, CubicDecimetersTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicFeet(cubicmeter.CubicFeet).CubicMeters, CubicFeetTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicInches(cubicmeter.CubicInches).CubicMeters, CubicInchesTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicKilometers(cubicmeter.CubicKilometers).CubicMeters, CubicKilometersTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicMeters(cubicmeter.CubicMeters).CubicMeters, CubicMetersTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicMicrometers(cubicmeter.CubicMicrometers).CubicMeters, CubicMicrometersTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicMiles(cubicmeter.CubicMiles).CubicMeters, CubicMilesTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicMillimeters(cubicmeter.CubicMillimeters).CubicMeters, CubicMillimetersTolerance); - AssertEx.EqualTolerance(1, Volume.FromCubicYards(cubicmeter.CubicYards).CubicMeters, CubicYardsTolerance); - AssertEx.EqualTolerance(1, Volume.FromDeciliters(cubicmeter.Deciliters).CubicMeters, DecilitersTolerance); - AssertEx.EqualTolerance(1, Volume.FromHectocubicFeet(cubicmeter.HectocubicFeet).CubicMeters, HectocubicFeetTolerance); - AssertEx.EqualTolerance(1, Volume.FromHectocubicMeters(cubicmeter.HectocubicMeters).CubicMeters, HectocubicMetersTolerance); - AssertEx.EqualTolerance(1, Volume.FromHectoliters(cubicmeter.Hectoliters).CubicMeters, HectolitersTolerance); - AssertEx.EqualTolerance(1, Volume.FromImperialBeerBarrels(cubicmeter.ImperialBeerBarrels).CubicMeters, ImperialBeerBarrelsTolerance); - AssertEx.EqualTolerance(1, Volume.FromImperialGallons(cubicmeter.ImperialGallons).CubicMeters, ImperialGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromImperialOunces(cubicmeter.ImperialOunces).CubicMeters, ImperialOuncesTolerance); - AssertEx.EqualTolerance(1, Volume.FromKilocubicFeet(cubicmeter.KilocubicFeet).CubicMeters, KilocubicFeetTolerance); - AssertEx.EqualTolerance(1, Volume.FromKilocubicMeters(cubicmeter.KilocubicMeters).CubicMeters, KilocubicMetersTolerance); - AssertEx.EqualTolerance(1, Volume.FromKiloimperialGallons(cubicmeter.KiloimperialGallons).CubicMeters, KiloimperialGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromKilousGallons(cubicmeter.KilousGallons).CubicMeters, KilousGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromLiters(cubicmeter.Liters).CubicMeters, LitersTolerance); - AssertEx.EqualTolerance(1, Volume.FromMegacubicFeet(cubicmeter.MegacubicFeet).CubicMeters, MegacubicFeetTolerance); - AssertEx.EqualTolerance(1, Volume.FromMegaimperialGallons(cubicmeter.MegaimperialGallons).CubicMeters, MegaimperialGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromMegausGallons(cubicmeter.MegausGallons).CubicMeters, MegausGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromMetricCups(cubicmeter.MetricCups).CubicMeters, MetricCupsTolerance); - AssertEx.EqualTolerance(1, Volume.FromMetricTeaspoons(cubicmeter.MetricTeaspoons).CubicMeters, MetricTeaspoonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromMicroliters(cubicmeter.Microliters).CubicMeters, MicrolitersTolerance); - AssertEx.EqualTolerance(1, Volume.FromMilliliters(cubicmeter.Milliliters).CubicMeters, MillilitersTolerance); - AssertEx.EqualTolerance(1, Volume.FromOilBarrels(cubicmeter.OilBarrels).CubicMeters, OilBarrelsTolerance); - AssertEx.EqualTolerance(1, Volume.FromUkTablespoons(cubicmeter.UkTablespoons).CubicMeters, UkTablespoonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromUsBeerBarrels(cubicmeter.UsBeerBarrels).CubicMeters, UsBeerBarrelsTolerance); - AssertEx.EqualTolerance(1, Volume.FromUsCustomaryCups(cubicmeter.UsCustomaryCups).CubicMeters, UsCustomaryCupsTolerance); - AssertEx.EqualTolerance(1, Volume.FromUsGallons(cubicmeter.UsGallons).CubicMeters, UsGallonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromUsLegalCups(cubicmeter.UsLegalCups).CubicMeters, UsLegalCupsTolerance); - AssertEx.EqualTolerance(1, Volume.FromUsOunces(cubicmeter.UsOunces).CubicMeters, UsOuncesTolerance); - AssertEx.EqualTolerance(1, Volume.FromUsPints(cubicmeter.UsPints).CubicMeters, UsPintsTolerance); - AssertEx.EqualTolerance(1, Volume.FromUsQuarts(cubicmeter.UsQuarts).CubicMeters, UsQuartsTolerance); - AssertEx.EqualTolerance(1, Volume.FromUsTablespoons(cubicmeter.UsTablespoons).CubicMeters, UsTablespoonsTolerance); - AssertEx.EqualTolerance(1, Volume.FromUsTeaspoons(cubicmeter.UsTeaspoons).CubicMeters, UsTeaspoonsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Volume v = Volume.FromCubicMeters(1); - AssertEx.EqualTolerance(-1, -v.CubicMeters, CubicMetersTolerance); - AssertEx.EqualTolerance(2, (Volume.FromCubicMeters(3)-v).CubicMeters, CubicMetersTolerance); - AssertEx.EqualTolerance(2, (v + v).CubicMeters, CubicMetersTolerance); - AssertEx.EqualTolerance(10, (v*10).CubicMeters, CubicMetersTolerance); - AssertEx.EqualTolerance(10, (10*v).CubicMeters, CubicMetersTolerance); - AssertEx.EqualTolerance(2, (Volume.FromCubicMeters(10)/5).CubicMeters, CubicMetersTolerance); - AssertEx.EqualTolerance(2, Volume.FromCubicMeters(10)/Volume.FromCubicMeters(5), CubicMetersTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Volume oneCubicMeter = Volume.FromCubicMeters(1); - Volume twoCubicMeters = Volume.FromCubicMeters(2); - - Assert.True(oneCubicMeter < twoCubicMeters); - Assert.True(oneCubicMeter <= twoCubicMeters); - Assert.True(twoCubicMeters > oneCubicMeter); - Assert.True(twoCubicMeters >= oneCubicMeter); - - Assert.False(oneCubicMeter > twoCubicMeters); - Assert.False(oneCubicMeter >= twoCubicMeters); - Assert.False(twoCubicMeters < oneCubicMeter); - Assert.False(twoCubicMeters <= oneCubicMeter); - } - - [Fact] - public void CompareToIsImplemented() - { - Volume cubicmeter = Volume.FromCubicMeters(1); - Assert.Equal(0, cubicmeter.CompareTo(cubicmeter)); - Assert.True(cubicmeter.CompareTo(Volume.Zero) > 0); - Assert.True(Volume.Zero.CompareTo(cubicmeter) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Volume cubicmeter = Volume.FromCubicMeters(1); - Assert.Throws(() => cubicmeter.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Volume cubicmeter = Volume.FromCubicMeters(1); - Assert.Throws(() => cubicmeter.CompareTo(null)); - } - - [Fact] - public void EqualsIsImplemented() - { - Volume v = Volume.FromCubicMeters(1); - Assert.True(v.Equals(Volume.FromCubicMeters(1), CubicMetersTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Volume.Zero, CubicMetersTolerance, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Volume cubicmeter = Volume.FromCubicMeters(1); - Assert.False(cubicmeter.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Volume cubicmeter = Volume.FromCubicMeters(1); - Assert.False(cubicmeter.Equals(null)); - } - - [Fact] - public void UnitsDoesNotContainUndefined() - { - Assert.DoesNotContain(VolumeUnit.Undefined, Volume.Units); - } - - [Fact] - public void AllUnitsHaveAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(VolumeUnit)).Cast(); - foreach(var unit in units) - { - if(unit == VolumeUnit.Undefined) - continue; - - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - } -}