Skip to content

Commit

Permalink
Merge branch 'eriove-feature/overloadsforviscosity'
Browse files Browse the repository at this point in the history
Fixes #161
  • Loading branch information
angularsen committed Apr 18, 2016
2 parents f252722 + ceeb381 commit 3826d21
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 2 deletions.
7 changes: 7 additions & 0 deletions UnitsNet.Tests/CustomCode/DensityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,12 @@ public static void VolumeTimesDensityEqualsMass()
Mass mass = Volume.FromCubicMeters(3)*Density.FromKilogramsPerCubicMeter(2);
Assert.AreEqual(mass, Mass.FromKilograms(6));
}

[Test]
public static void DensityTimesKinematicViscosityEqualsDynamicViscosity()
{
DynamicViscosity dynamicViscosity = Density.FromKilogramsPerCubicMeter(2) * KinematicViscosity.FromSquareMetersPerSecond(10);
Assert.AreEqual(dynamicViscosity, DynamicViscosity.FromNewtonSecondsPerMeterSquared(20));
}
}
}
6 changes: 6 additions & 0 deletions UnitsNet.Tests/CustomCode/DynamicViscosityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ public class DynamicViscosityTests : DynamicViscosityTestsBase
protected override double PascalSecondsInOneNewtonSecondPerMeterSquared => 1;
protected override double PoiseInOneNewtonSecondPerMeterSquared => 10;

[Test]
public static void DynamicViscosityDividedByDensityEqualsKinematicViscosity()
{
KinematicViscosity kinematicViscosity = DynamicViscosity.FromNewtonSecondsPerMeterSquared(10) / Density.FromKilogramsPerCubicMeter(2);
Assert.AreEqual(kinematicViscosity, KinematicViscosity.FromSquareMetersPerSecond(5));
}
}
}
7 changes: 7 additions & 0 deletions UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,12 @@ public static void TimeSpanTimesKinematicViscosityEqualsArea()
Area area = TimeSpan.FromSeconds(2)*KinematicViscosity.FromSquareMetersPerSecond(4);
Assert.AreEqual(area, Area.FromSquareMeters(8));
}

[Test]
public static void KinematicViscosityTimesDensityEqualsDynamicViscosity()
{
DynamicViscosity dynamicViscosity = KinematicViscosity.FromSquareMetersPerSecond(10) * Density.FromKilogramsPerCubicMeter(2);
Assert.AreEqual(dynamicViscosity, DynamicViscosity.FromNewtonSecondsPerMeterSquared(20));
}
}
}
7 changes: 7 additions & 0 deletions UnitsNet.Tests/CustomCode/LengthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public void LengthDividedBySpeedEqualsDuration()
Assert.AreEqual(Duration.FromSeconds(10), duration);
}

[Test]
public void LengthTimesSpeedEqualsKinematicViscosity()
{
KinematicViscosity kinematicViscosity = Length.FromMeters(20) * Speed.FromMetersPerSecond(2);
Assert.AreEqual(KinematicViscosity.FromSquareMetersPerSecond(40), kinematicViscosity);
}

[Test]
public void ToStringReturnsCorrectNumberAndUnitWithDefaultUnitWhichIsMeter()
{
Expand Down
9 changes: 8 additions & 1 deletion UnitsNet.Tests/CustomCode/SpeedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public void TimeSpanTimesSpeedEqualsLength()
Assert.AreEqual(length, Length.FromMeters(40));
}

[Test]
public void SpeedTimesLengthEqualsKinematicViscosity()
{
KinematicViscosity kinematicViscosity = Length.FromMeters(20) * Speed.FromMetersPerSecond(2);
Assert.AreEqual(KinematicViscosity.FromSquareMetersPerSecond(40), kinematicViscosity);
}

[Test]
public void SpeedTimesSpeedEqualsSpecificEnergy()
{
Expand All @@ -128,4 +135,4 @@ public void SpeedTimesSpeedEqualsSpecificEnergy()
Assert.AreEqual(length, SpecificEnergy.FromJoulesPerKilogram(40));
}
}
}
}
5 changes: 5 additions & 0 deletions UnitsNet/CustomCode/UnitClasses/Density.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ public partial struct Density
{
return Mass.FromKilograms(density.KilogramsPerCubicMeter*volume.CubicMeters);
}

public static DynamicViscosity operator *(Density density, KinematicViscosity kinematicViscosity)
{
return DynamicViscosity.FromNewtonSecondsPerMeterSquared(kinematicViscosity.SquareMetersPerSecond * density.KilogramsPerCubicMeter);
}
}
}
33 changes: 33 additions & 0 deletions UnitsNet/CustomCode/UnitClasses/DynamicViscosity.extra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright(c) 2007 Andreas Gullberg Larsen
// https://github.com/anjdreas/UnitsNet
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;

namespace UnitsNet
{
public partial struct DynamicViscosity
{
public static KinematicViscosity operator /(DynamicViscosity dynamicViscosity, Density density)
{
return KinematicViscosity.FromSquareMetersPerSecond(dynamicViscosity.NewtonSecondsPerMeterSquared / density.KilogramsPerCubicMeter);
}
}
}
5 changes: 5 additions & 0 deletions UnitsNet/CustomCode/UnitClasses/KinematicViscosity.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ public partial struct KinematicViscosity
{
return Area.FromSquareMeters(kinematicViscosity.SquareMetersPerSecond*duration.Seconds);
}

public static DynamicViscosity operator *(KinematicViscosity kinematicViscosity, Density density)
{
return DynamicViscosity.FromNewtonSecondsPerMeterSquared(kinematicViscosity.SquareMetersPerSecond * density.KilogramsPerCubicMeter);
}
}
}
5 changes: 5 additions & 0 deletions UnitsNet/CustomCode/UnitClasses/Length.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public static Length FromFeetInches(double feet, double inches)
{
return Torque.FromNewtonMeters(force.Newtons*length.Meters);
}

public static KinematicViscosity operator *(Length length, Speed speed)
{
return KinematicViscosity.FromSquareMetersPerSecond(length.Meters * speed.MetersPerSecond);
}
}

public class FeetInches
Expand Down
7 changes: 6 additions & 1 deletion UnitsNet/CustomCode/UnitClasses/Speed.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ public partial struct Speed
return Length.FromMeters(speed.MetersPerSecond*duration.Seconds);
}

public static KinematicViscosity operator *(Speed speed, Length length)
{
return KinematicViscosity.FromSquareMetersPerSecond(length.Meters * speed.MetersPerSecond);
}

public static SpecificEnergy operator *(Speed left, Speed right)
{
return SpecificEnergy.FromJoulesPerKilogram(left.MetersPerSecond * right.MetersPerSecond);
}
}
}
}

4 comments on commit 3826d21

@angularsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Units.NET :: CI Build 93 is now running

@angularsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Units.NET :: CI Build 93 outcome was SUCCESS
Summary: Tests passed: 728 Build time: 0:0:17

@angularsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Units.NET :: Master Build 35 is now running

@angularsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Units.NET :: Master Build 35 outcome was SUCCESS
Summary: Tests passed: 728 Build time: 0:0:22

Please sign in to comment.