Skip to content

Commit

Permalink
Add micropascalseconds (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferit Tunçer authored and angularsen committed Nov 7, 2017
1 parent 0a585b8 commit aa9a99a
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 17 deletions.
1 change: 1 addition & 0 deletions UnitsNet.Tests/CustomCode/DynamicViscosityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace UnitsNet.Tests.CustomCode
public class DynamicViscosityTests : DynamicViscosityTestsBase
{
protected override double CentipoiseInOneNewtonSecondPerMeterSquared => 1e3;
protected override double MicropascalSecondsInOneNewtonSecondPerMeterSquared => 1e6;
protected override double MillipascalSecondsInOneNewtonSecondPerMeterSquared => 1e3;
protected override double NewtonSecondsPerMeterSquaredInOneNewtonSecondPerMeterSquared => 1;
protected override double PascalSecondsInOneNewtonSecondPerMeterSquared => 1;
Expand Down
6 changes: 6 additions & 0 deletions UnitsNet.Tests/GeneratedCode/DynamicViscosityTestsBase.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ namespace UnitsNet.Tests
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; } }
Expand All @@ -71,6 +73,7 @@ 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);
Expand All @@ -81,6 +84,7 @@ public void NewtonSecondPerMeterSquaredToDynamicViscosityUnits()
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);
Expand All @@ -92,6 +96,7 @@ 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);
Expand All @@ -103,6 +108,7 @@ 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,40 @@ public static class NumberToDynamicViscosityExtensions

#endregion

#region MicropascalSecond

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double)"/>
public static DynamicViscosity MicropascalSeconds(this int value) => DynamicViscosity.FromMicropascalSeconds(value);

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double?)"/>
public static DynamicViscosity? MicropascalSeconds(this int? value) => DynamicViscosity.FromMicropascalSeconds(value);

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double)"/>
public static DynamicViscosity MicropascalSeconds(this long value) => DynamicViscosity.FromMicropascalSeconds(value);

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double?)"/>
public static DynamicViscosity? MicropascalSeconds(this long? value) => DynamicViscosity.FromMicropascalSeconds(value);

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double)"/>
public static DynamicViscosity MicropascalSeconds(this double value) => DynamicViscosity.FromMicropascalSeconds(value);

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double?)"/>
public static DynamicViscosity? MicropascalSeconds(this double? value) => DynamicViscosity.FromMicropascalSeconds(value);

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double)"/>
public static DynamicViscosity MicropascalSeconds(this float value) => DynamicViscosity.FromMicropascalSeconds(value);

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double?)"/>
public static DynamicViscosity? MicropascalSeconds(this float? value) => DynamicViscosity.FromMicropascalSeconds(value);

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double)"/>
public static DynamicViscosity MicropascalSeconds(this decimal value) => DynamicViscosity.FromMicropascalSeconds(Convert.ToDouble(value));

/// <inheritdoc cref="DynamicViscosity.FromMicropascalSeconds(double?)"/>
public static DynamicViscosity? MicropascalSeconds(this decimal? value) => DynamicViscosity.FromMicropascalSeconds(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

#region MillipascalSecond

/// <inheritdoc cref="DynamicViscosity.FromMillipascalSeconds(double)"/>
Expand Down
112 changes: 112 additions & 0 deletions UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ public double Centipoise
get { return (_newtonSecondsPerMeterSquared*10) / 1e-2d; }
}

/// <summary>
/// Get DynamicViscosity in MicropascalSeconds.
/// </summary>
public double MicropascalSeconds
{
get { return (_newtonSecondsPerMeterSquared) / 1e-6d; }
}

/// <summary>
/// Get DynamicViscosity in MillipascalSeconds.
/// </summary>
Expand Down Expand Up @@ -216,6 +224,44 @@ public static DynamicViscosity FromCentipoise(decimal centipoise)
}
#endif

/// <summary>
/// Get DynamicViscosity from MicropascalSeconds.
/// </summary>
#if NETFX_CORE
[Windows.Foundation.Metadata.DefaultOverload]
#endif
public static DynamicViscosity FromMicropascalSeconds(double micropascalseconds)
{
return new DynamicViscosity((micropascalseconds) * 1e-6d);
}

