Skip to content

Commit ed00e94

Browse files
JKSndangularsen
authored andcommitted
Added DecibelsUnloaded (dBu) to AmplitudeRatio
1 parent 981e313 commit ed00e94

File tree

7 files changed

+97
-0
lines changed

7 files changed

+97
-0
lines changed

UnitsNet.Tests/CustomCode/AmplitudeRatioTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class AmplitudeRatioTests : AmplitudeRatioTestsBase
3131

3232
protected override double DecibelMillivoltsInOneDecibelVolt => 61;
3333

34+
protected override double DecibelsUnloadedInOneDecibelVolt => 3.218487499;
35+
3436
protected override double DecibelVoltsInOneDecibelVolt => 1;
3537

3638
protected override void AssertLogarithmicAddition()

UnitsNet.Tests/GeneratedCode/AmplitudeRatioTestsBase.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ public abstract partial class AmplitudeRatioTestsBase
3838
{
3939
protected abstract double DecibelMicrovoltsInOneDecibelVolt { get; }
4040
protected abstract double DecibelMillivoltsInOneDecibelVolt { get; }
41+
protected abstract double DecibelsUnloadedInOneDecibelVolt { get; }
4142
protected abstract double DecibelVoltsInOneDecibelVolt { get; }
4243

4344
// ReSharper disable VirtualMemberNeverOverriden.Global
4445
protected virtual double DecibelMicrovoltsTolerance { get { return 1e-5; } }
4546
protected virtual double DecibelMillivoltsTolerance { get { return 1e-5; } }
47+
protected virtual double DecibelsUnloadedTolerance { get { return 1e-5; } }
4648
protected virtual double DecibelVoltsTolerance { get { return 1e-5; } }
4749
// ReSharper restore VirtualMemberNeverOverriden.Global
4850

@@ -52,6 +54,7 @@ public void DecibelVoltToAmplitudeRatioUnits()
5254
AmplitudeRatio decibelvolt = AmplitudeRatio.FromDecibelVolts(1);
5355
Assert.AreEqual(DecibelMicrovoltsInOneDecibelVolt, decibelvolt.DecibelMicrovolts, DecibelMicrovoltsTolerance);
5456
Assert.AreEqual(DecibelMillivoltsInOneDecibelVolt, decibelvolt.DecibelMillivolts, DecibelMillivoltsTolerance);
57+
Assert.AreEqual(DecibelsUnloadedInOneDecibelVolt, decibelvolt.DecibelsUnloaded, DecibelsUnloadedTolerance);
5558
Assert.AreEqual(DecibelVoltsInOneDecibelVolt, decibelvolt.DecibelVolts, DecibelVoltsTolerance);
5659
}
5760

@@ -60,6 +63,7 @@ public void FromValueAndUnit()
6063
{
6164
Assert.AreEqual(1, AmplitudeRatio.From(1, AmplitudeRatioUnit.DecibelMicrovolt).DecibelMicrovolts, DecibelMicrovoltsTolerance);
6265
Assert.AreEqual(1, AmplitudeRatio.From(1, AmplitudeRatioUnit.DecibelMillivolt).DecibelMillivolts, DecibelMillivoltsTolerance);
66+
Assert.AreEqual(1, AmplitudeRatio.From(1, AmplitudeRatioUnit.DecibelUnloaded).DecibelsUnloaded, DecibelsUnloadedTolerance);
6367
Assert.AreEqual(1, AmplitudeRatio.From(1, AmplitudeRatioUnit.DecibelVolt).DecibelVolts, DecibelVoltsTolerance);
6468
}
6569

@@ -69,6 +73,7 @@ public void As()
6973
var decibelvolt = AmplitudeRatio.FromDecibelVolts(1);
7074
Assert.AreEqual(DecibelMicrovoltsInOneDecibelVolt, decibelvolt.As(AmplitudeRatioUnit.DecibelMicrovolt), DecibelMicrovoltsTolerance);
7175
Assert.AreEqual(DecibelMillivoltsInOneDecibelVolt, decibelvolt.As(AmplitudeRatioUnit.DecibelMillivolt), DecibelMillivoltsTolerance);
76+
Assert.AreEqual(DecibelsUnloadedInOneDecibelVolt, decibelvolt.As(AmplitudeRatioUnit.DecibelUnloaded), DecibelsUnloadedTolerance);
7277
Assert.AreEqual(DecibelVoltsInOneDecibelVolt, decibelvolt.As(AmplitudeRatioUnit.DecibelVolt), DecibelVoltsTolerance);
7378
}
7479

