Skip to content

Commit fac48df

Browse files
authored
Add inverse methods for electric conductivity and resistivity (#943)
1 parent 207363d commit fac48df

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323

2424
using System;
25+
using UnitsNet.Units;
26+
using Xunit;
2527

2628
namespace UnitsNet.Tests.CustomCode
2729
{
@@ -31,5 +33,19 @@ public class ElectricConductivityTests : ElectricConductivityTestsBase
3133
protected override double SiemensPerMeterInOneSiemensPerMeter => 1;
3234
protected override double SiemensPerInchInOneSiemensPerMeter => 2.54e-2;
3335
protected override double SiemensPerFootInOneSiemensPerMeter => 3.048e-1;
36+
37+
[Theory]
38+
[InlineData( -1.0, -1.0 )]
39+
[InlineData( -2.0, -0.5 )]
40+
[InlineData( 0.0, 0.0 )]
41+
[InlineData( 1.0, 1.0 )]
42+
[InlineData( 2.0, 0.5 )]
43+
public static void InverseTest( double value, double expected )
44+
{
45+
var unit = new ElectricConductivity( value, ElectricConductivityUnit.SiemensPerMeter );
46+
var inverse = unit.Inverse();
47+
48+
AssertEx.Equals( expected, inverse.OhmMeters );
49+
}
3450
}
3551
}

UnitsNet.Tests/CustomCode/ElectricResistivityTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323

2424
using System;
25+
using UnitsNet.Units;
26+
using Xunit;
2527

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

5759
protected override double PicoohmMetersInOneOhmMeter => 1e+12;
60+
61+
[Theory]
62+
[InlineData( -1.0, -1.0 )]
63+
[InlineData( -2.0, -0.5 )]
64+
[InlineData( 0.0, 0.0 )]
65+
[InlineData( 1.0, 1.0 )]
66+
[InlineData( 2.0, 0.5 )]
67+
public static void InverseTest( double value, double expected )
68+
{
69+
var unit = new ElectricResistivity( value, ElectricResistivityUnit.OhmMeter );
70+
var inverse = unit.Inverse();
71+
72+
AssertEx.Equals( expected, inverse.SiemensPerMeter );
73+
}
5874
}
5975
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
using UnitsNet.Units;
5+
6+
namespace UnitsNet
7+
{
8+
public partial struct ElectricConductivity
9+
{
10+
/// <summary>
11+
/// Calculates the inverse or <see cref="ElectricResistivity"/> of this unit.
12+
/// </summary>
13+
/// <returns>The inverse or <see cref="ElectricResistivity"/> of this unit.</returns>
14+
public ElectricResistivity Inverse()
15+
{
16+
if( SiemensPerMeter == 0.0 )
17+
return new ElectricResistivity( 0.0, ElectricResistivityUnit.OhmMeter );
18+
19+
return new ElectricResistivity( 1 / SiemensPerMeter, ElectricResistivityUnit.OhmMeter );
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
using UnitsNet.Units;
5+
6+
namespace UnitsNet
7+
{
8+
public partial struct ElectricResistivity
9+
{
10+
/// <summary>
11+
/// Calculates the inverse or <see cref="ElectricConductivity"/> of this unit.
12+
/// </summary>
13+
/// <returns>The inverse or <see cref="ElectricConductivity"/> of this unit.</returns>
14+
public ElectricConductivity Inverse()
15+
{
16+
if( OhmMeters == 0.0 )
17+
return new ElectricConductivity( 0, ElectricConductivityUnit.SiemensPerMeter );
18+
19+
return new ElectricConductivity( 1 / OhmMeters, ElectricConductivityUnit.SiemensPerMeter );
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)