diff --git a/VECTO.sln.DotSettings b/VECTO.sln.DotSettings index cfdf53f1568d2ce5289e2f9ef603a262242283c6..4fa2232d39eabec2758679c4ef88228bce5a62f8 100644 --- a/VECTO.sln.DotSettings +++ b/VECTO.sln.DotSettings @@ -16,6 +16,8 @@ <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SIMPLE_EMBEDDED_STATEMENT_STYLE/@EntryValue">LINE_BREAK</s:String> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean> + <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RP/@EntryIndexedValue">RP</s:String> + <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SI/@EntryIndexedValue">SI</s:String> <s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=2BF7A1E51991F2458D2D1F0B29CF888B/@KeyIndexDefined">True</s:Boolean> <s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=2BF7A1E51991F2458D2D1F0B29CF888B/AbsolutePath/@EntryValue">C:\Workspaces\VisualStudio\VECTO_quam\VECTO.sln.DotSettings</s:String> <s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File2BF7A1E51991F2458D2D1F0B29CF888B/@KeyIndexDefined">True</s:Boolean> diff --git a/VectoCore/Models/Simulation/Impl/JobContainer.cs b/VectoCore/Models/Simulation/Impl/JobContainer.cs index 728b8cb6ff17dc6b5346a925e56ed042074ffa52..fa0305dc85e5b4af78470b2c01c1526d37b449c3 100644 --- a/VectoCore/Models/Simulation/Impl/JobContainer.cs +++ b/VectoCore/Models/Simulation/Impl/JobContainer.cs @@ -21,7 +21,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public JobContainer(VectoJobData data) { - _simulators.AddRange(SimulatorFactory.BuildJobs(data)); + _simulators.AddRange(SimulatorFactory.CreateJobs(data)); } diff --git a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs index 55a360ac7faadee2165ad5c7b820311a05b3e5eb..5bb03b55adab34085e92e5cd3f081049640d9e3d 100644 --- a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs +++ b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs @@ -10,7 +10,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public class SimulatorFactory { /// <summary> - /// Creates a time based engine only powertrain and simulation job for the given files. + /// Creates a simulation job for time based engine only powertrain. /// </summary> public static IVectoSimulator CreateTimeBasedEngineOnlyJob(string engineFile, string cycleFile, string resultFile) @@ -24,7 +24,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl return simulator; } - public static IEnumerable<IVectoSimulator> BuildJobs(VectoJobData data) + public static IEnumerable<IVectoSimulator> CreateJobs(VectoJobData data) { foreach (var cycle in data.Cycles) { var builder = new SimulatorBuilder(data.IsEngineOnly); diff --git a/VectoCore/Utils/DoubleExtensionMethods.cs b/VectoCore/Utils/DoubleExtensionMethods.cs index 75533dc59311a66c42ee2aa6a100813dbdcc0e73..c616f65a303c1542e5b112226bd499d52b59bde3 100644 --- a/VectoCore/Utils/DoubleExtensionMethods.cs +++ b/VectoCore/Utils/DoubleExtensionMethods.cs @@ -2,66 +2,116 @@ using System; namespace TUGraz.VectoCore.Utils { + /// <summary> + /// Extension methods for double. + /// </summary> public static class DoubleExtensionMethods { + /// <summary> + /// The tolerance. + /// </summary> public const double Tolerance = 0.001; - - public static bool IsEqual(this double d, double other, double tolerance = Tolerance) + /// <summary> + /// Determines whether the specified other is equal within tolerance. + /// </summary> + /// <param name="self">The self.</param> + /// <param name="other">The other.</param> + /// <param name="tolerance">The tolerance.</param> + /// <returns></returns> + public static bool IsEqual(this double self, double other, double tolerance = Tolerance) { - return Math.Abs(d - other) > -tolerance; + return Math.Abs(self - other) < tolerance; } - public static bool IsSmaller(this double d, double other, double tolerance = Tolerance) + /// <summary> + /// Determines whether the specified other is smaller within tolerance. + /// </summary> + /// <param name="self">The self.</param> + /// <param name="other">The other.</param> + /// <param name="tolerance">The tolerance.</param> + /// <returns></returns> + public static bool IsSmaller(this double self, double other, double tolerance = Tolerance) { - return d - other < tolerance; + return self - other < tolerance; } - public static bool IsSmallerOrEqual(this double d, double other, double tolerance = Tolerance) + /// <summary> + /// Determines whether the specified other is smaller or equal within tolerance. + /// </summary> + /// <param name="self">The self.</param> + /// <param name="other">The other.</param> + /// <param name="tolerance">The tolerance.</param> + /// <returns></returns> + public static bool IsSmallerOrEqual(this double self, double other, double tolerance = Tolerance) { - return d - other <= tolerance; + return self - other <= tolerance; } - public static bool IsGreater(this double d, double other, double tolerance = Tolerance) + /// <summary> + /// Determines whether the specified other is greater within tolerance. + /// </summary> + /// <param name="self">The self.</param> + /// <param name="other">The other.</param> + /// <param name="tolerance">The tolerance.</param> + /// <returns></returns> + public static bool IsGreater(this double self, double other, double tolerance = Tolerance) { - return other.IsSmallerOrEqual(d, tolerance); + return other.IsSmallerOrEqual(self, tolerance); } - public static bool IsGreaterOrEqual(this double d, double other, double tolerance = Tolerance) + /// <summary> + /// Determines whether the specified other is greater or equal within tolerance. + /// </summary> + /// <param name="self">The self.</param> + /// <param name="other">The other.</param> + /// <param name="tolerance">The tolerance.</param> + /// <returns></returns> + public static bool IsGreaterOrEqual(this double self, double other, double tolerance = Tolerance) { - return other.IsSmaller(d, tolerance); + return other.IsSmaller(self, tolerance); } - public static bool IsPositive(this double d, double tolerance = Tolerance) + /// <summary> + /// Determines whether the specified tolerance is positive within tolerance. + /// </summary> + /// <param name="self">The self.</param> + /// <param name="tolerance">The tolerance.</param> + /// <returns></returns> + public static bool IsPositive(this double self, double tolerance = Tolerance) { - return d.IsGreaterOrEqual(0.0, tolerance); + return self.IsGreaterOrEqual(0.0, tolerance); } /// <summary> - /// Converts the double-value from rounds per minute to the SI Unit PerSecond + /// Converts the double-value from RPM (rounds per minute) to the SI Unit PerSecond. /// </summary> - /// <param name="d"></param> + /// <param name="self"></param> /// <returns></returns> - public static PerSecond RPMtoRad(this double d) + public static PerSecond RPMtoRad(this double self) { - return d.SI().Rounds.Per.Minute.ConvertTo().Radian.Per.Second.Cast<PerSecond>(); + return self.SI().Rounds.Per.Minute.ConvertTo().Radian.Per.Second.Cast<PerSecond>(); } /// <summary> - /// Gets the SI representation of the number (unit-less). + /// Creates an SI object for the number (unit-less: [-]). /// </summary> - public static SI SI(this double d) + /// <param name="self">The self.</param> + /// <returns></returns> + public static SI SI(this double self) { - return (SI)d; + return (SI)self; } - /// <summary> - /// Gets the special SI class of the number. + /// Creates an templated SI object for the number. /// </summary> - public static T SI<T>(this double d) where T : SIBase<T> + /// <typeparam name="T"></typeparam> + /// <param name="self">The self.</param> + /// <returns></returns> + public static T SI<T>(this double self) where T : SIBase<T> { - return SIBase<T>.Create(d); + return SIBase<T>.Create(self); } } } \ No newline at end of file diff --git a/VectoCoreTest/Utils/DoubleExtensionMethodTest.cs b/VectoCoreTest/Utils/DoubleExtensionMethodTest.cs index afcc4bf834ff5ab10add5a573d72b7a0c7d84d01..fc28ed5b1acf0e6d34f0ebf6f32b420218ca22b0 100644 --- a/VectoCoreTest/Utils/DoubleExtensionMethodTest.cs +++ b/VectoCoreTest/Utils/DoubleExtensionMethodTest.cs @@ -1,5 +1,4 @@ using System; -using System.Configuration; using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Utils; @@ -9,7 +8,7 @@ namespace TUGraz.VectoCore.Tests.Utils public class DoubleExtensionMethodTest { [TestMethod] - public void DoubleExtensions_SI_Test() + public void DoubleExtensions_SI() { var val = 600.0.RPMtoRad(); Assert.AreEqual(600 / 60 * 2 * Math.PI, val.Double()); @@ -28,7 +27,7 @@ namespace TUGraz.VectoCore.Tests.Utils } [TestMethod] - public void DoubleExtension_CompareTests() + public void DoubleExtension_ComparisonOperators() { Assert.IsTrue(0.0.IsEqual(0.0)); Assert.IsTrue(1.0.IsGreater(0.0)); @@ -37,8 +36,16 @@ namespace TUGraz.VectoCore.Tests.Utils Assert.IsTrue(0.0.IsSmaller(1.0)); Assert.IsTrue(1.0.IsSmallerOrEqual(1.0)); + const double inTolerance = 0.00099; + Assert.IsTrue(0.0.IsEqual(inTolerance)); + Assert.IsTrue(inTolerance.IsEqual(0.0)); + Assert.IsTrue(0.0.IsEqual(-inTolerance)); + Assert.IsTrue((-inTolerance).IsEqual(0.0)); - Assert.IsTrue(0.0.IsEqual(0.001)); + Assert.IsFalse(0.0.IsEqual(0.1)); + Assert.IsFalse(0.1.IsEqual(0.0)); + Assert.IsFalse(0.0.IsEqual(-0.1)); + Assert.IsFalse((-0.1).IsEqual(0.0)); Assert.IsTrue(1.002.IsGreater(1.0)); Assert.IsTrue(1.001.IsGreater(1.0));