@@ -78,6 +83,7 @@ public void ConversionRoundTrip()
7883
AmplitudeRatio decibelvolt = AmplitudeRatio.FromDecibelVolts(1);
7984
Assert.AreEqual(1, AmplitudeRatio.FromDecibelMicrovolts(decibelvolt.DecibelMicrovolts).DecibelVolts, DecibelMicrovoltsTolerance);
8085
Assert.AreEqual(1, AmplitudeRatio.FromDecibelMillivolts(decibelvolt.DecibelMillivolts).DecibelVolts, DecibelMillivoltsTolerance);
86+
Assert.AreEqual(1, AmplitudeRatio.FromDecibelsUnloaded(decibelvolt.DecibelsUnloaded).DecibelVolts, DecibelsUnloadedTolerance);
8187
Assert.AreEqual(1, AmplitudeRatio.FromDecibelVolts(decibelvolt.DecibelVolts).DecibelVolts, DecibelVoltsTolerance);
8288
}
8389

UnitsNet/GeneratedCode/Enums/AmplitudeRatioUnit.g.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public enum AmplitudeRatioUnit
2727
Undefined = 0,
2828
DecibelMicrovolt,
2929
DecibelMillivolt,
30+
DecibelUnloaded,
3031
DecibelVolt,
3132
}
3233
}

UnitsNet/GeneratedCode/Extensions/Number/NumberToAmplitudeRatioExtensions.g.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,40 @@ public static class NumberToAmplitudeRatioExtensions
9595

9696
#endregion
9797

98+
#region DecibelUnloaded
99+
100+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double)"/>
101+
public static AmplitudeRatio DecibelsUnloaded(this int value) => AmplitudeRatio.FromDecibelsUnloaded(value);
102+
103+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double?)"/>
104+
public static AmplitudeRatio? DecibelsUnloaded(this int? value) => AmplitudeRatio.FromDecibelsUnloaded(value);
105+
106+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double)"/>
107+
public static AmplitudeRatio DecibelsUnloaded(this long value) => AmplitudeRatio.FromDecibelsUnloaded(value);
108+
109+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double?)"/>
110+
public static AmplitudeRatio? DecibelsUnloaded(this long? value) => AmplitudeRatio.FromDecibelsUnloaded(value);
111+
112+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double)"/>
113+
public static AmplitudeRatio DecibelsUnloaded(this double value) => AmplitudeRatio.FromDecibelsUnloaded(value);
114+
115+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double?)"/>
116+
public static AmplitudeRatio? DecibelsUnloaded(this double? value) => AmplitudeRatio.FromDecibelsUnloaded(value);
117+
118+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double)"/>
119+
public static AmplitudeRatio DecibelsUnloaded(this float value) => AmplitudeRatio.FromDecibelsUnloaded(value);
120+
121+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double?)"/>
122+
public static AmplitudeRatio? DecibelsUnloaded(this float? value) => AmplitudeRatio.FromDecibelsUnloaded(value);
123+
124+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double)"/>
125+
public static AmplitudeRatio DecibelsUnloaded(this decimal value) => AmplitudeRatio.FromDecibelsUnloaded(Convert.ToDouble(value));
126+
127+
/// <inheritdoc cref="AmplitudeRatio.FromDecibelsUnloaded(double?)"/>
128+
public static AmplitudeRatio? DecibelsUnloaded(this decimal? value) => AmplitudeRatio.FromDecibelsUnloaded(value == null ? (double?)null : Convert.ToDouble(value.Value));
129+
130+
#endregion
131+
98132
#region DecibelVolt
99133

100134
/// <inheritdoc cref="AmplitudeRatio.FromDecibelVolts(double)"/>

UnitsNet/GeneratedCode/UnitClasses/AmplitudeRatio.g.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ public double DecibelMillivolts
109109
get { return _decibelVolts + 60; }
110110
}
111111

