Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit d39c9874 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

show nice units for SI class

parent 4dbee879
No related branches found
No related tags found
No related merge requests found
...@@ -104,6 +104,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -104,6 +104,8 @@ namespace TUGraz.VectoCommon.Utils
[DebuggerHidden] [DebuggerHidden]
private Newton(double val) : base(val, Units) { } private Newton(double val) : base(val, Units) { }
public override string UnitString { get { return "N"; } }
[DebuggerHidden] [DebuggerHidden]
public static NewtonMeter operator *(Newton newton, Meter meter) public static NewtonMeter operator *(Newton newton, Meter meter)
{ {
...@@ -224,6 +226,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -224,6 +226,8 @@ namespace TUGraz.VectoCommon.Utils
[DebuggerHidden] [DebuggerHidden]
private KilogramPerMeter(double val) : base(val, Units) { } private KilogramPerMeter(double val) : base(val, Units) { }
public override string UnitString { get { return "kg/m"; } }
public static KilogramPerMeterMass operator /(KilogramPerMeter kpm, Kilogram kg) public static KilogramPerMeterMass operator /(KilogramPerMeter kpm, Kilogram kg)
{ {
return SIBase<KilogramPerMeterMass>.Create(kpm.Val / kg.Value()); return SIBase<KilogramPerMeterMass>.Create(kpm.Val / kg.Value());
...@@ -244,6 +248,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -244,6 +248,8 @@ namespace TUGraz.VectoCommon.Utils
private LiterPerSecond(double val) : base(val, 0.001, Units) { } private LiterPerSecond(double val) : base(val, 0.001, Units) { }
public override string UnitString { get { return "l/s"; } }
[DebuggerHidden] [DebuggerHidden]
public static Liter operator *(LiterPerSecond l, Second second) public static Liter operator *(LiterPerSecond l, Second second)
{ {
...@@ -329,6 +335,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -329,6 +335,8 @@ namespace TUGraz.VectoCommon.Utils
//[DebuggerHidden] //[DebuggerHidden]
private Liter(double val) : base(val , 0.001, Units) { } private Liter(double val) : base(val , 0.001, Units) { }
public override string UnitString { get { return "l"; } }
public static Kilogram operator *(Liter liter, KilogramPerCubicMeter kilogramPerCubicMeter) public static Kilogram operator *(Liter liter, KilogramPerCubicMeter kilogramPerCubicMeter)
{ {
return SIBase<Kilogram>.Create(liter.AsBasicUnit * kilogramPerCubicMeter.Value()); return SIBase<Kilogram>.Create(liter.AsBasicUnit * kilogramPerCubicMeter.Value());
...@@ -345,6 +353,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -345,6 +353,8 @@ namespace TUGraz.VectoCommon.Utils
//[DebuggerHidden] //[DebuggerHidden]
private NormLiter(double val) : base(val , 0.001, Units) { } private NormLiter(double val) : base(val , 0.001, Units) { }
public override string UnitString { get { return "Nl"; } }
public static NormLiterPerSecond operator /(NormLiter nl, Second s) public static NormLiterPerSecond operator /(NormLiter nl, Second s)
{ {
return SIBase<NormLiterPerSecond>.Create(nl.Val / s.Value()); return SIBase<NormLiterPerSecond>.Create(nl.Val / s.Value());
...@@ -361,6 +371,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -361,6 +371,8 @@ namespace TUGraz.VectoCommon.Utils
//[DebuggerHidden] //[DebuggerHidden]
private NormLiterPerSecond(double val) : base(val, 0.001, Units) { } private NormLiterPerSecond(double val) : base(val, 0.001, Units) { }
public override string UnitString { get { return "Nl/s"; } }
public static NormLiter operator *(NormLiterPerSecond nips, Second s) public static NormLiter operator *(NormLiterPerSecond nips, Second s)
{ {
return SIBase<NormLiter>.Create(nips.Val * s.Value()); return SIBase<NormLiter>.Create(nips.Val * s.Value());
...@@ -435,7 +447,7 @@ namespace TUGraz.VectoCommon.Utils ...@@ -435,7 +447,7 @@ namespace TUGraz.VectoCommon.Utils
} }
/// <summary> /// <summary>
/// SI Class for Kilogram Square Meter [kgm^2]. /// SI Class for Kilogram per Cubic Meter [kg/m^3].
/// </summary> /// </summary>
public class KilogramPerCubicMeter : SIBase<KilogramPerCubicMeter> public class KilogramPerCubicMeter : SIBase<KilogramPerCubicMeter>
{ {
...@@ -444,6 +456,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -444,6 +456,8 @@ namespace TUGraz.VectoCommon.Utils
[DebuggerHidden] [DebuggerHidden]
private KilogramPerCubicMeter(double value) : base(value, Units) { } private KilogramPerCubicMeter(double value) : base(value, Units) { }
public override string UnitString { get { return "kg/m^3"; } }
[DebuggerHidden] [DebuggerHidden]
public static Kilogram operator *(KilogramPerCubicMeter kilogramPerCubicMeter, CubicMeter cubicMeter) public static Kilogram operator *(KilogramPerCubicMeter kilogramPerCubicMeter, CubicMeter cubicMeter)
{ {
...@@ -462,6 +476,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -462,6 +476,8 @@ namespace TUGraz.VectoCommon.Utils
[DebuggerHidden] [DebuggerHidden]
private KilogramPerWattSecond(double val) : base(val, Units) { } private KilogramPerWattSecond(double val) : base(val, Units) { }
public override string UnitString { get { return "kg/Ws"; } }
} }
/// <summary> /// <summary>
...@@ -475,6 +491,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -475,6 +491,8 @@ namespace TUGraz.VectoCommon.Utils
[DebuggerHidden] [DebuggerHidden]
private WattSecond(double val) : base(val, Units) { } private WattSecond(double val) : base(val, Units) { }
public override string UnitString { get { return "Ws"; } }
[DebuggerHidden] [DebuggerHidden]
public static Watt operator /(WattSecond wattSecond, Second second) public static Watt operator /(WattSecond wattSecond, Second second)
{ {
...@@ -492,6 +510,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -492,6 +510,8 @@ namespace TUGraz.VectoCommon.Utils
[DebuggerHidden] [DebuggerHidden]
private Watt(double val) : base(val, Units) { } private Watt(double val) : base(val, Units) { }
public override string UnitString { get { return "W"; } }
/// <summary> /// <summary>
/// Implements the operator /. /// Implements the operator /.
/// </summary> /// </summary>
...@@ -550,6 +570,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -550,6 +570,8 @@ namespace TUGraz.VectoCommon.Utils
[DebuggerHidden] [DebuggerHidden]
private Joule(double val) : base(val, Units) { } private Joule(double val) : base(val, Units) { }
public override string UnitString { get { return "J"; } }
public static implicit operator Joule(WattSecond self) public static implicit operator Joule(WattSecond self)
{ {
return Create(self.Value()); return Create(self.Value());
...@@ -572,9 +594,7 @@ namespace TUGraz.VectoCommon.Utils ...@@ -572,9 +594,7 @@ namespace TUGraz.VectoCommon.Utils
} }
/// <summary> /// <summary>
/// SI Class for Watt [W]. /// SI Class for Joule / kg.
/// J = Ws
/// W = kgm^2/s^3
/// </summary> /// </summary>
public class JoulePerKilogramm : SIBase<JoulePerKilogramm> public class JoulePerKilogramm : SIBase<JoulePerKilogramm>
{ {
...@@ -582,6 +602,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -582,6 +602,8 @@ namespace TUGraz.VectoCommon.Utils
private JoulePerKilogramm(double val) : base(val, Units) { } private JoulePerKilogramm(double val) : base(val, Units) { }
public override string UnitString { get { return "J/kg"; } }
public static Joule operator *(Kilogram kg, JoulePerKilogramm jpg) public static Joule operator *(Kilogram kg, JoulePerKilogramm jpg)
{ {
return SIBase<Joule>.Create(kg.Value() * jpg.Val); return SIBase<Joule>.Create(kg.Value() * jpg.Val);
...@@ -599,6 +621,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -599,6 +621,8 @@ namespace TUGraz.VectoCommon.Utils
[DebuggerHidden] [DebuggerHidden]
private JoulePerMeter(double val) : base(val, Units) { } private JoulePerMeter(double val) : base(val, Units) { }
public override string UnitString { get { return "J/m"; } }
} }
/// <summary> /// <summary>
...@@ -706,6 +730,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -706,6 +730,8 @@ namespace TUGraz.VectoCommon.Utils
[DebuggerHidden] [DebuggerHidden]
private NewtonMeter(double val) : base(val, Units) { } private NewtonMeter(double val) : base(val, Units) { }
public override string UnitString { get { return "Nm"; } }
[DebuggerHidden] [DebuggerHidden]
public static Watt operator *(NewtonMeter newtonMeter, PerSecond perSecond) public static Watt operator *(NewtonMeter newtonMeter, PerSecond perSecond)
{ {
...@@ -757,6 +783,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -757,6 +783,8 @@ namespace TUGraz.VectoCommon.Utils
{ {
private static readonly int[] Units = { 1, 2, -1, 0, 0, 0, 0 }; private static readonly int[] Units = { 1, 2, -1, 0, 0, 0, 0 };
private NewtonMeterSecond(double val) : base(val, Units) { } private NewtonMeterSecond(double val) : base(val, Units) { }
public override string UnitString { get { return "Nms"; } }
} }
/// <summary> /// <summary>
...@@ -792,6 +820,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -792,6 +820,8 @@ namespace TUGraz.VectoCommon.Utils
private static readonly int[] Units = { 1, 2, -2, -1, 0, 0, 0 }; private static readonly int[] Units = { 1, 2, -2, -1, 0, 0, 0 };
private Volt(double val) : base(val, Units) { } private Volt(double val) : base(val, Units) { }
public override string UnitString { get { return "V"; } }
public static Watt operator *(Volt volt, Ampere ampere) public static Watt operator *(Volt volt, Ampere ampere)
{ {
return SIBase<Watt>.Create(volt.Val * ampere.Value()); return SIBase<Watt>.Create(volt.Val * ampere.Value());
...@@ -808,6 +838,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -808,6 +838,8 @@ namespace TUGraz.VectoCommon.Utils
private static readonly int[] Units = { 0, 2, 0, 0, 0, 0, 0 }; private static readonly int[] Units = { 0, 2, 0, 0, 0, 0, 0 };
private VolumePerMeter(double val) : base(val, Units) { } private VolumePerMeter(double val) : base(val, Units) { }
public override string UnitString { get { return "m^3/m"; } }
public static VolumePerMeterMass operator /(VolumePerMeter vpm, Kilogram kg) public static VolumePerMeterMass operator /(VolumePerMeter vpm, Kilogram kg)
{ {
return SIBase<VolumePerMeterMass>.Create(vpm.Val / kg.Value()); return SIBase<VolumePerMeterMass>.Create(vpm.Val / kg.Value());
...@@ -825,6 +857,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -825,6 +857,8 @@ namespace TUGraz.VectoCommon.Utils
private static readonly int[] Units = { -1, 2, 0, 0, 0, 0, 0 }; private static readonly int[] Units = { -1, 2, 0, 0, 0, 0, 0 };
private VolumePerMeterMass(double val) : base (val, Units) { } private VolumePerMeterMass(double val) : base (val, Units) { }
public override string UnitString { get { return "m^3/kgm"; } }
} }
public class VolumePerMeterVolume : SIBase<VolumePerMeterVolume> public class VolumePerMeterVolume : SIBase<VolumePerMeterVolume>
...@@ -832,6 +866,8 @@ namespace TUGraz.VectoCommon.Utils ...@@ -832,6 +866,8 @@ namespace TUGraz.VectoCommon.Utils
private static readonly int[] Units = { 0, -1, 0, 0, 0, 0, 0 }; private static readonly int[] Units = { 0, -1, 0, 0, 0, 0, 0 };
private VolumePerMeterVolume(double val) : base (val, Units) { } private VolumePerMeterVolume(double val) : base (val, Units) { }
public override string UnitString { get { return "m^3/kgm^3"; } }
} }
public class KilogramPerMeterCubicMeter : SIBase<KilogramPerMeterCubicMeter> public class KilogramPerMeterCubicMeter : SIBase<KilogramPerMeterCubicMeter>
...@@ -839,13 +875,18 @@ namespace TUGraz.VectoCommon.Utils ...@@ -839,13 +875,18 @@ namespace TUGraz.VectoCommon.Utils
private static readonly int[] Units = { 1, -4, 0, 0, 0, 0, 0 }; private static readonly int[] Units = { 1, -4, 0, 0, 0, 0, 0 };
private KilogramPerMeterCubicMeter(double val) : base(val, Units) { } private KilogramPerMeterCubicMeter(double val) : base(val, Units) { }
public override string UnitString { get { return "kg/(m m^3)"; } }
} }
public class KilogramPerMeterMass : SIBase<KilogramPerMeterMass> public class KilogramPerMeterMass : SIBase<KilogramPerMeterMass>
{ {
private static readonly int[] Units = { 0, -1, 0, 0, 0, 0, 0 }; private static readonly int[] Units = { 0, -1, 0, 0, 0, 0, 0 };
private KilogramPerMeterMass(double val) : base(val, Units) { } private KilogramPerMeterMass(double val) : base(val, Units) { }
public override string UnitString { get { return "kg/(m kg)"; } }
} }
public class SpecificFuelConsumption : SIBase<SpecificFuelConsumption> public class SpecificFuelConsumption : SIBase<SpecificFuelConsumption>
...@@ -1060,7 +1101,7 @@ namespace TUGraz.VectoCommon.Utils ...@@ -1060,7 +1101,7 @@ namespace TUGraz.VectoCommon.Utils
/// <remarks> /// <remarks>
/// Usage: new SI(1.0).Newton.Meter, new SI(2.3).Rounds.Per.Minute /// Usage: new SI(1.0).Newton.Meter, new SI(2.3).Rounds.Per.Minute
/// </remarks> /// </remarks>
[DebuggerDisplay("{Val}")] [DebuggerDisplay("{Val} [{UnitString}]")]
public class SI : IComparable public class SI : IComparable
{ {
/// <summary> /// <summary>
...@@ -1232,7 +1273,7 @@ namespace TUGraz.VectoCommon.Utils ...@@ -1232,7 +1273,7 @@ namespace TUGraz.VectoCommon.Utils
} }
} catch (DivideByZeroException ex) { } catch (DivideByZeroException ex) {
throw new VectoException( throw new VectoException(
string.Format("Can not compute division by zero ([{0}] / 0[{1}])", si1.GetUnitString(), si2.GetUnitString()), ex); string.Format("Can not compute division by zero ([{0}] / 0[{1}])", si1.UnitString, si2.UnitString), ex);
} }
var unitArray = SIUtils.CombineUnits(si1._units, SIUtils.MultiplyUnits(si2._units, -1)); var unitArray = SIUtils.CombineUnits(si1._units, SIUtils.MultiplyUnits(si2._units, -1));
...@@ -1244,7 +1285,7 @@ namespace TUGraz.VectoCommon.Utils ...@@ -1244,7 +1285,7 @@ namespace TUGraz.VectoCommon.Utils
public static SI operator /(SI si1, double d) public static SI operator /(SI si1, double d)
{ {
if (d.IsEqual(0)) { if (d.IsEqual(0)) {
throw new VectoException(string.Format("Can not compute division by zero ([{0}] / 0)", si1.GetUnitString()), new DivideByZeroException()); throw new VectoException(string.Format("Can not compute division by zero ([{0}] / 0)", si1.UnitString), new DivideByZeroException());
} }
return new SI(si1.Val / d, si1); return new SI(si1.Val / d, si1);
...@@ -1254,7 +1295,7 @@ namespace TUGraz.VectoCommon.Utils ...@@ -1254,7 +1295,7 @@ namespace TUGraz.VectoCommon.Utils
public static SI operator /(double d, SI si1) public static SI operator /(double d, SI si1)
{ {
if (si1.IsEqual(0)) { if (si1.IsEqual(0)) {
throw new VectoException(string.Format("Can not compute division by zero (x / 0[{0}])", si1.GetUnitString()), throw new VectoException(string.Format("Can not compute division by zero (x / 0[{0}])", si1.UnitString),
new DivideByZeroException()); new DivideByZeroException());
} }
...@@ -1376,10 +1417,10 @@ namespace TUGraz.VectoCommon.Utils ...@@ -1376,10 +1417,10 @@ namespace TUGraz.VectoCommon.Utils
/// <summary> /// <summary>
/// Returns the Unit Part of the SI Unit Expression. /// Returns the Unit Part of the SI Unit Expression.
/// </summary> /// </summary>
public string GetUnitString(int[] units = null) public static string GetUnitString(int[] units = null)
{ {
if (units == null) { if (units == null) {
units = _units; return "";
} }
return Unit.GetUnitString(units); return Unit.GetUnitString(units);
} }
...@@ -1389,13 +1430,18 @@ namespace TUGraz.VectoCommon.Utils ...@@ -1389,13 +1430,18 @@ namespace TUGraz.VectoCommon.Utils
return ToString(null); return ToString(null);
} }
public virtual string UnitString
{
get { return GetUnitString(_units); }
}
private string ToString(string format) private string ToString(string format)
{ {
if (string.IsNullOrEmpty(format)) { if (string.IsNullOrEmpty(format)) {
format = "F4"; format = "F4";
} }
return string.Format(CultureInfo.InvariantCulture, "{0:" + format + "} [{2}]", Val, format, GetUnitString()); return string.Format(CultureInfo.InvariantCulture, "{0:" + format + "} [{2}]", Val, format, UnitString);
} }
#endregion #endregion
...@@ -1675,7 +1721,7 @@ namespace TUGraz.VectoCommon.Utils ...@@ -1675,7 +1721,7 @@ namespace TUGraz.VectoCommon.Utils
if (showUnit.Value) { if (showUnit.Value) {
return (Val * outputFactor.Value).ToString("F" + decimals.Value, CultureInfo.InvariantCulture) + " [" + return (Val * outputFactor.Value).ToString("F" + decimals.Value, CultureInfo.InvariantCulture) + " [" +
GetUnitString() + "]"; UnitString + "]";
} }
return (Val * outputFactor.Value).ToString("F" + decimals.Value, CultureInfo.InvariantCulture); return (Val * outputFactor.Value).ToString("F" + decimals.Value, CultureInfo.InvariantCulture);
......
...@@ -77,7 +77,7 @@ namespace TUGraz.VectoCommon.Utils ...@@ -77,7 +77,7 @@ namespace TUGraz.VectoCommon.Utils
public static implicit operator ConvertedSI(SI self) public static implicit operator ConvertedSI(SI self)
{ {
return self == null ? null : new ConvertedSI(self.Value(), self.GetUnitString()); return self == null ? null : new ConvertedSI(self.Value(), self.UnitString);
} }
public override string ToString() public override string ToString()
......
...@@ -102,7 +102,9 @@ namespace TUGraz.VectoCommon.Utils ...@@ -102,7 +102,9 @@ namespace TUGraz.VectoCommon.Utils
} }
} }
string result; string result;
if (numerator == "" && denominator == "") {
return "-";
}
if (numerator == "") { if (numerator == "") {
if (denominator == "") { if (denominator == "") {
result = "-"; result = "-";
......
...@@ -395,7 +395,7 @@ namespace TUGraz.VectoCommon.Utils ...@@ -395,7 +395,7 @@ namespace TUGraz.VectoCommon.Utils
var si = value as SI; var si = value as SI;
if (si != null) { if (si != null) {
_unit = si.GetUnitString(); _unit = si.UnitString;
} }
var validationService = var validationService =
validationContext.GetService(typeof(VectoValidationModeServiceContainer)) as VectoValidationModeServiceContainer; validationContext.GetService(typeof(VectoValidationModeServiceContainer)) as VectoValidationModeServiceContainer;
......
...@@ -144,7 +144,7 @@ namespace TUGraz.VectoCore.Tests.Utils ...@@ -144,7 +144,7 @@ namespace TUGraz.VectoCore.Tests.Utils
Assert.AreEqual(expectedVal, actualVal); Assert.AreEqual(expectedVal, actualVal);
} else if (propertyType == typeof(SI)) { } else if (propertyType == typeof(SI)) {
Assert.AreEqual((expectedVal as SI).Value(), (actualVal as SI).Value()); Assert.AreEqual((expectedVal as SI).Value(), (actualVal as SI).Value());
Assert.AreEqual((expectedVal as SI).GetUnitString(), (actualVal as SI).GetUnitString()); Assert.AreEqual((expectedVal as SI).UnitString, (actualVal as SI).UnitString);
} else if (expectedVal is IEnumerable<object>) { } else if (expectedVal is IEnumerable<object>) {
Assert.IsTrue(actualVal is IList); Assert.IsTrue(actualVal is IList);
var expectedEnumerable = (expectedVal as IEnumerable<object>).ToArray(); var expectedEnumerable = (expectedVal as IEnumerable<object>).ToArray();
......
...@@ -154,16 +154,18 @@ namespace TUGraz.VectoCore.Tests.Utils ...@@ -154,16 +154,18 @@ namespace TUGraz.VectoCore.Tests.Utils
var v4 = 100.SI<Watt>(); var v4 = 100.SI<Watt>();
var d = 700; var d = 700;
v1.ToString();
Assert.IsTrue(v1 > v2); Assert.IsTrue(v1 > v2);
Assert.IsFalse(v1 < v2); Assert.IsFalse(v1 < v2);
AssertHelper.Exception<VectoException>(() => { var x = v1 < v4; }, AssertHelper.Exception<VectoException>(() => { var x = v1 < v4; },
"Operator '<' can only operate on SI Objects with the same unit. Got: 600.0000 [kgm^2/s^2] < 100.0000 [kgm^2/s^3]"); "Operator '<' can only operate on SI Objects with the same unit. Got: 600.0000 [Nm] < 100.0000 [W]");
AssertHelper.Exception<VectoException>(() => { var x = v1 > v4; }, AssertHelper.Exception<VectoException>(() => { var x = v1 > v4; },
"Operator '>' can only operate on SI Objects with the same unit. Got: 600.0000 [kgm^2/s^2] > 100.0000 [kgm^2/s^3]"); "Operator '>' can only operate on SI Objects with the same unit. Got: 600.0000 [Nm] > 100.0000 [W]");
AssertHelper.Exception<VectoException>(() => { var x = v1 <= v4; }, AssertHelper.Exception<VectoException>(() => { var x = v1 <= v4; },
"Operator '<=' can only operate on SI Objects with the same unit. Got: 600.0000 [kgm^2/s^2] <= 100.0000 [kgm^2/s^3]"); "Operator '<=' can only operate on SI Objects with the same unit. Got: 600.0000 [Nm] <= 100.0000 [W]");
AssertHelper.Exception<VectoException>(() => { var x = v1 >= v4; }, AssertHelper.Exception<VectoException>(() => { var x = v1 >= v4; },
"Operator '>=' can only operate on SI Objects with the same unit. Got: 600.0000 [kgm^2/s^2] >= 100.0000 [kgm^2/s^3]"); "Operator '>=' can only operate on SI Objects with the same unit. Got: 600.0000 [Nm] >= 100.0000 [W]");
SI si = null; SI si = null;
Assert.IsFalse(si > 3); Assert.IsFalse(si > 3);
...@@ -420,7 +422,7 @@ namespace TUGraz.VectoCore.Tests.Utils ...@@ -420,7 +422,7 @@ namespace TUGraz.VectoCore.Tests.Utils
Assert.AreEqual("3.0000 [-]", 3.SI().ToOutputFormat(showUnit: true)); Assert.AreEqual("3.0000 [-]", 3.SI().ToOutputFormat(showUnit: true));
Assert.AreEqual("3.5000", 3.5.SI().ToOutputFormat()); Assert.AreEqual("3.5000", 3.5.SI().ToOutputFormat());
Assert.AreEqual("3.5000", 3.5.SI<Newton>().ToOutputFormat()); Assert.AreEqual("3.5000", 3.5.SI<Newton>().ToOutputFormat());
Assert.AreEqual("3.50 [kgm/s^2]", 3.5.SI<Newton>().ToOutputFormat(2, showUnit: true)); Assert.AreEqual("3.50 [N]", 3.5.SI<Newton>().ToOutputFormat(2, showUnit: true));
Assert.AreEqual("18.00 [m/s]", 5.SI<MeterPerSecond>().ToOutputFormat(2, 3.6, true)); Assert.AreEqual("18.00 [m/s]", 5.SI<MeterPerSecond>().ToOutputFormat(2, 3.6, true));
Assert.AreEqual("18.0000", 5.SI<MeterPerSecond>().ToOutputFormat(outputFactor: 3.6)); Assert.AreEqual("18.0000", 5.SI<MeterPerSecond>().ToOutputFormat(outputFactor: 3.6));
...@@ -529,16 +531,16 @@ namespace TUGraz.VectoCore.Tests.Utils ...@@ -529,16 +531,16 @@ namespace TUGraz.VectoCore.Tests.Utils
public void SI_NewTests() public void SI_NewTests()
{ {
UnitInstance sikg = Unit.SI.Kilo.Gramm; UnitInstance sikg = Unit.SI.Kilo.Gramm;
Assert.AreEqual("kg", 1.SI().GetUnitString(sikg.GetSIUnits())); Assert.AreEqual("kg", SI.GetUnitString(sikg.GetSIUnits()));
UnitInstance ui1 = Unit.SI.Kilo.Gramm.Meter.Per.Square.Second; UnitInstance ui1 = Unit.SI.Kilo.Gramm.Meter.Per.Square.Second;
Assert.AreEqual("kgm/s^2", 1.SI().GetUnitString(ui1.GetSIUnits())); Assert.AreEqual("kgm/s^2", SI.GetUnitString(ui1.GetSIUnits()));
UnitInstance ui3 = Unit.SI.Kilo.Gramm.Per.Watt.Second; UnitInstance ui3 = Unit.SI.Kilo.Gramm.Per.Watt.Second;
Assert.AreEqual("s^2/m^2", 1.SI().GetUnitString(ui3.GetSIUnits())); Assert.AreEqual("s^2/m^2", SI.GetUnitString(ui3.GetSIUnits()));
Assert.AreEqual(1, ui3.Factor); Assert.AreEqual(1, ui3.Factor);
var kg = 3000.SI(Unit.SI.Kilo.Gramm); var kg = 3000.SI(Unit.SI.Kilo.Gramm).Cast<Kilogram>();
Assert.AreEqual("3000.0000 [kg]", kg.ToOutputFormat(showUnit: true)); Assert.AreEqual("3000.0000 [kg]", kg.ToOutputFormat(showUnit: true));
var ton = 3.SI(Unit.SI.Ton); var ton = 3.SI(Unit.SI.Ton);
...@@ -548,15 +550,15 @@ namespace TUGraz.VectoCore.Tests.Utils ...@@ -548,15 +550,15 @@ namespace TUGraz.VectoCore.Tests.Utils
Assert.AreEqual("0.0070 [m^3]", val1.ToOutputFormat(showUnit: true)); Assert.AreEqual("0.0070 [m^3]", val1.ToOutputFormat(showUnit: true));
var uni = Unit.SI.Cubic.Dezi.Meter; var uni = Unit.SI.Cubic.Dezi.Meter;
Assert.AreEqual("m^3", 1.SI().GetUnitString(uni.GetSIUnits())); Assert.AreEqual("m^3", SI.GetUnitString(uni.GetSIUnits()));
AssertHelper.AreRelativeEqual(0.001, uni.Factor); AssertHelper.AreRelativeEqual(0.001, uni.Factor);
var uni2 = Unit.SI.Cubic.Centi.Meter; var uni2 = Unit.SI.Cubic.Centi.Meter;
Assert.AreEqual("m^3", 1.SI().GetUnitString(uni2.GetSIUnits())); Assert.AreEqual("m^3", SI.GetUnitString(uni2.GetSIUnits()));
AssertHelper.AreRelativeEqual(0.000001, uni2.Factor); AssertHelper.AreRelativeEqual(0.000001, uni2.Factor);
var uni1 = Unit.SI.Kilo.Meter.Per.Hour; var uni1 = Unit.SI.Kilo.Meter.Per.Hour;
Assert.AreEqual("m/s", 1.SI().GetUnitString(uni1.GetSIUnits())); Assert.AreEqual("m/s", SI.GetUnitString(uni1.GetSIUnits()));
AssertHelper.AreRelativeEqual(0.2777777777, uni1.Factor); AssertHelper.AreRelativeEqual(0.2777777777, uni1.Factor);
NewtonMeter newtonMeter = 5.SI<NewtonMeter>(); NewtonMeter newtonMeter = 5.SI<NewtonMeter>();
...@@ -568,7 +570,7 @@ namespace TUGraz.VectoCore.Tests.Utils ...@@ -568,7 +570,7 @@ namespace TUGraz.VectoCore.Tests.Utils
AssertHelper.AreRelativeEqual((6.0/3600).SI<Liter>(), (2.SI<Second>() * 3.SI(Unit.SI.Liter.Per.Hour)).Cast<Liter>()); AssertHelper.AreRelativeEqual((6.0/3600).SI<Liter>(), (2.SI<Second>() * 3.SI(Unit.SI.Liter.Per.Hour)).Cast<Liter>());
AssertHelper.AreRelativeEqual(2.13093, 2.13093.SI(Unit.SI.Liter).Cast<Liter>().Value()); AssertHelper.AreRelativeEqual(2.13093, 2.13093.SI(Unit.SI.Liter).Cast<Liter>().Value());
Assert.AreEqual("m^3", 2.13093.SI(Unit.SI.Liter).GetUnitString()); Assert.AreEqual("m^3", 2.13093.SI(Unit.SI.Liter).UnitString);
} }
//[TestCase] //[TestCase]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment