Skip to content

Commit

Permalink
Fix LapseRate Units (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferit Tunçer authored and angularsen committed Nov 11, 2017
1 parent c94c1d2 commit 90d5f93
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 299 deletions.
5 changes: 2 additions & 3 deletions UnitsNet.Tests/CustomCode/LapseRateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// </auto-generated>
//------------------------------------------------------------------------------

// Copyright (c) 2007 Andreas Gullberg Larsen (angularsen@gmail.com).
// Copyright (c) 2007 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
Expand Down Expand Up @@ -46,7 +46,6 @@ namespace UnitsNet.Tests.CustomCode
{
public class LapseRateTests : LapseRateTestsBase
{
protected override double DegreesCelciusPerMeterInOneDegreeCelsiusPerMeter => 1e0;
protected override double KilodegreesCelciusPerMeterInOneDegreeCelsiusPerMeter => 1e-3;
protected override double DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer => 1e0;
}
}
98 changes: 46 additions & 52 deletions UnitsNet.Tests/GeneratedCode/LapseRateTestsBase.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,104 +52,98 @@ namespace UnitsNet.Tests
// ReSharper disable once PartialTypeWithSinglePart
public abstract partial class LapseRateTestsBase
{
protected abstract double DegreesCelciusPerMeterInOneDegreeCelsiusPerMeter { get; }
protected abstract double KilodegreesCelciusPerMeterInOneDegreeCelsiusPerMeter { get; }
protected abstract double DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer { get; }

// ReSharper disable VirtualMemberNeverOverriden.Global
protected virtual double DegreesCelciusPerMeterTolerance { get { return 1e-5; } }
protected virtual double KilodegreesCelciusPerMeterTolerance { get { return 1e-5; } }
protected virtual double DegreesCelciusPerKilometerTolerance { get { return 1e-5; } }
// ReSharper restore VirtualMemberNeverOverriden.Global

[Fact]
public void DegreeCelsiusPerMeterToLapseRateUnits()
public void DegreeCelsiusPerKilometerToLapseRateUnits()
{
LapseRate degreecelsiuspermeter = LapseRate.FromDegreesCelciusPerMeter(1);
AssertEx.EqualTolerance(DegreesCelciusPerMeterInOneDegreeCelsiusPerMeter, degreecelsiuspermeter.DegreesCelciusPerMeter, DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(KilodegreesCelciusPerMeterInOneDegreeCelsiusPerMeter, degreecelsiuspermeter.KilodegreesCelciusPerMeter, KilodegreesCelciusPerMeterTolerance);
LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1);
AssertEx.EqualTolerance(DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer, degreecelsiusperkilometer.DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance);
}

[Fact]
public void FromValueAndUnit()
{
AssertEx.EqualTolerance(1, LapseRate.From(1, LapseRateUnit.DegreeCelsiusPerMeter).DegreesCelciusPerMeter, DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(1, LapseRate.From(1, LapseRateUnit.KilodegreeCelsiusPerMeter).KilodegreesCelciusPerMeter, KilodegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(1, LapseRate.From(1, LapseRateUnit.DegreeCelsiusPerKilometer).DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance);
}

[Fact]
public void As()
{
var degreecelsiuspermeter = LapseRate.FromDegreesCelciusPerMeter(1);
AssertEx.EqualTolerance(DegreesCelciusPerMeterInOneDegreeCelsiusPerMeter, degreecelsiuspermeter.As(LapseRateUnit.DegreeCelsiusPerMeter), DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(KilodegreesCelciusPerMeterInOneDegreeCelsiusPerMeter, degreecelsiuspermeter.As(LapseRateUnit.KilodegreeCelsiusPerMeter), KilodegreesCelciusPerMeterTolerance);
var degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1);
AssertEx.EqualTolerance(DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer, degreecelsiusperkilometer.As(LapseRateUnit.DegreeCelsiusPerKilometer), DegreesCelciusPerKilometerTolerance);
}

[Fact]
public void ConversionRoundTrip()
{
LapseRate degreecelsiuspermeter = LapseRate.FromDegreesCelciusPerMeter(1);
AssertEx.EqualTolerance(1, LapseRate.FromDegreesCelciusPerMeter(degreecelsiuspermeter.DegreesCelciusPerMeter).DegreesCelciusPerMeter, DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(1, LapseRate.FromKilodegreesCelciusPerMeter(degreecelsiuspermeter.KilodegreesCelciusPerMeter).DegreesCelciusPerMeter, KilodegreesCelciusPerMeterTolerance);
LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1);
AssertEx.EqualTolerance(1, LapseRate.FromDegreesCelciusPerKilometer(degreecelsiusperkilometer.DegreesCelciusPerKilometer).DegreesCelciusPerKilometer, DegreesCelciusPerKilometerTolerance);
}

[Fact]
public void ArithmeticOperators()
{
LapseRate v = LapseRate.FromDegreesCelciusPerMeter(1);
AssertEx.EqualTolerance(-1, -v.DegreesCelciusPerMeter, DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(2, (LapseRate.FromDegreesCelciusPerMeter(3)-v).DegreesCelciusPerMeter, DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(2, (v + v).DegreesCelciusPerMeter, DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(10, (v*10).DegreesCelciusPerMeter, DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(10, (10*v).DegreesCelciusPerMeter, DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(2, (LapseRate.FromDegreesCelciusPerMeter(10)/5).DegreesCelciusPerMeter, DegreesCelciusPerMeterTolerance);
AssertEx.EqualTolerance(2, LapseRate.FromDegreesCelciusPerMeter(10)/LapseRate.FromDegreesCelciusPerMeter(5), DegreesCelciusPerMeterTolerance);
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 oneDegreeCelsiusPerMeter = LapseRate.FromDegreesCelciusPerMeter(1);
LapseRate twoDegreesCelciusPerMeter = LapseRate.FromDegreesCelciusPerMeter(2);

Assert.True(oneDegreeCelsiusPerMeter < twoDegreesCelciusPerMeter);
Assert.True(oneDegreeCelsiusPerMeter <= twoDegreesCelciusPerMeter);
Assert.True(twoDegreesCelciusPerMeter > oneDegreeCelsiusPerMeter);
Assert.True(twoDegreesCelciusPerMeter >= oneDegreeCelsiusPerMeter);

Assert.False(oneDegreeCelsiusPerMeter > twoDegreesCelciusPerMeter);
Assert.False(oneDegreeCelsiusPerMeter >= twoDegreesCelciusPerMeter);
Assert.False(twoDegreesCelciusPerMeter < oneDegreeCelsiusPerMeter);
Assert.False(twoDegreesCelciusPerMeter <= oneDegreeCelsiusPerMeter);
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 degreecelsiuspermeter = LapseRate.FromDegreesCelciusPerMeter(1);
Assert.Equal(0, degreecelsiuspermeter.CompareTo(degreecelsiuspermeter));
Assert.True(degreecelsiuspermeter.CompareTo(LapseRate.Zero) > 0);
Assert.True(LapseRate.Zero.CompareTo(degreecelsiuspermeter) < 0);
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 degreecelsiuspermeter = LapseRate.FromDegreesCelciusPerMeter(1);
Assert.Throws<ArgumentException>(() => degreecelsiuspermeter.CompareTo(new object()));
LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1);
Assert.Throws<ArgumentException>(() => degreecelsiusperkilometer.CompareTo(new object()));
}

[Fact]
public void CompareToThrowsOnNull()
{
LapseRate degreecelsiuspermeter = LapseRate.FromDegreesCelciusPerMeter(1);
Assert.Throws<ArgumentNullException>(() => degreecelsiuspermeter.CompareTo(null));
LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1);
Assert.Throws<ArgumentNullException>(() => degreecelsiusperkilometer.CompareTo(null));
}


[Fact]
public void EqualityOperators()
{
LapseRate a = LapseRate.FromDegreesCelciusPerMeter(1);
LapseRate b = LapseRate.FromDegreesCelciusPerMeter(2);
LapseRate a = LapseRate.FromDegreesCelciusPerKilometer(1);
LapseRate b = LapseRate.FromDegreesCelciusPerKilometer(2);

// ReSharper disable EqualExpressionComparison
Assert.True(a == a);
Expand All @@ -163,23 +157,23 @@ public void EqualityOperators()
[Fact]
public void EqualsIsImplemented()
{
LapseRate v = LapseRate.FromDegreesCelciusPerMeter(1);
Assert.True(v.Equals(LapseRate.FromDegreesCelciusPerMeter(1)));
LapseRate v = LapseRate.FromDegreesCelciusPerKilometer(1);
Assert.True(v.Equals(LapseRate.FromDegreesCelciusPerKilometer(1)));
Assert.False(v.Equals(LapseRate.Zero));
}

[Fact]
public void EqualsReturnsFalseOnTypeMismatch()
{
LapseRate degreecelsiuspermeter = LapseRate.FromDegreesCelciusPerMeter(1);
Assert.False(degreecelsiuspermeter.Equals(new object()));
LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1);
Assert.False(degreecelsiusperkilometer.Equals(new object()));
}

[Fact]
public void EqualsReturnsFalseOnNull()
{
LapseRate degreecelsiuspermeter = LapseRate.FromDegreesCelciusPerMeter(1);
Assert.False(degreecelsiuspermeter.Equals(null));
LapseRate degreecelsiusperkilometer = LapseRate.FromDegreesCelciusPerKilometer(1);
Assert.False(degreecelsiusperkilometer.Equals(null));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,71 +44,37 @@ namespace UnitsNet.Extensions.NumberToLapseRate
{
public static class NumberToLapseRateExtensions
{
#region DegreeCelsiusPerMeter
#region DegreeCelsiusPerKilometer

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double)"/>
public static LapseRate DegreesCelciusPerMeter(this int value) => LapseRate.FromDegreesCelciusPerMeter(value);
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double)"/>
public static LapseRate DegreesCelciusPerKilometer(this int value) => LapseRate.FromDegreesCelciusPerKilometer(value);

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double?)"/>
public static LapseRate? DegreesCelciusPerMeter(this int? value) => LapseRate.FromDegreesCelciusPerMeter(value);
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double?)"/>
public static LapseRate? DegreesCelciusPerKilometer(this int? value) => LapseRate.FromDegreesCelciusPerKilometer(value);

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double)"/>
public static LapseRate DegreesCelciusPerMeter(this long value) => LapseRate.FromDegreesCelciusPerMeter(value);
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double)"/>
public static LapseRate DegreesCelciusPerKilometer(this long value) => LapseRate.FromDegreesCelciusPerKilometer(value);

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double?)"/>
public static LapseRate? DegreesCelciusPerMeter(this long? value) => LapseRate.FromDegreesCelciusPerMeter(value);
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double?)"/>
public static LapseRate? DegreesCelciusPerKilometer(this long? value) => LapseRate.FromDegreesCelciusPerKilometer(value);

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double)"/>
public static LapseRate DegreesCelciusPerMeter(this double value) => LapseRate.FromDegreesCelciusPerMeter(value);
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double)"/>
public static LapseRate DegreesCelciusPerKilometer(this double value) => LapseRate.FromDegreesCelciusPerKilometer(value);

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double?)"/>
public static LapseRate? DegreesCelciusPerMeter(this double? value) => LapseRate.FromDegreesCelciusPerMeter(value);
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double?)"/>
public static LapseRate? DegreesCelciusPerKilometer(this double? value) => LapseRate.FromDegreesCelciusPerKilometer(value);

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double)"/>
public static LapseRate DegreesCelciusPerMeter(this float value) => LapseRate.FromDegreesCelciusPerMeter(value);
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double)"/>
public static LapseRate DegreesCelciusPerKilometer(this float value) => LapseRate.FromDegreesCelciusPerKilometer(value);

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double?)"/>
public static LapseRate? DegreesCelciusPerMeter(this float? value) => LapseRate.FromDegreesCelciusPerMeter(value);
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double?)"/>
public static LapseRate? DegreesCelciusPerKilometer(this float? value) => LapseRate.FromDegreesCelciusPerKilometer(value);

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double)"/>
public static LapseRate DegreesCelciusPerMeter(this decimal value) => LapseRate.FromDegreesCelciusPerMeter(Convert.ToDouble(value));
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double)"/>
public static LapseRate DegreesCelciusPerKilometer(this decimal value) => LapseRate.FromDegreesCelciusPerKilometer(Convert.ToDouble(value));

