From 0e9179c4d825f89efe80a3ee140647db0e9d61e3 Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Wed, 8 Jul 2015 12:32:15 +0200 Subject: [PATCH] code refactorings: optimize imports, qualify by type name, added AssertHelper --- VECTO.sln.DotSettings | 1 + VectoCore/Models/Declaration/Axle.cs | 2 +- .../Models/Declaration/DeclarationData.cs | 10 ++- VectoCore/Models/Declaration/HVAC.cs | 2 +- VectoCore/Models/Declaration/MissionType.cs | 6 +- VectoCore/Models/Declaration/Segment.cs | 3 +- VectoCore/Models/Declaration/Segments.cs | 2 +- VectoCore/Models/Declaration/Wheels.cs | 5 +- .../Simulation/Data/IModalDataWriter.cs | 4 +- .../Models/Simulation/Data/ModalDataWriter.cs | 4 +- .../Simulation/Data/SummaryFileWriter.cs | 4 +- .../Models/Simulation/Data/VectoJobData.cs | 1 - .../Simulation/Impl/SimulatorFactory.cs | 2 +- VectoCore/Models/Simulation/Impl/VectoRun.cs | 2 - .../Data/AuxiliaryCycleDataAdapter.cs | 4 +- .../Data/Engine/FullLoadCurve.cs | 1 - .../Data/Gearbox/GearData.cs | 2 +- .../Data/Gearbox/ShiftPolygon.cs | 4 +- .../Data/Gearbox/TransmissionLossMap.cs | 8 +- .../SimulationComponent/Data/GearboxData.cs | 6 +- .../Data/JsonDataHeader.cs | 3 +- .../SimulationComponent/Data/RetarderData.cs | 1 - .../Data/RetarderLossMap.cs | 1 - .../Data/SimulationComponentData.cs | 4 +- .../Factories/EngineeringModeFactory.cs | 1 + .../Models/SimulationComponent/IClutch.cs | 4 +- .../Models/SimulationComponent/IVehicle.cs | 6 +- .../Impl/CombustionEngine.cs | 29 +++--- .../Impl/DirectAuxiliary.cs | 7 +- .../Impl/EngineOnlyGearbox.cs | 89 +++++++++---------- .../Impl/MappingAuxiliary.cs | 2 +- VectoCore/Utils/DoubleExtensionMethods.cs | 1 - VectoCore/Utils/RessourceHelper.cs | 2 +- .../EngineOnlyCycle/EngineOnlyCycleTest.cs | 15 ++-- VectoCoreTest/Models/DeclarationDataTest.cs | 35 +++----- .../Models/Simulation/SimulationTests.cs | 2 +- .../Models/SimulationComponent/ClutchTest.cs | 13 ++- .../CombustionEngineTest.cs | 36 ++------ .../Models/SimulationComponent/VehicleTest.cs | 1 - .../Models/SimulationComponent/WheelsTest.cs | 1 - .../FullLoadCurveTest.cs | 24 ++--- .../GearboxDataTest.cs | 48 +++------- VectoCoreTest/Utils/AssertHelper.cs | 24 +++++ VectoCoreTest/Utils/DummyGearbox.cs | 1 - VectoCoreTest/Utils/ResultFileHelper.cs | 4 +- VectoCoreTest/Utils/TestSumWriter.cs | 2 +- VectoCoreTest/VectoCoreTest.csproj | 1 + 47 files changed, 177 insertions(+), 253 deletions(-) create mode 100644 VectoCoreTest/Utils/AssertHelper.cs diff --git a/VECTO.sln.DotSettings b/VECTO.sln.DotSettings index d635c0c1a2..1e16474b71 100644 --- a/VECTO.sln.DotSettings +++ b/VECTO.sln.DotSettings @@ -15,6 +15,7 @@ <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ELSE_ON_NEW_LINE/@EntryValue">False</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FINALLY_ON_NEW_LINE/@EntryValue">False</s:Boolean> <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_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean> <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_BEFORE_TYPEOF_PARENTHESES/@EntryValue">False</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean> diff --git a/VectoCore/Models/Declaration/Axle.cs b/VectoCore/Models/Declaration/Axle.cs index 2a9706ade6..6e06fdb374 100644 --- a/VectoCore/Models/Declaration/Axle.cs +++ b/VectoCore/Models/Declaration/Axle.cs @@ -1,6 +1,6 @@ using TUGraz.VectoCore.Utils; -namespace TUGraz.VectoCore.Models.SimulationComponent.Data +namespace TUGraz.VectoCore.Models.Declaration { public class Axle { diff --git a/VectoCore/Models/Declaration/DeclarationData.cs b/VectoCore/Models/Declaration/DeclarationData.cs index 1e2a7369dd..e12fc5d253 100644 --- a/VectoCore/Models/Declaration/DeclarationData.cs +++ b/VectoCore/Models/Declaration/DeclarationData.cs @@ -9,7 +9,7 @@ private PT1 _pt1; private ElectricSystem _electricSystem; private Fan _fan; - private HVAC _hvac; + private HeatingVentilationAirConditioning _heatingVentilationAirConditioning; private PneumaticSystem _pneumaticSystem; private SteeringPump _steeringPump; @@ -43,9 +43,13 @@ get { return Instance()._fan ?? (Instance()._fan = new Fan()); } } - public static HVAC HVAC + public static HeatingVentilationAirConditioning HeatingVentilationAirConditioning { - get { return Instance()._hvac ?? (Instance()._hvac = new HVAC()); } + get + { + return Instance()._heatingVentilationAirConditioning ?? + (Instance()._heatingVentilationAirConditioning = new HeatingVentilationAirConditioning()); + } } public static PneumaticSystem PneumaticSystem diff --git a/VectoCore/Models/Declaration/HVAC.cs b/VectoCore/Models/Declaration/HVAC.cs index 1abe9195db..16859b6635 100644 --- a/VectoCore/Models/Declaration/HVAC.cs +++ b/VectoCore/Models/Declaration/HVAC.cs @@ -5,7 +5,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public class HVAC : LookupData<MissionType, string, Watt> + public class HeatingVentilationAirConditioning : LookupData<MissionType, string, Watt> { private readonly Dictionary<Tuple<MissionType, string>, Watt> _data = new Dictionary<Tuple<MissionType, string>, Watt>(); diff --git a/VectoCore/Models/Declaration/MissionType.cs b/VectoCore/Models/Declaration/MissionType.cs index 3c53bfa23d..eb1604b9ca 100644 --- a/VectoCore/Models/Declaration/MissionType.cs +++ b/VectoCore/Models/Declaration/MissionType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace TUGraz.VectoCore.Models +namespace TUGraz.VectoCore.Models.Declaration { public enum MissionType { diff --git a/VectoCore/Models/Declaration/Segment.cs b/VectoCore/Models/Declaration/Segment.cs index 2e34c439ae..8db815f6bf 100644 --- a/VectoCore/Models/Declaration/Segment.cs +++ b/VectoCore/Models/Declaration/Segment.cs @@ -1,5 +1,4 @@ using System.IO; -using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration @@ -11,7 +10,7 @@ namespace TUGraz.VectoCore.Models.Declaration public Kilogram GrossVehicleWeightMin { get; set; } public Kilogram GrossVehicleWeightMax { get; set; } - public string HDVClass { get; internal set; } + public string VehicleClass { get; internal set; } public Stream AccelerationFile { get; internal set; } public Mission[] Missions { get; internal set; } } diff --git a/VectoCore/Models/Declaration/Segments.cs b/VectoCore/Models/Declaration/Segments.cs index 766bf0af89..3eeff6b8cc 100644 --- a/VectoCore/Models/Declaration/Segments.cs +++ b/VectoCore/Models/Declaration/Segments.cs @@ -38,7 +38,7 @@ namespace TUGraz.VectoCore.Models.Declaration GrossVehicleWeightMax = row.ParseDouble("gvw_max").SI().Ton.Cast<Kilogram>(), VehicleCategory = vehicleCategory, AxleConfiguration = axleConfiguration, - HDVClass = row.Field<string>("hdv_class"), + VehicleClass = row.Field<string>("hdv_class"), AccelerationFile = RessourceHelper.ReadStream(ResourceNamespace + "VACC." + row.Field<string>("vacc")), Missions = CreateMissions(grossVehicleMassRating, curbWeight, row).ToArray() }; diff --git a/VectoCore/Models/Declaration/Wheels.cs b/VectoCore/Models/Declaration/Wheels.cs index 2122d792e3..85ec531bc1 100644 --- a/VectoCore/Models/Declaration/Wheels.cs +++ b/VectoCore/Models/Declaration/Wheels.cs @@ -1,5 +1,4 @@ -using System; -using System.Data; +using System.Data; using System.Linq; using TUGraz.VectoCore.Utils; @@ -19,7 +18,7 @@ namespace TUGraz.VectoCore.Models.Declaration WheelType = row[0].ToString(), Inertia = row.ParseDouble(1).SI<KilogramSquareMeter>(), DynamicTyreRadius = row.ParseDouble(2).SI().Milli.Meter.Cast<Meter>(), - SizeClass = Int32.Parse(row[3].ToString()) + SizeClass = int.Parse(row[3].ToString()) }).ToDictionary(e => e.WheelType); } diff --git a/VectoCore/Models/Simulation/Data/IModalDataWriter.cs b/VectoCore/Models/Simulation/Data/IModalDataWriter.cs index fa3c9c3a9d..de07839879 100644 --- a/VectoCore/Models/Simulation/Data/IModalDataWriter.cs +++ b/VectoCore/Models/Simulation/Data/IModalDataWriter.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using System.Data; namespace TUGraz.VectoCore.Models.Simulation.Data { @@ -22,7 +20,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data void Finish(); - Object Compute(string expression, string filter); + object Compute(string expression, string filter); IEnumerable<T> GetValues<T>(ModalResultField key); } diff --git a/VectoCore/Models/Simulation/Data/ModalDataWriter.cs b/VectoCore/Models/Simulation/Data/ModalDataWriter.cs index 4e947fed36..7bffe3fe1f 100644 --- a/VectoCore/Models/Simulation/Data/ModalDataWriter.cs +++ b/VectoCore/Models/Simulation/Data/ModalDataWriter.cs @@ -1,6 +1,6 @@ -using System.Data; +using System.Collections.Generic; +using System.Data; using System.Linq; -using System.Collections.Generic; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Simulation.Data diff --git a/VectoCore/Models/Simulation/Data/SummaryFileWriter.cs b/VectoCore/Models/Simulation/Data/SummaryFileWriter.cs index 1ec8730c7c..6c73bc5ff5 100644 --- a/VectoCore/Models/Simulation/Data/SummaryFileWriter.cs +++ b/VectoCore/Models/Simulation/Data/SummaryFileWriter.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -using TUGraz.VectoCore.Utils; -using System.Linq; using System.Data; +using System.Linq; using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Simulation.Data { diff --git a/VectoCore/Models/Simulation/Data/VectoJobData.cs b/VectoCore/Models/Simulation/Data/VectoJobData.cs index feb6ba377e..d36e84b740 100644 --- a/VectoCore/Models/Simulation/Data/VectoJobData.cs +++ b/VectoCore/Models/Simulation/Data/VectoJobData.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.IO; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs index cf5426ad35..ce390b9947 100644 --- a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs +++ b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs @@ -1,5 +1,5 @@ -using System.IO; using System.Collections.Generic; +using System.IO; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent; using TUGraz.VectoCore.Models.SimulationComponent.Data; diff --git a/VectoCore/Models/Simulation/Impl/VectoRun.cs b/VectoCore/Models/Simulation/Impl/VectoRun.cs index 52c9c13a89..8e496ebde5 100644 --- a/VectoCore/Models/Simulation/Impl/VectoRun.cs +++ b/VectoCore/Models/Simulation/Impl/VectoRun.cs @@ -1,6 +1,4 @@ using System; -using System.Data; -using System.IO; using Common.Logging; using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports.Impl; diff --git a/VectoCore/Models/SimulationComponent/Data/AuxiliaryCycleDataAdapter.cs b/VectoCore/Models/SimulationComponent/Data/AuxiliaryCycleDataAdapter.cs index e7d6d2be3d..3bcf89c03e 100644 --- a/VectoCore/Models/SimulationComponent/Data/AuxiliaryCycleDataAdapter.cs +++ b/VectoCore/Models/SimulationComponent/Data/AuxiliaryCycleDataAdapter.cs @@ -25,7 +25,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data _auxiliaryId = column; if (_auxiliaryId != null && !_drivingCycle.Entries.First().AuxiliarySupplyPower.ContainsKey(_auxiliaryId)) { Log.ErrorFormat("driving cycle data does not contain column {0}", column); - throw new VectoException(String.Format("driving cycle does not contain column {0}", column)); + throw new VectoException(string.Format("driving cycle does not contain column {0}", column)); } } @@ -37,7 +37,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data CurrentCycleEntry = _nextCycleEntry.Current; _nextCycleEntry.MoveNext(); } - return String.IsNullOrEmpty(_auxiliaryId) + return string.IsNullOrEmpty(_auxiliaryId) ? CurrentCycleEntry.AdditionalAuxPowerDemand : CurrentCycleEntry.AuxiliarySupplyPower[_auxiliaryId]; } diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs index 0d8ceaeca3..8c431e0abf 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs @@ -6,7 +6,6 @@ using System.Linq; using Common.Logging; using Newtonsoft.Json; using TUGraz.VectoCore.Exceptions; -using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine diff --git a/VectoCore/Models/SimulationComponent/Data/Gearbox/GearData.cs b/VectoCore/Models/SimulationComponent/Data/Gearbox/GearData.cs index 87ef6a9b30..8ed6c34922 100644 --- a/VectoCore/Models/SimulationComponent/Data/Gearbox/GearData.cs +++ b/VectoCore/Models/SimulationComponent/Data/Gearbox/GearData.cs @@ -12,7 +12,7 @@ public double AverageEfficiency { get; set; } - public GearData(TransmissionLossMap lossMap, Gearbox.ShiftPolygon shiftPolygon, double ratio, + public GearData(TransmissionLossMap lossMap, ShiftPolygon shiftPolygon, double ratio, bool torqueconverterActive) { LossMap = lossMap; diff --git a/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs b/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs index 07f5d5f090..df2df5c261 100644 --- a/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs +++ b/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Data; using System.Linq; -using System.Runtime.Remoting.Messaging; using Common.Logging; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Utils; diff --git a/VectoCore/Models/SimulationComponent/Data/Gearbox/TransmissionLossMap.cs b/VectoCore/Models/SimulationComponent/Data/Gearbox/TransmissionLossMap.cs index 8a5b759a3d..a3665d8444 100644 --- a/VectoCore/Models/SimulationComponent/Data/Gearbox/TransmissionLossMap.cs +++ b/VectoCore/Models/SimulationComponent/Data/Gearbox/TransmissionLossMap.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Data; using System.Linq; -using System.Runtime.InteropServices; -using System.Runtime.Remoting.Messaging; using Common.Logging; using Newtonsoft.Json; using TUGraz.VectoCore.Exceptions; @@ -63,7 +61,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox TorqueLoss = row.ParseDouble(Fields.TorqeLoss).SI<NewtonMeter>(), Efficiency = (!hasEfficiency || row[Fields.Efficiency] == DBNull.Value || row[Fields.Efficiency] != null) - ? Double.NaN + ? double.NaN : row.ParseDouble(Fields.Efficiency) }).ToList(); } @@ -109,7 +107,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox 0.SI<NewtonMeter>()); } catch (Exception e) { throw new VectoSimulationException( - String.Format("Failed to interpolate in TransmissionLossMap. angularVelocity: {0}, torque: {1}", angularVelocity, + string.Format("Failed to interpolate in TransmissionLossMap. angularVelocity: {0}, torque: {1}", angularVelocity, gbxOutTorque), e); } } @@ -117,8 +115,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox /// <summary> /// Compute the available torque at the output of the gear(box) (towards wheels) /// </summary> - /// <param name="angularVelocity">[1/s] angular speed of the shaft</param> - /// <param name="gbxInTorque">[Nm] torque provided by the engine at the gearbox' input shaft</param> /// <returns>[Nm] torque provided to the next component (towards the wheels)</returns> //public NewtonMeter GearboxOutTorque(PerSecond angularVelocity, NewtonMeter gbxInTorque) //{ diff --git a/VectoCore/Models/SimulationComponent/Data/GearboxData.cs b/VectoCore/Models/SimulationComponent/Data/GearboxData.cs index 525e86da4a..08dbb96ddf 100644 --- a/VectoCore/Models/SimulationComponent/Data/GearboxData.cs +++ b/VectoCore/Models/SimulationComponent/Data/GearboxData.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Runtime.Serialization; using Newtonsoft.Json; @@ -100,7 +98,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data var lossMapPath = Path.Combine(basePath, gearSettings.LossMap); TransmissionLossMap lossMap = TransmissionLossMap.ReadFromFile(lossMapPath, gearSettings.Ratio); - var shiftPolygon = !String.IsNullOrEmpty(gearSettings.ShiftPolygon) + var shiftPolygon = !string.IsNullOrEmpty(gearSettings.ShiftPolygon) ? ShiftPolygon.ReadFromFile(Path.Combine(basePath, gearSettings.ShiftPolygon)) : null; diff --git a/VectoCore/Models/SimulationComponent/Data/JsonDataHeader.cs b/VectoCore/Models/SimulationComponent/Data/JsonDataHeader.cs index db169b94b8..bbfac2a44c 100644 --- a/VectoCore/Models/SimulationComponent/Data/JsonDataHeader.cs +++ b/VectoCore/Models/SimulationComponent/Data/JsonDataHeader.cs @@ -1,5 +1,4 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace TUGraz.VectoCore.Models.SimulationComponent.Data { diff --git a/VectoCore/Models/SimulationComponent/Data/RetarderData.cs b/VectoCore/Models/SimulationComponent/Data/RetarderData.cs index bb1c46cf10..bab160a183 100644 --- a/VectoCore/Models/SimulationComponent/Data/RetarderData.cs +++ b/VectoCore/Models/SimulationComponent/Data/RetarderData.cs @@ -1,5 +1,4 @@ using System.IO; -using System.Runtime.InteropServices; using Newtonsoft.Json; namespace TUGraz.VectoCore.Models.SimulationComponent.Data diff --git a/VectoCore/Models/SimulationComponent/Data/RetarderLossMap.cs b/VectoCore/Models/SimulationComponent/Data/RetarderLossMap.cs index d3feadd3cd..e610c1ca8a 100644 --- a/VectoCore/Models/SimulationComponent/Data/RetarderLossMap.cs +++ b/VectoCore/Models/SimulationComponent/Data/RetarderLossMap.cs @@ -3,7 +3,6 @@ using System.Data; using System.Linq; using Common.Logging; using TUGraz.VectoCore.Exceptions; -using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Data diff --git a/VectoCore/Models/SimulationComponent/Data/SimulationComponentData.cs b/VectoCore/Models/SimulationComponent/Data/SimulationComponentData.cs index ea6d458a1f..9cb621a200 100644 --- a/VectoCore/Models/SimulationComponent/Data/SimulationComponentData.cs +++ b/VectoCore/Models/SimulationComponent/Data/SimulationComponentData.cs @@ -16,8 +16,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data protected static Tuple<int, bool> GetFileVersion(string jsonStr) { dynamic json = JsonConvert.DeserializeObject(jsonStr); - return new Tuple<int, bool>(Int32.Parse(json.Header.FileVersion.ToString()), - Boolean.Parse(json.Body.SavedInDeclMode.ToString())); + return new Tuple<int, bool>(int.Parse(json.Header.FileVersion.ToString()), + bool.Parse(json.Body.SavedInDeclMode.ToString())); } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Factories/EngineeringModeFactory.cs b/VectoCore/Models/SimulationComponent/Factories/EngineeringModeFactory.cs index 786d027931..af2c8e0e53 100644 --- a/VectoCore/Models/SimulationComponent/Factories/EngineeringModeFactory.cs +++ b/VectoCore/Models/SimulationComponent/Factories/EngineeringModeFactory.cs @@ -3,6 +3,7 @@ using System.Linq; using Newtonsoft.Json; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.FileIO; +using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Utils; diff --git a/VectoCore/Models/SimulationComponent/IClutch.cs b/VectoCore/Models/SimulationComponent/IClutch.cs index 953f3f613f..1ffff0489c 100644 --- a/VectoCore/Models/SimulationComponent/IClutch.cs +++ b/VectoCore/Models/SimulationComponent/IClutch.cs @@ -1,6 +1,4 @@ -using TUGraz.VectoCore.Models.Connector.Ports; - -namespace TUGraz.VectoCore.Models.SimulationComponent +namespace TUGraz.VectoCore.Models.SimulationComponent { public interface IClutch : IPowerTrainComponent {} } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/IVehicle.cs b/VectoCore/Models/SimulationComponent/IVehicle.cs index 5a1a336c12..de6646fbf0 100644 --- a/VectoCore/Models/SimulationComponent/IVehicle.cs +++ b/VectoCore/Models/SimulationComponent/IVehicle.cs @@ -3,8 +3,4 @@ namespace TUGraz.VectoCore.Models.SimulationComponent { public interface IVehicle : IRoadPortInProvider, IDriverDemandOutProvider, IFvInPort, IDriverDemandOutPort {} -} - -/// </summary> -// public interface IVehicle : IDriverDemandOutProvider, IRoadPortInProvider {} -//} \ No newline at end of file +} \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index b7b1ce901b..3a161c68b6 100644 --- a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.Contracts; -using NLog.LayoutRenderers; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports.Impl; @@ -84,7 +83,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _currentState.EnginePowerLoss = InertiaPowerLoss(torque, engineSpeed); var requestedEnginePower = requestedPower + _currentState.EnginePowerLoss; - if (engineSpeed < (double) _data.IdleSpeed - EngineIdleSpeedStopThreshold) { + if (engineSpeed < (double)_data.IdleSpeed - EngineIdleSpeedStopThreshold) { _currentState.OperationMode = EngineOperationMode.Stopped; //todo: _currentState.EnginePowerLoss = enginePowerLoss; } @@ -116,15 +115,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public override void CommitSimulationStep(IModalDataWriter writer) { - writer[ModalResultField.PaEng] = (double) _currentState.EnginePowerLoss; - writer[ModalResultField.Pe_drag] = (double) _currentState.FullDragPower; - writer[ModalResultField.Pe_full] = (double) _currentState.DynamicFullLoadPower; - writer[ModalResultField.Pe_eng] = (double) _currentState.EnginePower; + writer[ModalResultField.PaEng] = (double)_currentState.EnginePowerLoss; + writer[ModalResultField.Pe_drag] = (double)_currentState.FullDragPower; + writer[ModalResultField.Pe_full] = (double)_currentState.DynamicFullLoadPower; + writer[ModalResultField.Pe_eng] = (double)_currentState.EnginePower; - writer[ModalResultField.Tq_drag] = (double) _currentState.FullDragTorque; - writer[ModalResultField.Tq_full] = (double) _currentState.DynamicFullLoadTorque; - writer[ModalResultField.Tq_eng] = (double) _currentState.EngineTorque; - writer[ModalResultField.n] = (double) _currentState.EngineSpeed.ConvertTo().Rounds.Per.Minute; + writer[ModalResultField.Tq_drag] = (double)_currentState.FullDragTorque; + writer[ModalResultField.Tq_full] = (double)_currentState.DynamicFullLoadTorque; + writer[ModalResultField.Tq_eng] = (double)_currentState.EngineTorque; + writer[ModalResultField.n] = (double)_currentState.EngineSpeed.ConvertTo().Rounds.Per.Minute; try { writer[ModalResultField.FC] = @@ -135,7 +134,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } catch (VectoException ex) { Log.WarnFormat("t: {0} - {1} n: {2} Tq: {3}", _currentState.AbsTime.TotalSeconds, ex.Message, _currentState.EngineSpeed, _currentState.EngineTorque); - writer[ModalResultField.FC] = Double.NaN; + writer[ModalResultField.FC] = double.NaN; } _previousState = _currentState; @@ -153,11 +152,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Contract.Requires(requestedEnginePower.HasEqualUnit(new SI().Watt)); if (_currentState.FullDragPower >= 0 && requestedEnginePower < 0) { - throw new VectoSimulationException(String.Format("t: {0} P_engine_drag > 0! n: {1} [1/min] ", + throw new VectoSimulationException(string.Format("t: {0} P_engine_drag > 0! n: {1} [1/min] ", _currentState.AbsTime, _currentState.EngineSpeed.ConvertTo().Rounds.Per.Minute)); } if (_currentState.DynamicFullLoadPower <= 0 && requestedEnginePower > 0) { - throw new VectoSimulationException(String.Format("t: {0} P_engine_full < 0! n: {1} [1/min] ", + throw new VectoSimulationException(string.Format("t: {0} P_engine_full < 0! n: {1} [1/min] ", _currentState.AbsTime, _currentState.EngineSpeed.ConvertTo().Rounds.Per.Minute)); } } @@ -360,7 +359,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public override int GetHashCode() { unchecked { - var hashCode = (int) OperationMode; + var hashCode = (int)OperationMode; hashCode = (hashCode * 397) ^ (EnginePower != null ? EnginePower.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (EngineSpeed != null ? EngineSpeed.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (EnginePowerLoss != null ? EnginePowerLoss.GetHashCode() : 0); @@ -382,7 +381,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (ReferenceEquals(this, obj)) { return true; } - return obj.GetType() == GetType() && Equals((CombustionEngine) obj); + return obj.GetType() == GetType() && Equals((CombustionEngine)obj); } protected bool Equals(CombustionEngine other) diff --git a/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs b/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs index 368ecfb617..eb7a7deddf 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs @@ -1,11 +1,10 @@ using System; -using TUGraz.VectoCore.Utils; using TUGraz.VectoCore.Exceptions; -using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Connector.Ports; +using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data; - +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { @@ -55,7 +54,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (_outPort == null) { Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime); throw new VectoSimulationException( - String.Format("{0} cannot handle incoming request - no outport available", + string.Format("{0} cannot handle incoming request - no outport available", absTime.TotalSeconds)); } diff --git a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs index 50b9421f52..d6b997ae04 100644 --- a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs @@ -8,67 +8,66 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class EngineOnlyGearbox : VectoSimulationComponent, IGearbox, ITnInPort, ITnOutPort - { - private ITnOutPort _outPort; - public EngineOnlyGearbox(IVehicleContainer cockpit) : base(cockpit) {} + public class EngineOnlyGearbox : VectoSimulationComponent, IGearbox, ITnInPort, ITnOutPort + { + private ITnOutPort _outPort; + public EngineOnlyGearbox(IVehicleContainer cockpit) : base(cockpit) {} - #region IInShaft + #region IInShaft - public ITnInPort InShaft() - { - return this; - } + public ITnInPort InShaft() + { + return this; + } - #endregion IOutShaft + #endregion IOutShaft - #region IOutShaft + #region IOutShaft - public ITnOutPort OutShaft() - { - return this; - } + public ITnOutPort OutShaft() + { + return this; + } - #endregion + #endregion - #region IGearboxCockpit + #region IGearboxCockpit - uint IGearboxCockpit.Gear() - { - return 0; - } + uint IGearboxCockpit.Gear() + { + return 0; + } - #endregion + #endregion - #region ITnInPort + #region ITnInPort - void ITnInPort.Connect(ITnOutPort other) - { - _outPort = other; - } + void ITnInPort.Connect(ITnOutPort other) + { + _outPort = other; + } - #endregion + #endregion + #region ITnOutPort - #region ITnOutPort + IResponse ITnOutPort.Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond engineSpeed) + { + if (_outPort == null) { + Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime); + throw new VectoSimulationException( + string.Format("{0} cannot handle incoming request - no outport available", + absTime.TotalSeconds)); + } + return _outPort.Request(absTime, dt, torque, engineSpeed); + } - IResponse ITnOutPort.Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond engineSpeed) - { - if (_outPort == null) { - Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime); - throw new VectoSimulationException( - String.Format("{0} cannot handle incoming request - no outport available", - absTime.TotalSeconds)); - } - return _outPort.Request(absTime, dt, torque, engineSpeed); - } + #endregion - #endregion + #region VectoSimulationComponent - #region VectoSimulationComponent + public override void CommitSimulationStep(IModalDataWriter writer) {} - public override void CommitSimulationStep(IModalDataWriter writer) {} - - #endregion - } + #endregion + } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs b/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs index 1182205cb2..3642568920 100644 --- a/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs +++ b/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs @@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (_outPort == null) { Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime); throw new VectoSimulationException( - String.Format("{0} cannot handle incoming request - no outport available", + string.Format("{0} cannot handle incoming request - no outport available", absTime.TotalSeconds)); } diff --git a/VectoCore/Utils/DoubleExtensionMethods.cs b/VectoCore/Utils/DoubleExtensionMethods.cs index 439afc2820..813c467d95 100644 --- a/VectoCore/Utils/DoubleExtensionMethods.cs +++ b/VectoCore/Utils/DoubleExtensionMethods.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; diff --git a/VectoCore/Utils/RessourceHelper.cs b/VectoCore/Utils/RessourceHelper.cs index 5aa9a5e8bc..d91325e923 100644 --- a/VectoCore/Utils/RessourceHelper.cs +++ b/VectoCore/Utils/RessourceHelper.cs @@ -1,7 +1,7 @@ using System.IO; using System.Reflection; -namespace TUGraz.VectoCore.Models +namespace TUGraz.VectoCore.Utils { public static class RessourceHelper { diff --git a/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs b/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs index 847731dcca..6285c37b94 100644 --- a/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs +++ b/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs @@ -1,6 +1,5 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.VisualStudio.TestTools.UnitTesting.Web; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Data; @@ -65,25 +64,25 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle for (var j = 0; j < results.Length; j++) { var field = results[j]; // if (!Double.IsNaN(dataWriter.GetDouble(field))) - Assert.AreEqual((double) row[field.GetName()], dataWriter.GetDouble(field), + Assert.AreEqual((double)row[field.GetName()], dataWriter.GetDouble(field), 0.0001, - String.Format("t: {0} field: {1}", i, field)); + string.Format("t: {0} field: {1}", i, field)); } if (row[ModalResultField.FC.GetName()] is double && - !Double.IsNaN(Double.Parse(row[ModalResultField.FC.GetName()].ToString()))) { - Assert.AreEqual((double) row[ModalResultField.FC.GetName()], + !double.IsNaN(double.Parse(row[ModalResultField.FC.GetName()].ToString()))) { + Assert.AreEqual((double)row[ModalResultField.FC.GetName()], dataWriter.GetDouble(ModalResultField.FC), 0.01, "t: {0} field: {1}", i, ModalResultField.FC); } else { - Assert.IsTrue(Double.IsNaN(dataWriter.GetDouble(ModalResultField.FC)), - String.Format("t: {0}", i)); + Assert.IsTrue(double.IsNaN(dataWriter.GetDouble(ModalResultField.FC)), + string.Format("t: {0}", i)); } } dataWriter.CommitSimulationStep(absTime, dt); absTime += dt; } - dataWriter.Data.WriteToFile(String.Format("result_{0}.csv", TestContext.DataRow["TestName"].ToString())); + dataWriter.Data.WriteToFile(string.Format("result_{0}.csv", TestContext.DataRow["TestName"].ToString())); } [TestMethod] diff --git a/VectoCoreTest/Models/DeclarationDataTest.cs b/VectoCoreTest/Models/DeclarationDataTest.cs index c743d91216..80820c564c 100644 --- a/VectoCoreTest/Models/DeclarationDataTest.cs +++ b/VectoCoreTest/Models/DeclarationDataTest.cs @@ -4,9 +4,9 @@ using System.IO; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Exceptions; -using TUGraz.VectoCore.Models; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Tests.Utils; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Models @@ -16,19 +16,6 @@ namespace TUGraz.VectoCore.Tests.Models { public const double Tolerance = 0.0001; - public static void AssertException<T>(Action func, string message = null) where T : Exception - { - try { - func(); - Assert.Fail("Expected an exception."); - } catch (T ex) { - if (!string.IsNullOrEmpty(message)) { - Assert.AreEqual(message, ex.Message); - } - } - } - - [TestMethod] public void WheelDataTest() { @@ -83,8 +70,8 @@ namespace TUGraz.VectoCore.Tests.Models // EXTRAPOLATE Assert.AreEqual(0.11, pt1.Lookup(3000.RPMtoRad()).Double(), Tolerance); - AssertException<VectoException>(() => pt1.Lookup(200.RPMtoRad())); - AssertException<VectoException>(() => pt1.Lookup(0.RPMtoRad())); + AssertHelper.Exception<VectoException>(() => pt1.Lookup(200.RPMtoRad())); + AssertHelper.Exception<VectoException>(() => pt1.Lookup(0.RPMtoRad())); } @@ -95,7 +82,7 @@ namespace TUGraz.VectoCore.Tests.Models } [TestMethod] - public void AuxESTechTest() + public void AuxElectricSystemTest() { var es = DeclarationData.ElectricSystem; @@ -115,10 +102,10 @@ namespace TUGraz.VectoCore.Tests.Models foreach (var expectation in expected) { var baseConsumption = es.Lookup(expectation.Mission, technologies: new string[] { }); - var withLEDs = es.Lookup(expectation.Mission, technologies: new[] { "LED lights" }); + var leds = es.Lookup(expectation.Mission, technologies: new[] { "LED lights" }); Assert.AreEqual(expectation.Base, baseConsumption.Double(), Tolerance); - Assert.AreEqual(expectation.LED, withLEDs.Double(), Tolerance); + Assert.AreEqual(expectation.LED, leds.Double(), Tolerance); } } @@ -188,9 +175,9 @@ namespace TUGraz.VectoCore.Tests.Models } [TestMethod] - public void AuxHVACTest() + public void AuxHeatingVentilationAirConditionTest() { - var hvac = DeclarationData.HVAC; + var hvac = DeclarationData.HeatingVentilationAirConditioning; var expected = new Dictionary<string, int[]> { { "1", new[] { 0, 150, 150, 0, 0, 0, 0, 0, 0, 0 } }, @@ -225,7 +212,7 @@ namespace TUGraz.VectoCore.Tests.Models } [TestMethod] - public void AuxPSTest() + public void AuxPneumaticSystemTest() { var ps = DeclarationData.PneumaticSystem; @@ -262,7 +249,7 @@ namespace TUGraz.VectoCore.Tests.Models } [TestMethod] - public void AuxSPTest() + public void AuxSteeringPumpTest() { var sp = DeclarationData.SteeringPump; @@ -357,7 +344,7 @@ namespace TUGraz.VectoCore.Tests.Models vehicleData.GrossVehicleMassRating, vehicleData.CurbWeight); - Assert.AreEqual("2", segment.HDVClass); + Assert.AreEqual("2", segment.VehicleClass); var data = AccelerationCurveData.ReadFromStream(segment.AccelerationFile); TestAcceleration(data); diff --git a/VectoCoreTest/Models/Simulation/SimulationTests.cs b/VectoCoreTest/Models/Simulation/SimulationTests.cs index a2c60c1abf..57899da508 100644 --- a/VectoCoreTest/Models/Simulation/SimulationTests.cs +++ b/VectoCoreTest/Models/Simulation/SimulationTests.cs @@ -4,8 +4,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.Impl; -using TUGraz.VectoCore.Utils; using TUGraz.VectoCore.Tests.Utils; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Models.Simulation { diff --git a/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs b/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs index 948f42e378..8282b61b20 100644 --- a/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs @@ -1,6 +1,5 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Impl; @@ -34,22 +33,22 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent gearbox.CurrentGear = 1; clutchOutPort.Request(new TimeSpan(), new TimeSpan(), 100.SI<NewtonMeter>(), 30.SI<PerSecond>()); - Assert.AreEqual(48.293649, (double) outPort.Torque, 0.001); - Assert.AreEqual(62.119969, (double) outPort.AngularVelocity, 0.001); + Assert.AreEqual(48.293649, (double)outPort.Torque, 0.001); + Assert.AreEqual(62.119969, (double)outPort.AngularVelocity, 0.001); //Test - Clutch opened gearbox.CurrentGear = 0; clutchOutPort.Request(new TimeSpan(), new TimeSpan(), 100.SI<NewtonMeter>(), 30.SI<PerSecond>()); - Assert.AreEqual(0, (double) outPort.Torque, 0.001); - Assert.AreEqual((double) engineData.IdleSpeed, (double) outPort.AngularVelocity, 0.001); + Assert.AreEqual(0, (double)outPort.Torque, 0.001); + Assert.AreEqual((double)engineData.IdleSpeed, (double)outPort.AngularVelocity, 0.001); //Test - Clutch closed gearbox.CurrentGear = 1; clutchOutPort.Request(new TimeSpan(), new TimeSpan(), 100.SI<NewtonMeter>(), 80.SI<PerSecond>()); - Assert.AreEqual(100.0, (double) outPort.Torque, 0.001); - Assert.AreEqual(80.0, (double) outPort.AngularVelocity, 0.001); + Assert.AreEqual(100.0, (double)outPort.Torque, 0.001); + Assert.AreEqual(80.0, (double)outPort.AngularVelocity, 0.001); } } } \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs index d463a85778..1c41b67f46 100644 --- a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Reflection; using Microsoft.VisualStudio.TestTools.UnitTesting; -using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Data; @@ -25,24 +24,6 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent AppDomain.CurrentDomain.SetData("DataDirectory", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); } - /// <summary> - /// Assert an expected Exception. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="func"></param> - /// <param name="message"></param> - public static void AssertException<T>(Action func, string message = null) where T : Exception - { - try { - func(); - Assert.Fail("Expected Exception {0}, but no exception occured.", typeof(T)); - } catch (T ex) { - if (message != null) { - Assert.AreEqual(message, ex.Message); - } - } - } - [TestMethod] public void TestEngineHasOutPort() { @@ -79,7 +60,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var vehicle = new VehicleContainer(); var engineData = CombustionEngineData.ReadFromFile(CoachEngine); var engine = new CombustionEngine(vehicle, engineData); - var gearbox = new EngineOnlyGearbox(vehicle); + new EngineOnlyGearbox(vehicle); var port = engine.OutShaft(); var absTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); @@ -108,7 +89,6 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent absTime += dt; var power = new[] { 569.3641, 4264.177 }; - ; for (var i = 0; i < 2; i++) { port.Request(absTime, dt, Formulas.PowerToTorque(power[i].SI<Watt>(), engineSpeed), engineSpeed); engine.CommitSimulationStep(dataWriter); @@ -131,7 +111,6 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(-7108.32, dataWriter.GetDouble(ModalResultField.PaEng), 0.001); dataWriter.CommitSimulationStep(absTime, dt); - absTime += dt; dataWriter.Data.WriteToFile(@"test1.csv"); } @@ -156,9 +135,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent //var modalData = new ModalDataWriter(string.Format("load_jump_{0}.csv", TestContext.DataRow["TestName"].ToString())); var modalData = new TestModalDataWriter(); - var idlePower = Double.Parse(TestContext.DataRow["initialIdleLoad"].ToString()).SI<Watt>(); + var idlePower = double.Parse(TestContext.DataRow["initialIdleLoad"].ToString()).SI<Watt>(); - var angularSpeed = Double.Parse(TestContext.DataRow["rpm"].ToString()).RPMtoRad(); + var angularSpeed = double.Parse(TestContext.DataRow["rpm"].ToString()).RPMtoRad(); var t = TimeSpan.FromSeconds(0); var dt = TimeSpan.FromSeconds(0.1); @@ -172,7 +151,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent // dt = TimeSpan.FromSeconds(double.Parse(TestContext.DataRow["dt"].ToString(), CultureInfo.InvariantCulture)); // dt = TimeSpan.FromSeconds(expectedResults.Rows[i].ParseDouble(0)) - t; var engineLoadPower = engineData.GetFullLoadCurve(0).FullLoadStationaryPower(angularSpeed); - idlePower = Double.Parse(TestContext.DataRow["finalIdleLoad"].ToString()).SI<Watt>(); + idlePower = double.Parse(TestContext.DataRow["finalIdleLoad"].ToString()).SI<Watt>(); for (; t.TotalSeconds < 25; t += dt, i++) { dt = TimeSpan.FromSeconds(expectedResults.Rows[i + 1].ParseDouble(0) - expectedResults.Rows[i].ParseDouble(0)); if (t >= TimeSpan.FromSeconds(10)) { @@ -185,7 +164,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent // todo: compare results... Assert.AreEqual(expectedResults.Rows[i].ParseDouble(0), t.TotalSeconds, 0.001, "Time"); Assert.AreEqual(expectedResults.Rows[i].ParseDouble(1), modalData.GetDouble(ModalResultField.Pe_full), 0.1, - String.Format("Load in timestep {0}", t)); + string.Format("Load in timestep {0}", t)); modalData.CommitSimulationStep(); } modalData.Finish(); @@ -257,9 +236,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(58.6430628670095, idle.Double(), 0.000001); Assert.IsTrue(idle.HasEqualUnit(0.SI<PerSecond>())); - var flc0 = engineData.GetFullLoadCurve(0); - - AssertException<KeyNotFoundException>(() => { var flc10000 = engineData.GetFullLoadCurve(1000); }); + engineData.GetFullLoadCurve(0); + AssertHelper.Exception<KeyNotFoundException>(() => engineData.GetFullLoadCurve(1000)); } } } \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs index 30c5ea3249..508dee2cba 100644 --- a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs @@ -1,7 +1,6 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Models.Simulation.Impl; -using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Factories; using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.Tests.Utils; diff --git a/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs index 9a874c5931..e5ad1d5947 100644 --- a/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs @@ -2,7 +2,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent; -using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Factories; using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.Tests.Utils; diff --git a/VectoCoreTest/Models/SimulationComponentData/FullLoadCurveTest.cs b/VectoCoreTest/Models/SimulationComponentData/FullLoadCurveTest.cs index 7e66f3f63f..53eb73c7d6 100644 --- a/VectoCoreTest/Models/SimulationComponentData/FullLoadCurveTest.cs +++ b/VectoCoreTest/Models/SimulationComponentData/FullLoadCurveTest.cs @@ -1,7 +1,7 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; +using TUGraz.VectoCore.Tests.Utils; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData @@ -77,12 +77,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData [TestMethod] public void Test_FileRead_WrongFileFormat_InsufficientColumns() { - try { - var curve = FullLoadCurve.ReadFromFile(@"TestData\Components\FullLoadCurve insufficient columns.vfld"); - Assert.Fail("this should not be reached."); - } catch (VectoException ex) { - Assert.AreEqual("FullLoadCurve Data File must consist of 4 columns.", ex.Message); - } + AssertHelper.Exception<VectoException>( + () => FullLoadCurve.ReadFromFile(@"TestData\Components\FullLoadCurve insufficient columns.vfld"), + "FullLoadCurve Data File must consist of 4 columns."); } /// <summary> @@ -112,14 +109,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData [TestMethod] public void Test_FileRead_InsufficientEntries() { - try { - FullLoadCurve.ReadFromFile(@"TestData\Components\FullLoadCurve insufficient entries.vfld"); - Assert.Fail("this should not be reached."); - } catch (VectoException ex) { - Assert.AreEqual( - "FullLoadCurve must consist of at least two lines with numeric values (below file header)", - ex.Message); - } + AssertHelper.Exception<VectoException>( + () => FullLoadCurve.ReadFromFile(@"TestData\Components\FullLoadCurve insufficient entries.vfld"), + "FullLoadCurve must consist of at least two lines with numeric values (below file header)"); } } } \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs b/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs index b244798b84..976ce6a40b 100644 --- a/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs +++ b/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs @@ -3,6 +3,7 @@ using System.Globalization; using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Tests.Utils; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData @@ -46,8 +47,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData var gbxData = GearboxData.ReadFromFile(TestContext.DataRow["GearboxDataFile"].ToString()); - - var PvD = Double.Parse(TestContext.DataRow["PowerGbxOut"].ToString(), CultureInfo.InvariantCulture).SI<Watt>(); + var PvD = double.Parse(TestContext.DataRow["PowerGbxOut"].ToString(), CultureInfo.InvariantCulture).SI<Watt>(); var torqueToWheels = Formulas.PowerToTorque(PvD, SpeedToAngularSpeed(speed, rdyn)); var torqueFromEngine = 0.SI<NewtonMeter>(); @@ -60,7 +60,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData var powerEngine = Formulas.TorqueToPower(torqueFromEngine, angSpeed); var loss = powerEngine - PvD; - Assert.AreEqual(Double.Parse(TestContext.DataRow["GbxPowerLoss"].ToString(), CultureInfo.InvariantCulture), + Assert.AreEqual(double.Parse(TestContext.DataRow["GbxPowerLoss"].ToString(), CultureInfo.InvariantCulture), loss.Double(), 0.1, TestContext.DataRow["TestName"].ToString()); } @@ -70,43 +70,17 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData { var gbxData = GearboxData.ReadFromFile(GearboxFile); + AssertHelper.Exception<VectoSimulationException>( + () => gbxData.AxleGearData.LossMap.GearboxInTorque(2700.RPMtoRad(), 100.SI<NewtonMeter>())); - var angSpeed = 2700.RPMtoRad(); - var torqueToWheels = 100.SI<NewtonMeter>(); - - try { - gbxData.AxleGearData.LossMap.GearboxInTorque(angSpeed, torqueToWheels); - Assert.Fail("angular Speed too high"); - } catch (Exception e) { - Assert.IsInstanceOfType(e, typeof(VectoSimulationException), "angular speed too high"); - } + AssertHelper.Exception<VectoSimulationException>( + () => gbxData.AxleGearData.LossMap.GearboxInTorque(1000.RPMtoRad(), 50000.SI<NewtonMeter>())); - angSpeed = 1000.RPMtoRad(); - torqueToWheels = 50000.SI<NewtonMeter>(); - try { - gbxData.AxleGearData.LossMap.GearboxInTorque(angSpeed, torqueToWheels); - Assert.Fail("torque too high"); - } catch (Exception e) { - Assert.IsInstanceOfType(e, typeof(VectoSimulationException), "torque too high"); - } + AssertHelper.Exception<VectoSimulationException>( + () => gbxData.AxleGearData.LossMap.GearboxInTorque(1000.RPMtoRad(), -10000.SI<NewtonMeter>())); - angSpeed = 1000.RPMtoRad(); - torqueToWheels = -10000.SI<NewtonMeter>(); - try { - gbxData.AxleGearData.LossMap.GearboxInTorque(angSpeed, torqueToWheels); - Assert.Fail("torque too low"); - } catch (Exception e) { - Assert.IsInstanceOfType(e, typeof(VectoSimulationException), "torque too low"); - } - - angSpeed = -1000.RPMtoRad(); - torqueToWheels = 500.SI<NewtonMeter>(); - try { - gbxData.AxleGearData.LossMap.GearboxInTorque(angSpeed, torqueToWheels); - Assert.Fail("negative angular speed"); - } catch (Exception e) { - Assert.IsInstanceOfType(e, typeof(VectoSimulationException), "negative angular speed"); - } + AssertHelper.Exception<VectoSimulationException>( + () => gbxData.AxleGearData.LossMap.GearboxInTorque(-1000.RPMtoRad(), 500.SI<NewtonMeter>())); } protected PerSecond SpeedToAngularSpeed(double v, double r) diff --git a/VectoCoreTest/Utils/AssertHelper.cs b/VectoCoreTest/Utils/AssertHelper.cs new file mode 100644 index 0000000000..7236d9bf6e --- /dev/null +++ b/VectoCoreTest/Utils/AssertHelper.cs @@ -0,0 +1,24 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace TUGraz.VectoCore.Tests.Utils +{ + public class AssertHelper + { + /// <summary> + /// Assert an expected Exception. + /// </summary> + public static void Exception<T>(Action func, string message = null) where T : Exception + { + try { + func(); + Assert.Fail("Expected Exception {0}, but no exception occured.", typeof(T)); + } catch (T ex) { + if (!string.IsNullOrEmpty(message)) { + Assert.AreEqual(message, ex.Message, + string.Format("Expected Exception message: {0}, but got message: {}", message, ex.Message)); + } + } + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/Utils/DummyGearbox.cs b/VectoCoreTest/Utils/DummyGearbox.cs index fd22e802a5..e1e3610186 100644 --- a/VectoCoreTest/Utils/DummyGearbox.cs +++ b/VectoCoreTest/Utils/DummyGearbox.cs @@ -1,5 +1,4 @@ using System; -using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; diff --git a/VectoCoreTest/Utils/ResultFileHelper.cs b/VectoCoreTest/Utils/ResultFileHelper.cs index 3658b316ca..6983a3a49b 100644 --- a/VectoCoreTest/Utils/ResultFileHelper.cs +++ b/VectoCoreTest/Utils/ResultFileHelper.cs @@ -1,8 +1,8 @@ using System; -using System.IO; +using System.Collections.Generic; using System.Data; +using System.IO; using System.Linq; -using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Models.Simulation.Data; diff --git a/VectoCoreTest/Utils/TestSumWriter.cs b/VectoCoreTest/Utils/TestSumWriter.cs index 803f01004a..d24cf56fa9 100644 --- a/VectoCoreTest/Utils/TestSumWriter.cs +++ b/VectoCoreTest/Utils/TestSumWriter.cs @@ -1,6 +1,6 @@ using TUGraz.VectoCore.Models.Simulation.Data; -namespace TUGraz.VectoCore.Tests.Models.Simulation +namespace TUGraz.VectoCore.Tests.Utils { public class TestSumWriter : SummaryFileWriter, ISummaryDataWriter { diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj index d7ae801e17..4986286459 100644 --- a/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCoreTest/VectoCoreTest.csproj @@ -83,6 +83,7 @@ <Compile Include="Models\SimulationComponent\WheelsTest.cs" /> <Compile Include="Models\SimulationComponent\VehicleTest.cs" /> <Compile Include="Models\Simulation\DrivingCycleTests.cs" /> + <Compile Include="Utils\AssertHelper.cs" /> <Compile Include="Utils\ResultFileHelper.cs" /> <Compile Include="Utils\MockPorts.cs" /> <Compile Include="Models\Simulation\SimulationTests.cs" /> -- GitLab