112+
/// <summary>
113+
/// Get AmplitudeRatio in DecibelsUnloaded.
114+
/// </summary>
115+
public double DecibelsUnloaded
116+
{
117+
get { return _decibelVolts + 2.218487499; }
118+
}
119+
112120
/// <summary>
113121
/// Get AmplitudeRatio in DecibelVolts.
114122
/// </summary>
@@ -142,6 +150,14 @@ public static AmplitudeRatio FromDecibelMillivolts(double decibelmillivolts)
142150
return new AmplitudeRatio(decibelmillivolts - 60);
143151
}
144152

153+
/// <summary>
154+
/// Get AmplitudeRatio from DecibelsUnloaded.
155+
/// </summary>
156+
public static AmplitudeRatio FromDecibelsUnloaded(double decibelsunloaded)
157+
{
158+
return new AmplitudeRatio(decibelsunloaded - 2.218487499);
159+
}
160+
145161
/// <summary>
146162
/// Get AmplitudeRatio from DecibelVolts.
147163
/// </summary>
@@ -181,6 +197,21 @@ public static AmplitudeRatio FromDecibelVolts(double decibelvolts)
181197
}
182198
}
183199

200+
/// <summary>
201+
/// Get nullable AmplitudeRatio from nullable DecibelsUnloaded.
202+
/// </summary>
203+
public static AmplitudeRatio? FromDecibelsUnloaded(double? decibelsunloaded)
204+
{
205+
if (decibelsunloaded.HasValue)
206+
{
207+
return FromDecibelsUnloaded(decibelsunloaded.Value);
208+
}
209+
else
210+
{
211+
return null;
212+
}
213+
}
214+
184215
/// <summary>
185216
/// Get nullable AmplitudeRatio from nullable DecibelVolts.
186217
/// </summary>
@@ -212,6 +243,8 @@ public static AmplitudeRatio From(double val, AmplitudeRatioUnit fromUnit)
212243
return FromDecibelMicrovolts(val);
213244
case AmplitudeRatioUnit.DecibelMillivolt:
214245
return FromDecibelMillivolts(val);
246+
case AmplitudeRatioUnit.DecibelUnloaded:
247+
return FromDecibelsUnloaded(val);
215248
case AmplitudeRatioUnit.DecibelVolt:
216249
return FromDecibelVolts(val);
217250

@@ -239,6 +272,8 @@ public static AmplitudeRatio From(double val, AmplitudeRatioUnit fromUnit)
239272
return FromDecibelMicrovolts(value.Value);
240273
case AmplitudeRatioUnit.DecibelMillivolt:
241274
return FromDecibelMillivolts(value.Value);
275+
case AmplitudeRatioUnit.DecibelUnloaded:
276+
return FromDecibelsUnloaded(value.Value);
242277
case AmplitudeRatioUnit.DecibelVolt:
243278
return FromDecibelVolts(value.Value);
244279

@@ -407,6 +442,8 @@ public double As(AmplitudeRatioUnit unit)
407442
return DecibelMicrovolts;
408443
case AmplitudeRatioUnit.DecibelMillivolt:
409444
return DecibelMillivolts;
445+
case AmplitudeRatioUnit.DecibelUnloaded:
446+
return DecibelsUnloaded;
410447
case AmplitudeRatioUnit.DecibelVolt:
411448
return DecibelVolts;
412449

UnitsNet/GeneratedCode/UnitSystem.Default.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
8686
{
8787
new AbbreviationsForCulture("en-US", "dBmV"),
8888
}),
89+
new CulturesForEnumValue((int) AmplitudeRatioUnit.DecibelUnloaded,
90+
new[]
91+
{
92+
new AbbreviationsForCulture("en-US", "dBu"),
93+
}),
8994
new CulturesForEnumValue((int) AmplitudeRatioUnit.DecibelVolt,
9095
new[]
9196
{

UnitsNet/Scripts/UnitDefinitions/AmplitudeRatio.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
4040
"Abbreviations": [ "dBmV" ]
4141
}
4242
]
43+
},
44+
{
45+
"SingularName": "DecibelUnloaded",
46+
"PluralName": "DecibelsUnloaded",
47+
"FromUnitToBaseFunc": "x - 2.218487499",
48+
"FromBaseToUnitFunc": "x + 2.218487499",
49+
"Localization": [
50+
{
51+
"Culture": "en-US",
52+
"Abbreviations": [ "dBu" ]
53+
}
54+
]
4355
}
4456
]
4557
}

0 commit comments

Comments
 (0)