Skip to content

Commit 9c00fc7

Browse files
author
Erik Ovegard
committed
Added overloads for KinematicViscosity and some more for Density
1 parent adfc84a commit 9c00fc7

File tree

5 files changed

+144
-5
lines changed

5 files changed

+144
-5
lines changed

UnitsNet.Tests/CustomCode/DensityTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,26 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22+
using NUnit.Framework;
23+
2224
namespace UnitsNet.Tests.CustomCode
2325
{
2426
public class DensityTests : DensityTestsBase
2527
{
28+
[Test]
29+
public static void DensityTimesVolumeEqualsMass()
30+
{
31+
var mass = Density.FromKilogramsPerCubicMeter(2) * Volume.FromCubicMeters(3);
32+
Assert.AreEqual(mass, Mass.FromKilograms(6));
33+
}
34+
35+
[Test]
36+
public static void VolumeTimesDensityEqualsMass()
37+
{
38+
var mass = Volume.FromCubicMeters(3) * Density.FromKilogramsPerCubicMeter(2);
39+
Assert.AreEqual(mass, Mass.FromKilograms(6));
40+
}
41+
2642
protected override double KilogramsPerCubicCentimeterInOneKilogramPerCubicMeter
2743
{
2844
get { return 1e-6; }

UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,48 @@
2020
// THE SOFTWARE.
2121

2222

23+
using NUnit.Framework;
2324
using System;
2425

2526
namespace UnitsNet.Tests.CustomCode
2627
{
2728
public class KinematicViscosityTests : KinematicViscosityTestsBase
2829
{
30+
[Test]
31+
public static void KinematicViscosityDividedByLengthEqualsSpeed()
32+
{
33+
var speed = KinematicViscosity.FromSquareMetersPerSecond(4) / Length.FromMeters(2);
34+
Assert.AreEqual(speed, Speed.FromMetersPerSecond(2));
35+
}
36+
37+
[Test]
38+
public static void KinematicViscosityTimesTimeSpanEqualsArea()
39+
{
40+
var area = KinematicViscosity.FromSquareMetersPerSecond(4) * TimeSpan.FromSeconds(2);
41+
Assert.AreEqual(area, Area.FromSquareMeters(8));
42+
}
43+
44+
[Test]
45+
public static void TimeSpanTimesKinematicViscosityEqualsArea()
46+
{
47+
var area = TimeSpan.FromSeconds(2) * KinematicViscosity.FromSquareMetersPerSecond(4);
48+
Assert.AreEqual(area, Area.FromSquareMeters(8));
49+
}
50+
51+
[Test]
52+
public static void KinematicViscosityTimesDurationEqualsArea()
53+
{
54+
var area = KinematicViscosity.FromSquareMetersPerSecond(4) * Duration.FromSeconds(2);
55+
Assert.AreEqual(area, Area.FromSquareMeters(8));
56+
}
57+
58+
[Test]
59+
public static void DurationTimesKinematicViscosityEqualsArea()
60+
{
61+
var area = Duration.FromSeconds(2) * KinematicViscosity.FromSquareMetersPerSecond(4);
62+
Assert.AreEqual(area, Area.FromSquareMeters(8));
63+
}
64+
2965
#region Overrides of KinematicViscosityTestsBase
3066

3167
protected override double CentistokesInOneSquareMeterPerSecond
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/InitialForce/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
namespace UnitsNet
23+
{
24+
public partial struct Density
25+
{
26+
public static Mass operator *(Density density, Volume volume)
27+
{
28+
return Mass.FromKilograms(density.KilogramsPerCubicMeter * volume.CubicMeters);
29+
}
30+
31+
public static Mass operator *(Volume volume, Density density)
32+
{
33+
return Mass.FromKilograms(density.KilogramsPerCubicMeter * volume.CubicMeters);
34+
}
35+
}
36+
}
37+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright © 2007 by Initial Force AS. All rights reserved.
2+
// https://github.com/InitialForce/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
using System;
23+
24+
namespace UnitsNet
25+
{
26+
public partial struct KinematicViscosity
27+
{
28+
public static Speed operator /(KinematicViscosity kinematicViscosity, Length length)
29+
{
30+
return Speed.FromMetersPerSecond(kinematicViscosity.SquareMetersPerSecond / length.Meters);
31+
}
32+
33+
public static Area operator *(KinematicViscosity kinematicViscosity, TimeSpan timeSpan)
34+
{
35+
return Area.FromSquareMeters(kinematicViscosity.SquareMetersPerSecond * timeSpan.TotalSeconds);
36+
}
37+
38+
public static Area operator *(TimeSpan timeSpan, KinematicViscosity kinematicViscosity)
39+
{
40+
return Area.FromSquareMeters(kinematicViscosity.SquareMetersPerSecond * timeSpan.TotalSeconds);
41+
}
42+
43+
public static Area operator *(KinematicViscosity kinematicViscosity, Duration duration)
44+
{
45+
return Area.FromSquareMeters(kinematicViscosity.SquareMetersPerSecond * duration.Seconds);
46+
}
47+
48+
public static Area operator *(Duration duration, KinematicViscosity kinematicViscosity)
49+
{
50+
return Area.FromSquareMeters(kinematicViscosity.SquareMetersPerSecond * duration.Seconds);
51+
}
52+
}
53+
}
54+

UnitsNet/CustomCode/UnitClasses/Volume.extra.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@ namespace UnitsNet
2323
{
2424
public partial struct Volume
2525
{
26-
27-
public static Mass operator *(Volume volume, Density density)
28-
{
29-
return Mass.FromKilograms(volume.CubicMeters * density.KilogramsPerCubicMeter);
30-
}
3126
public static Area operator /(Volume volume, Length length)
3227
{
3328
return Area.FromSquareMeters(volume.CubicMeters / length.Meters);
3429
}
30+
3531
public static Length operator /(Volume volume, Area area)
3632
{
3733
return Length.FromMeters(volume.CubicMeters / area.SquareMeters);

0 commit comments

Comments
 (0)