/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerMeter(double?)"/>
public static LapseRate? DegreesCelciusPerMeter(this decimal? value) => LapseRate.FromDegreesCelciusPerMeter(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

#region KilodegreeCelsiusPerMeter

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double)"/>
public static LapseRate KilodegreesCelciusPerMeter(this int value) => LapseRate.FromKilodegreesCelciusPerMeter(value);

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double?)"/>
public static LapseRate? KilodegreesCelciusPerMeter(this int? value) => LapseRate.FromKilodegreesCelciusPerMeter(value);

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double)"/>
public static LapseRate KilodegreesCelciusPerMeter(this long value) => LapseRate.FromKilodegreesCelciusPerMeter(value);

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double?)"/>
public static LapseRate? KilodegreesCelciusPerMeter(this long? value) => LapseRate.FromKilodegreesCelciusPerMeter(value);

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double)"/>
public static LapseRate KilodegreesCelciusPerMeter(this double value) => LapseRate.FromKilodegreesCelciusPerMeter(value);

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double?)"/>
public static LapseRate? KilodegreesCelciusPerMeter(this double? value) => LapseRate.FromKilodegreesCelciusPerMeter(value);

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double)"/>
public static LapseRate KilodegreesCelciusPerMeter(this float value) => LapseRate.FromKilodegreesCelciusPerMeter(value);

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double?)"/>
public static LapseRate? KilodegreesCelciusPerMeter(this float? value) => LapseRate.FromKilodegreesCelciusPerMeter(value);

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double)"/>
public static LapseRate KilodegreesCelciusPerMeter(this decimal value) => LapseRate.FromKilodegreesCelciusPerMeter(Convert.ToDouble(value));

/// <inheritdoc cref="LapseRate.FromKilodegreesCelciusPerMeter(double?)"/>
public static LapseRate? KilodegreesCelciusPerMeter(this decimal? value) => LapseRate.FromKilodegreesCelciusPerMeter(value == null ? (double?)null : Convert.ToDouble(value.Value));
/// <inheritdoc cref="LapseRate.FromDegreesCelciusPerKilometer(double?)"/>
public static LapseRate? DegreesCelciusPerKilometer(this decimal? value) => LapseRate.FromDegreesCelciusPerKilometer(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

Expand Down
Loading

0 comments on commit 90d5f93

Please sign in to comment.