diff --git a/UnitsNet.Tests/CustomCode/DurationTests.cs b/UnitsNet.Tests/CustomCode/DurationTests.cs index 488d3af6c4..e18f554810 100644 --- a/UnitsNet.Tests/CustomCode/DurationTests.cs +++ b/UnitsNet.Tests/CustomCode/DurationTests.cs @@ -207,5 +207,12 @@ public static void TimeSpanNotEqualToDurationShouldReturnCorrectly() Duration duration = Duration.FromHours(11); Assert.True(timeSpan != duration, "timeSpan should not be equal to duration"); } + + [Fact] + public void DurationTimesVolumeFlowEqualsVolume() + { + Volume volume = Duration.FromSeconds(20) * VolumeFlow.FromCubicMetersPerSecond(2); + Assert.Equal(Volume.FromCubicMeters(40), volume); + } } } \ No newline at end of file diff --git a/UnitsNet.Tests/CustomCode/VolumeFlowTests.cs b/UnitsNet.Tests/CustomCode/VolumeFlowTests.cs index c50bad344b..6f8cf81a49 100644 --- a/UnitsNet.Tests/CustomCode/VolumeFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeFlowTests.cs @@ -39,6 +39,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; +using Xunit; + namespace UnitsNet.Tests.CustomCode { public class VolumeFlowTests : VolumeFlowTestsBase @@ -88,5 +91,19 @@ public class VolumeFlowTests : VolumeFlowTestsBase protected override double UsGallonsPerHourInOneCubicMeterPerSecond => 9.510193884893328E5; protected override double UsGallonsPerSecondInOneCubicMeterPerSecond => 2.64172052358148E2; + + [Fact] + public void VolumeFlowTimesTimeSpanEqualsVolume() + { + Volume volume = VolumeFlow.FromCubicMetersPerSecond(20) * TimeSpan.FromSeconds(2); + Assert.Equal(Volume.FromCubicMeters(40), volume); + } + + [Fact] + public void VolumeFlowTimesDurationEqualsVolume() + { + Volume volume = VolumeFlow.FromCubicMetersPerSecond(20) * Duration.FromSeconds(2); + Assert.Equal(Volume.FromCubicMeters(40), volume); + } } } diff --git a/UnitsNet.Tests/CustomCode/VolumeTests.cs b/UnitsNet.Tests/CustomCode/VolumeTests.cs index 0336807c5d..aa67b625b4 100644 --- a/UnitsNet.Tests/CustomCode/VolumeTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeTests.cs @@ -19,6 +19,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; using Xunit; namespace UnitsNet.Tests.CustomCode @@ -125,5 +126,26 @@ public void VolumeTimesDensityEqualsMass() Mass mass = Volume.FromCubicMeters(2)*Density.FromKilogramsPerCubicMeter(3); Assert.Equal(mass, Mass.FromKilograms(6)); } + + [Fact] + public void VolumeDividedByTimeSpanEqualsVolumeFlow() + { + VolumeFlow volumeFlow = Volume.FromCubicMeters(20) / TimeSpan.FromSeconds(2); + Assert.Equal(VolumeFlow.FromCubicMetersPerSecond(10), volumeFlow); + } + + [Fact] + public void VolumeDividedByDurationEqualsVolumeFlow() + { + VolumeFlow volumeFlow = Volume.FromCubicMeters(20) / Duration.FromSeconds(2); + Assert.Equal(VolumeFlow.FromCubicMetersPerSecond(10), volumeFlow); + } + + [Fact] + public void VolumeDividedByVolumeFlowEqualsTimeSpan() + { + TimeSpan timeSpan = Volume.FromCubicMeters(20) / VolumeFlow.FromCubicMetersPerSecond(2); + Assert.Equal(TimeSpan.FromSeconds(10), timeSpan); + } } } \ No newline at end of file diff --git a/UnitsNet/CustomCode/Quantities/Duration.extra.cs b/UnitsNet/CustomCode/Quantities/Duration.extra.cs index 3730895672..3c465b8946 100644 --- a/UnitsNet/CustomCode/Quantities/Duration.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Duration.extra.cs @@ -113,6 +113,11 @@ public static explicit operator Duration(TimeSpan duration) { return timeSpan.TotalSeconds != duration.Seconds; } + + public static Volume operator *(Duration duration, VolumeFlow volumeFlow) + { + return Volume.FromCubicMeters(volumeFlow.CubicMetersPerSecond * duration.Seconds); + } #endif /// diff --git a/UnitsNet/CustomCode/Quantities/Volume.extra.cs b/UnitsNet/CustomCode/Quantities/Volume.extra.cs index ea69b973ee..4efd4d2ce6 100644 --- a/UnitsNet/CustomCode/Quantities/Volume.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Volume.extra.cs @@ -19,6 +19,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; + namespace UnitsNet { // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components @@ -41,6 +43,21 @@ public partial struct Volume { return Length.FromMeters(volume.CubicMeters / area.SquareMeters); } + + public static VolumeFlow operator /(Volume volume, Duration duration) + { + return VolumeFlow.FromCubicMetersPerSecond(volume.CubicMeters / duration.Seconds); + } + + public static VolumeFlow operator /(Volume volume, TimeSpan timeSpan) + { + return VolumeFlow.FromCubicMetersPerSecond(volume.CubicMeters / timeSpan.Seconds); + } + + public static TimeSpan operator /(Volume volume, VolumeFlow volumeFlow) + { + return TimeSpan.FromSeconds(volume.CubicMeters / volumeFlow.CubicMetersPerSecond); + } #endif } } \ No newline at end of file diff --git a/UnitsNet/CustomCode/Quantities/VolumeFlow.extra.cs b/UnitsNet/CustomCode/Quantities/VolumeFlow.extra.cs new file mode 100644 index 0000000000..d38026aba9 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/VolumeFlow.extra.cs @@ -0,0 +1,48 @@ +// 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; + +namespace UnitsNet +{ + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class VolumeFlow +#else + public partial struct VolumeFlow +#endif + { + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static Volume operator *(VolumeFlow volumeFlow, TimeSpan timeSpan) + { + return Volume.FromCubicMeters(volumeFlow.CubicMetersPerSecond * timeSpan.Seconds); + } + + public static Volume operator *(VolumeFlow volumeFlow, Duration duration) + { + return Volume.FromCubicMeters(volumeFlow.CubicMetersPerSecond * duration.Seconds); + } +#endif + } +} \ No newline at end of file