/// <summary>
/// Get DynamicViscosity from MicropascalSeconds.
/// </summary>
public static DynamicViscosity FromMicropascalSeconds(int micropascalseconds)
{
return new DynamicViscosity((micropascalseconds) * 1e-6d);
}

/// <summary>
/// Get DynamicViscosity from MicropascalSeconds.
/// </summary>
public static DynamicViscosity FromMicropascalSeconds(long micropascalseconds)
{
return new DynamicViscosity((micropascalseconds) * 1e-6d);
}

// Windows Runtime Component does not support decimal type
#if !WINDOWS_UWP
/// <summary>
/// Get DynamicViscosity from MicropascalSeconds of type decimal.
/// </summary>
public static DynamicViscosity FromMicropascalSeconds(decimal micropascalseconds)
{
return new DynamicViscosity((Convert.ToDouble(micropascalseconds)) * 1e-6d);
}
#endif

/// <summary>
/// Get DynamicViscosity from MillipascalSeconds.
/// </summary>
Expand Down Expand Up @@ -430,6 +476,66 @@ public static DynamicViscosity FromPoise(decimal poise)
}
}

/// <summary>
/// Get nullable DynamicViscosity from nullable MicropascalSeconds.
/// </summary>
public static DynamicViscosity? FromMicropascalSeconds(double? micropascalseconds)
{
if (micropascalseconds.HasValue)
{
return FromMicropascalSeconds(micropascalseconds.Value);
}
else
{
return null;
}
}

/// <summary>
/// Get nullable DynamicViscosity from nullable MicropascalSeconds.
/// </summary>
public static DynamicViscosity? FromMicropascalSeconds(int? micropascalseconds)
{
if (micropascalseconds.HasValue)
{
return FromMicropascalSeconds(micropascalseconds.Value);
}
else
{
return null;
}
}

/// <summary>
/// Get nullable DynamicViscosity from nullable MicropascalSeconds.
/// </summary>
public static DynamicViscosity? FromMicropascalSeconds(long? micropascalseconds)
{
if (micropascalseconds.HasValue)
{
return FromMicropascalSeconds(micropascalseconds.Value);
}
else
{
return null;
}
}

/// <summary>
/// Get nullable DynamicViscosity from MicropascalSeconds of type decimal.
/// </summary>
public static DynamicViscosity? FromMicropascalSeconds(decimal? micropascalseconds)
{
if (micropascalseconds.HasValue)
{
return FromMicropascalSeconds(micropascalseconds.Value);
}
else
{
return null;
}
}

/// <summary>
/// Get nullable DynamicViscosity from nullable MillipascalSeconds.
/// </summary>
Expand Down Expand Up @@ -684,6 +790,8 @@ public static DynamicViscosity From(double val, DynamicViscosityUnit fromUnit)
{
case DynamicViscosityUnit.Centipoise:
return FromCentipoise(val);
case DynamicViscosityUnit.MicropascalSecond:
return FromMicropascalSeconds(val);
case DynamicViscosityUnit.MillipascalSecond:
return FromMillipascalSeconds(val);
case DynamicViscosityUnit.NewtonSecondPerMeterSquared:
Expand Down Expand Up @@ -716,6 +824,8 @@ public static DynamicViscosity From(double val, DynamicViscosityUnit fromUnit)
{
case DynamicViscosityUnit.Centipoise:
return FromCentipoise(value.Value);
case DynamicViscosityUnit.MicropascalSecond:
return FromMicropascalSeconds(value.Value);
case DynamicViscosityUnit.MillipascalSecond:
return FromMillipascalSeconds(value.Value);
case DynamicViscosityUnit.NewtonSecondPerMeterSquared:
Expand Down Expand Up @@ -883,6 +993,8 @@ public double As(DynamicViscosityUnit unit)
{
case DynamicViscosityUnit.Centipoise:
return Centipoise;
case DynamicViscosityUnit.MicropascalSecond:
return MicropascalSeconds;
case DynamicViscosityUnit.MillipascalSecond:
return MillipascalSeconds;
case DynamicViscosityUnit.NewtonSecondPerMeterSquared:
Expand Down
2 changes: 1 addition & 1 deletion UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
namespace UnitsNet
{
/// <summary>
///
/// Molar entropy is amount of energy required to increase temperature of 1 mole substance by 1 Kelvin.
/// </summary>
// ReSharper disable once PartialTypeWithSinglePart

Expand Down
2 changes: 1 addition & 1 deletion UnitsNet/GeneratedCode/QuantityType.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public enum QuantityType
Mass,
MassFlow,
MassMomentOfInertia,
MolarEntropy,
MolarEnergy,
MolarEntropy,
Molarity,
MolarMass,
Power,
Expand Down
35 changes: 21 additions & 14 deletions UnitsNet/GeneratedCode/UnitSystem.Default.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
{
new AbbreviationsForCulture("en-US", "cP"),
}),
new CulturesForEnumValue((int) DynamicViscosityUnit.MicropascalSecond,
new[]
{
new AbbreviationsForCulture("en-US", "µPaS"),
}),
new CulturesForEnumValue((int) DynamicViscosityUnit.MillipascalSecond,
new[]
{
Expand Down Expand Up @@ -1953,40 +1958,42 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
new AbbreviationsForCulture("en-US", "t·mm²"),
}),
}),
new UnitLocalization(typeof (MolarEntropyUnit),
new UnitLocalization(typeof (MolarEnergyUnit),
new[]
{
new CulturesForEnumValue((int) MolarEntropyUnit.JoulePerMoleKelvin,
new CulturesForEnumValue((int) MolarEnergyUnit.JoulePerMole,
new[]
{
new AbbreviationsForCulture("en-US", "J/(mol*K)"),
new AbbreviationsForCulture("en-US", "J/mol"),
}),
new CulturesForEnumValue((int) MolarEntropyUnit.KilojoulePerMoleKelvin,
new CulturesForEnumValue((int) MolarEnergyUnit.KilojoulePerMole,
new[]
{
new AbbreviationsForCulture("en-US", "kJ/(mol*K)"),
new AbbreviationsForCulture("en-US", "kJ/mol"),
}),
new CulturesForEnumValue((int) MolarEntropyUnit.MegajoulePerMoleKelvin,
new CulturesForEnumValue((int) MolarEnergyUnit.MegajoulePerMole,
new[]
{
new AbbreviationsForCulture("en-US", "MJ/(mol*K)"),
new UnitLocalization(typeof (MolarEnergyUnit),
new AbbreviationsForCulture("en-US", "MJ/mol"),
}),
}),
new UnitLocalization(typeof (MolarEntropyUnit),
new[]
{
new CulturesForEnumValue((int) MolarEnergyUnit.JoulePerMole,
new CulturesForEnumValue((int) MolarEntropyUnit.JoulePerMoleKelvin,
new[]
{
new AbbreviationsForCulture("en-US", "J/mol"),
new AbbreviationsForCulture("en-US", "J/(mol*K)"),
}),
new CulturesForEnumValue((int) MolarEnergyUnit.KilojoulePerMole,
new CulturesForEnumValue((int) MolarEntropyUnit.KilojoulePerMoleKelvin,
new[]
{
new AbbreviationsForCulture("en-US", "kJ/mol"),
new AbbreviationsForCulture("en-US", "kJ/(mol*K)"),
}),
new CulturesForEnumValue((int) MolarEnergyUnit.MegajoulePerMole,
new CulturesForEnumValue((int) MolarEntropyUnit.MegajoulePerMoleKelvin,
new[]
{
new AbbreviationsForCulture("en-US", "MJ/mol"),
new AbbreviationsForCulture("en-US", "MJ/(mol*K)"),
}),
}),
new UnitLocalization(typeof (MolarityUnit),
Expand Down
1 change: 1 addition & 0 deletions UnitsNet/GeneratedCode/Units/DynamicViscosityUnit.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum DynamicViscosityUnit
{
Undefined = 0,
Centipoise,
MicropascalSecond,
MillipascalSecond,
NewtonSecondPerMeterSquared,
PascalSecond,
Expand Down
2 changes: 1 addition & 1 deletion UnitsNet/UnitDefinitions/DynamicViscosity.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"PluralName": "PascalSeconds",
"FromUnitToBaseFunc": "x",
"FromBaseToUnitFunc": "x",
"Prefixes": [ "Milli" ],
"Prefixes": [ "Milli", "Micro" ],
"Localization": [
{
"Culture": "en-US",
Expand Down

0 comments on commit aa9a99a

Please sign in to comment.