Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UnitsNet.Tests/CustomCode/DurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
17 changes: 17 additions & 0 deletions UnitsNet.Tests/CustomCode/VolumeFlowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
22 changes: 22 additions & 0 deletions UnitsNet.Tests/CustomCode/VolumeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
5 changes: 5 additions & 0 deletions UnitsNet/CustomCode/Quantities/Duration.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
Expand Down
17 changes: 17 additions & 0 deletions UnitsNet/CustomCode/Quantities/Volume.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
48 changes: 48 additions & 0 deletions UnitsNet/CustomCode/Quantities/VolumeFlow.extra.cs
Original file line number Diff line number Diff line change
@@ -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
}
}