Skip to content

Commit 68bfddd

Browse files
Adding the 'Siemens' unit to assist in measuring electric admittance.
1 parent 4b2c78c commit 68bfddd

File tree

8 files changed

+1267
-0
lines changed

8 files changed

+1267
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated (once) by \generate-code.bat, but will not be
4+
// regenerated when it already exists. The purpose of creating this file is to make
5+
// it easier to remember to implement all the unit conversion test cases.
6+
//
7+
// Whenever a new unit is added to this unit class and \generate-code.bat is run,
8+
// the base test class will get a new abstract property and cause a compile error
9+
// in this derived class, reminding the developer to implement the test case
10+
// for the new unit.
11+
//
12+
// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
13+
//
14+
// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes.
15+
// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior.
16+
// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes.
17+
//
18+
// </auto-generated>
19+
//------------------------------------------------------------------------------
20+
21+
// Copyright (c) 2007 Andreas Gullberg Larsen ([email protected]).
22+
// https://github.com/anjdreas/UnitsNet
23+
//
24+
// Permission is hereby granted, free of charge, to any person obtaining a copy
25+
// of this software and associated documentation files (the "Software"), to deal
26+
// in the Software without restriction, including without limitation the rights
27+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28+
// copies of the Software, and to permit persons to whom the Software is
29+
// furnished to do so, subject to the following conditions:
30+
//
31+
// The above copyright notice and this permission notice shall be included in
32+
// all copies or substantial portions of the Software.
33+
//
34+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
40+
// THE SOFTWARE.
41+
42+
43+
using System;
44+
45+
namespace UnitsNet.Tests.CustomCode
46+
{
47+
public class ElectricAdmittanceTests : ElectricAdmittanceTestsBase
48+
{
49+
protected override double MicrosiemensInOneSiemens => 1e+6;
50+
51+
protected override double MillisiemensInOneSiemens => 1000;
52+
53+
protected override double NanosiemensInOneSiemens => 1e+9;
54+
55+
protected override double SiemensInOneSiemens => 1;
56+
}
57+
}
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by \generate-code.bat.
4+
//
5+
// Changes to this file will be lost when the code is regenerated.
6+
// The build server regenerates the code before each build and a pre-build
7+
// step will regenerate the code on each local build.
8+
//
9+
// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
10+
//
11+
// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes.
12+
// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior.
13+
// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes.
14+
//
15+
// </auto-generated>
16+
//------------------------------------------------------------------------------
17+
18+
// Copyright (c) 2007 Andreas Gullberg Larsen ([email protected]).
19+
// https://github.com/anjdreas/UnitsNet
20+
//
21+
// Permission is hereby granted, free of charge, to any person obtaining a copy
22+
// of this software and associated documentation files (the "Software"), to deal
23+
// in the Software without restriction, including without limitation the rights
24+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25+
// copies of the Software, and to permit persons to whom the Software is
26+
// furnished to do so, subject to the following conditions:
27+
//
28+
// The above copyright notice and this permission notice shall be included in
29+
// all copies or substantial portions of the Software.
30+
//
31+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
37+
// THE SOFTWARE.
38+
39+
using System;
40+
using NUnit.Framework;
41+
using UnitsNet.Units;
42+
43+
// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else?
44+
#pragma warning disable 1718
45+
46+
// ReSharper disable once CheckNamespace
47+
namespace UnitsNet.Tests
48+
{
49+
/// <summary>
50+
/// Test of ElectricAdmittance.
51+
/// </summary>
52+
[TestFixture]
53+
// ReSharper disable once PartialTypeWithSinglePart
54+
public abstract partial class ElectricAdmittanceTestsBase
55+
{
56+
protected abstract double MicrosiemensInOneSiemens { get; }
57+
protected abstract double MillisiemensInOneSiemens { get; }
58+
protected abstract double NanosiemensInOneSiemens { get; }
59+
protected abstract double SiemensInOneSiemens { get; }
60+
61+
// ReSharper disable VirtualMemberNeverOverriden.Global
62+
protected virtual double MicrosiemensTolerance { get { return 1e-5; } }
63+
protected virtual double MillisiemensTolerance { get { return 1e-5; } }
64+
protected virtual double NanosiemensTolerance { get { return 1e-5; } }
65+
protected virtual double SiemensTolerance { get { return 1e-5; } }
66+
// ReSharper restore VirtualMemberNeverOverriden.Global
67+
68+
[Test]
69+
public void SiemensToElectricAdmittanceUnits()
70+
{
71+
ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);
72+
Assert.AreEqual(MicrosiemensInOneSiemens, siemens.Microsiemens, MicrosiemensTolerance);
73+
Assert.AreEqual(MillisiemensInOneSiemens, siemens.Millisiemens, MillisiemensTolerance);
74+
Assert.AreEqual(NanosiemensInOneSiemens, siemens.Nanosiemens, NanosiemensTolerance);
75+
Assert.AreEqual(SiemensInOneSiemens, siemens.Siemens, SiemensTolerance);
76+
}
77+
78+
[Test]
79+
public void FromValueAndUnit()
80+
{
81+
Assert.AreEqual(1, ElectricAdmittance.From(1, ElectricAdmittanceUnit.Microsiemens).Microsiemens, MicrosiemensTolerance);
82+
Assert.AreEqual(1, ElectricAdmittance.From(1, ElectricAdmittanceUnit.Millisiemens).Millisiemens, MillisiemensTolerance);
83+
Assert.AreEqual(1, ElectricAdmittance.From(1, ElectricAdmittanceUnit.Nanosiemens).Nanosiemens, NanosiemensTolerance);
84+
Assert.AreEqual(1, ElectricAdmittance.From(1, ElectricAdmittanceUnit.Siemens).Siemens, SiemensTolerance);
85+
}
86+
87+
[Test]
88+
public void As()
89+
{
90+
var siemens = ElectricAdmittance.FromSiemens(1);
91+
Assert.AreEqual(MicrosiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Microsiemens), MicrosiemensTolerance);
92+
Assert.AreEqual(MillisiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Millisiemens), MillisiemensTolerance);
93+
Assert.AreEqual(NanosiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Nanosiemens), NanosiemensTolerance);
94+
Assert.AreEqual(SiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Siemens), SiemensTolerance);
95+
}
96+
97+
[Test]
98+
public void ConversionRoundTrip()
99+
{
100+
ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);
101+
Assert.AreEqual(1, ElectricAdmittance.FromMicrosiemens(siemens.Microsiemens).Siemens, MicrosiemensTolerance);
102+
Assert.AreEqual(1, ElectricAdmittance.FromMillisiemens(siemens.Millisiemens).Siemens, MillisiemensTolerance);
103+
Assert.AreEqual(1, ElectricAdmittance.FromNanosiemens(siemens.Nanosiemens).Siemens, NanosiemensTolerance);
104+
Assert.AreEqual(1, ElectricAdmittance.FromSiemens(siemens.Siemens).Siemens, SiemensTolerance);
105+
}
106+
107+
[Test]
108+
public void ArithmeticOperators()
109+
{
110+
ElectricAdmittance v = ElectricAdmittance.FromSiemens(1);
111+
Assert.AreEqual(-1, -v.Siemens, SiemensTolerance);
112+
Assert.AreEqual(2, (ElectricAdmittance.FromSiemens(3)-v).Siemens, SiemensTolerance);
113+
Assert.AreEqual(2, (v + v).Siemens, SiemensTolerance);
114+
Assert.AreEqual(10, (v*10).Siemens, SiemensTolerance);
115+
Assert.AreEqual(10, (10*v).Siemens, SiemensTolerance);
116+
Assert.AreEqual(2, (ElectricAdmittance.FromSiemens(10)/5).Siemens, SiemensTolerance);
117+
Assert.AreEqual(2, ElectricAdmittance.FromSiemens(10)/ElectricAdmittance.FromSiemens(5), SiemensTolerance);
118+
}
119+
120+
[Test]
121+
public void ComparisonOperators()
122+
{
123+
ElectricAdmittance oneSiemens = ElectricAdmittance.FromSiemens(1);
124+
ElectricAdmittance twoSiemens = ElectricAdmittance.FromSiemens(2);
125+
126+
Assert.True(oneSiemens < twoSiemens);
127+
Assert.True(oneSiemens <= twoSiemens);
128+
Assert.True(twoSiemens > oneSiemens);
129+
Assert.True(twoSiemens >= oneSiemens);
130+
131+
Assert.False(oneSiemens > twoSiemens);
132+
Assert.False(oneSiemens >= twoSiemens);
133+
Assert.False(twoSiemens < oneSiemens);
134+
Assert.False(twoSiemens <= oneSiemens);
135+
}
136+
137+
[Test]
138+
public void CompareToIsImplemented()
139+
{
140+
ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);
141+
Assert.AreEqual(0, siemens.CompareTo(siemens));
142+
Assert.Greater(siemens.CompareTo(ElectricAdmittance.Zero), 0);
143+
Assert.Less(ElectricAdmittance.Zero.CompareTo(siemens), 0);
144+
}
145+
146+
[Test]
147+
[ExpectedException(typeof(ArgumentException))]
148+
public void CompareToThrowsOnTypeMismatch()
149+
{
150+
ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);
151+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
152+
siemens.CompareTo(new object());
153+
}
154+
155+
[Test]
156+
[ExpectedException(typeof(ArgumentNullException))]
157+
public void CompareToThrowsOnNull()
158+
{
159+
ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);
160+
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
161+
siemens.CompareTo(null);
162+
}
163+
164+
165+
[Test]
166+
public void EqualityOperators()
167+
{
168+
ElectricAdmittance a = ElectricAdmittance.FromSiemens(1);
169+
ElectricAdmittance b = ElectricAdmittance.FromSiemens(2);
170+
171+
// ReSharper disable EqualExpressionComparison
172+
Assert.True(a == a);
173+
Assert.True(a != b);
174+
175+
Assert.False(a == b);
176+
Assert.False(a != a);
177+
// ReSharper restore EqualExpressionComparison
178+
}
179+
180+
[Test]
181+
public void EqualsIsImplemented()
182+
{
183+
ElectricAdmittance v = ElectricAdmittance.FromSiemens(1);
184+
Assert.IsTrue(v.Equals(ElectricAdmittance.FromSiemens(1)));
185+
Assert.IsFalse(v.Equals(ElectricAdmittance.Zero));
186+
}
187+
188+
[Test]
189+
public void EqualsReturnsFalseOnTypeMismatch()
190+
{
191+
ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);
192+
Assert.IsFalse(siemens.Equals(new object()));
193+
}
194+
195+
[Test]
196+
public void EqualsReturnsFalseOnNull()
197+
{
198+
ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1);
199+
Assert.IsFalse(siemens.Equals(null));
200+
}
201+
}
202+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by \generate-code.bat.
4+
//
5+
// Changes to this file will be lost when the code is regenerated.
6+
// The build server regenerates the code before each build and a pre-build
7+
// step will regenerate the code on each local build.
8+
//
9+
// See https://github.com/anjdreas/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
10+
//
11+
// Add CustomCode\UnitClasses\MyUnit.extra.cs files to add code to generated unit classes.
12+
// Add Extensions\MyUnitExtensions.cs to decorate unit classes with new behavior.
13+
// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or unit classes.
14+
//
15+
// </auto-generated>
16+
//------------------------------------------------------------------------------
17+
18+
// Copyright (c) 2007 Andreas Gullberg Larsen ([email protected]).
19+
// https://github.com/anjdreas/UnitsNet
20+
//
21+
// Permission is hereby granted, free of charge, to any person obtaining a copy
22+
// of this software and associated documentation files (the "Software"), to deal
23+
// in the Software without restriction, including without limitation the rights
24+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25+
// copies of the Software, and to permit persons to whom the Software is
26+
// furnished to do so, subject to the following conditions:
27+
//
28+
// The above copyright notice and this permission notice shall be included in
29+
// all copies or substantial portions of the Software.
30+
//
31+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
37+
// THE SOFTWARE.
38+
39+
// ReSharper disable once CheckNamespace
40+
namespace UnitsNet.Units
41+
{
42+
public enum ElectricAdmittanceUnit
43+
{
44+
Undefined = 0,
45+
Microsiemens,
46+
Millisiemens,
47+
Nanosiemens,
48+
Siemens,
49+
}
50+
}

0 commit comments

Comments
 (0)