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
16 changes: 16 additions & 0 deletions UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@


using System;
using UnitsNet.Units;
using Xunit;

namespace UnitsNet.Tests.CustomCode
{
Expand All @@ -31,5 +33,19 @@ public class ElectricConductivityTests : ElectricConductivityTestsBase
protected override double SiemensPerMeterInOneSiemensPerMeter => 1;
protected override double SiemensPerInchInOneSiemensPerMeter => 2.54e-2;
protected override double SiemensPerFootInOneSiemensPerMeter => 3.048e-1;

[Theory]
[InlineData( -1.0, -1.0 )]
[InlineData( -2.0, -0.5 )]
[InlineData( 0.0, 0.0 )]
[InlineData( 1.0, 1.0 )]
[InlineData( 2.0, 0.5 )]
public static void InverseTest( double value, double expected )
{
var unit = new ElectricConductivity( value, ElectricConductivityUnit.SiemensPerMeter );
var inverse = unit.Inverse();

AssertEx.Equals( expected, inverse.OhmMeters );
}
}
}
16 changes: 16 additions & 0 deletions UnitsNet.Tests/CustomCode/ElectricResistivityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@


using System;
using UnitsNet.Units;
using Xunit;

namespace UnitsNet.Tests.CustomCode
{
Expand Down Expand Up @@ -55,5 +57,19 @@ public class ElectricResistivityTests : ElectricResistivityTestsBase
protected override double PicoohmsCentimeterInOneOhmMeter => 1e14;

protected override double PicoohmMetersInOneOhmMeter => 1e+12;

[Theory]
[InlineData( -1.0, -1.0 )]
[InlineData( -2.0, -0.5 )]
[InlineData( 0.0, 0.0 )]
[InlineData( 1.0, 1.0 )]
[InlineData( 2.0, 0.5 )]
public static void InverseTest( double value, double expected )
{
var unit = new ElectricResistivity( value, ElectricResistivityUnit.OhmMeter );
var inverse = unit.Inverse();

AssertEx.Equals( expected, inverse.SiemensPerMeter );
}
}
}
22 changes: 22 additions & 0 deletions UnitsNet/CustomCode/Quantities/ElectricConductivity.extra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

using UnitsNet.Units;

namespace UnitsNet
{
public partial struct ElectricConductivity
{
/// <summary>
/// Calculates the inverse or <see cref="ElectricResistivity"/> of this unit.
/// </summary>
/// <returns>The inverse or <see cref="ElectricResistivity"/> of this unit.</returns>
public ElectricResistivity Inverse()
{
if( SiemensPerMeter == 0.0 )
return new ElectricResistivity( 0.0, ElectricResistivityUnit.OhmMeter );

return new ElectricResistivity( 1 / SiemensPerMeter, ElectricResistivityUnit.OhmMeter );
}
}
}
22 changes: 22 additions & 0 deletions UnitsNet/CustomCode/Quantities/ElectricResistivity.extra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.

using UnitsNet.Units;

namespace UnitsNet
{
public partial struct ElectricResistivity
{
/// <summary>
/// Calculates the inverse or <see cref="ElectricConductivity"/> of this unit.
/// </summary>
/// <returns>The inverse or <see cref="ElectricConductivity"/> of this unit.</returns>
public ElectricConductivity Inverse()
{
if( OhmMeters == 0.0 )
return new ElectricConductivity( 0, ElectricConductivityUnit.SiemensPerMeter );

return new ElectricConductivity( 1 / OhmMeters, ElectricConductivityUnit.SiemensPerMeter );
}
}
}