From 236c7928a04c3418a90c3f4beda0213d99168ae5 Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Sun, 21 Jan 2024 21:49:41 +0500 Subject: [PATCH] Trace logger calls were adde in limit curve calculator --- .../Calculators/LimitCurveVisualCalculator.cs | 3 + .../CalculatorsViews/CrackDiagramLogic.cs | 3 + .../InteractionDiagramLogic.cs | 5 +- .../ForceResultLogic/ShowDiagramLogic.cs | 2 + .../NdmCrossSections/AnalysisVewModelLogic.cs | 14 +-- .../Interfaces/ILongProcessLogic.cs | 3 + .../Calculators/FindParameterCalculator.cs | 8 +- .../Models/Calculators/ICalculator.cs | 2 + .../Models/Loggers/ILogger.cs | 13 +++ .../Models/Loggers/ITraceLogger.cs | 14 +++ .../Models/Loggers/ITraceLoggerEntry.cs | 14 +++ .../Models/Loggers/StringLoggerEntry.cs | 20 +++++ .../Models/Loggers/TraceLogger.cs | 57 ++++++++++++ .../Models/Loggers/TraceLoggerStatuses.cs | 18 ++++ .../Models/Soils/AnchorCalculator.cs | 2 + .../StructureHelperCommon.csproj | 4 + .../Analyses/ByForces/ForceCalculator.cs | 2 + .../Analyses/ByForces/ForceTupleCalculator.cs | 2 + .../LimitCurve/Factories/GetPredicateLogic.cs | 3 + .../Factories/IGetPredicateLogic.cs | 5 +- .../ByForces/LimitCurve/ILimitCurveLogic.cs | 2 + .../LimitCurve/ILimitCurveParameterLogic.cs | 5 ++ .../LimitCurve/LimitCurveCalculator.cs | 9 ++ .../ByForces/LimitCurve/LimitCurveLogic.cs | 88 +++++++++---------- .../LimitCurve/LimitCurveParameterLogic.cs | 3 + .../LimitCurve/LimitCurvesCalculator.cs | 20 +++-- .../LimitCurve/StabLimitCurveLogic.cs | 2 + .../Logics/InterpolationProgressLogic.cs | 3 + .../Analyses/Geometry/GeometryCalculator.cs | 2 + .../Buckling/ConcreteBucklingCalculator.cs | 2 + .../Cracking/CrackForceCalculator.cs | 3 + .../Cracking/CrackWidthCalculator.cs | 3 + .../Cracking/CrackWidthSimpleCalculator.cs | 2 + .../Calcuators/LimitCurveCalculatorTest.cs | 1 + .../Calcuators/LimitCurveLogicTest.cs | 32 +------ 35 files changed, 280 insertions(+), 91 deletions(-) create mode 100644 StructureHelperCommon/Models/Loggers/ILogger.cs create mode 100644 StructureHelperCommon/Models/Loggers/ITraceLogger.cs create mode 100644 StructureHelperCommon/Models/Loggers/ITraceLoggerEntry.cs create mode 100644 StructureHelperCommon/Models/Loggers/StringLoggerEntry.cs create mode 100644 StructureHelperCommon/Models/Loggers/TraceLogger.cs create mode 100644 StructureHelperCommon/Models/Loggers/TraceLoggerStatuses.cs diff --git a/StructureHelper/Models/Calculators/LimitCurveVisualCalculator.cs b/StructureHelper/Models/Calculators/LimitCurveVisualCalculator.cs index c81ac24..dc99558 100644 --- a/StructureHelper/Models/Calculators/LimitCurveVisualCalculator.cs +++ b/StructureHelper/Models/Calculators/LimitCurveVisualCalculator.cs @@ -1,5 +1,6 @@ using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using System; using System.Collections.Generic; @@ -18,6 +19,8 @@ namespace StructureHelper.Models.Calculators public IResult Result => result; + public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public void Run() { throw new NotImplementedException(); diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs index 2520d47..ab20ba8 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs @@ -4,6 +4,7 @@ using StructureHelper.Windows.ViewModels.Errors; using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Settings; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Parameters; using StructureHelperCommon.Services.Units; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; @@ -35,6 +36,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews public int StepCount => ValidTupleList.Count(); + public ITraceLogger? TraceLogger { get; set; } + public CrackDiagramLogic(IEnumerable tupleList, IEnumerable ndmPrimitives) { TupleList = tupleList; diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/InteractionDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/InteractionDiagramLogic.cs index e9f89ac..e0279ce 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/InteractionDiagramLogic.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/InteractionDiagramLogic.cs @@ -5,6 +5,7 @@ using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Parameters; using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Services.Units; @@ -40,6 +41,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu public Action SetProgress { get; set; } public bool Result { get; set; } + public ITraceLogger? TraceLogger { get; set; } public InteractionDiagramLogic(LimitCurveInputData inputData) { @@ -57,8 +59,9 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu var convertLogic = InputData.SurroundData.ConvertLogicEntity; var calculator = new LimitCurvesCalculator() { - InputData = InputData + InputData = InputData, }; + if (TraceLogger is not null) { calculator.TraceLogger = TraceLogger; } calculator.ActionToOutputResults = SetProgressByResult; SafetyProcessor.RunSafeProcess(() => { diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs index 3d146d9..0ea4440 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs @@ -3,6 +3,7 @@ using StructureHelper.Windows.ViewModels.Errors; using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Settings; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Parameters; using StructureHelperCommon.Services.Units; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; @@ -27,6 +28,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu public Action SetProgress { get; set; } public bool Result { get; set; } + public ITraceLogger? TraceLogger { get; set; } public void WorkerDoWork(object sender, DoWorkEventArgs e) { diff --git a/StructureHelper/Windows/ViewModels/NdmCrossSections/AnalysisVewModelLogic.cs b/StructureHelper/Windows/ViewModels/NdmCrossSections/AnalysisVewModelLogic.cs index 699bba1..572355c 100644 --- a/StructureHelper/Windows/ViewModels/NdmCrossSections/AnalysisVewModelLogic.cs +++ b/StructureHelper/Windows/ViewModels/NdmCrossSections/AnalysisVewModelLogic.cs @@ -6,6 +6,7 @@ using StructureHelper.Windows.ViewModels.Calculations.Calculators; using StructureHelper.Windows.ViewModels.Errors; using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve; @@ -33,7 +34,8 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections { NewItem = new ForceCalculator() { - Name = "New force calculator" + Name = "New force calculator", + TraceLogger = new TraceLogger(), }; } else if (parameterType == CalculatorTypes.LimitCurveCalculator) @@ -42,7 +44,8 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections NewItem = new LimitCurvesCalculator() { Name = "New interaction diagram calculator", - InputData = inputData + InputData = inputData, + TraceLogger = new TraceLogger(), }; } else @@ -133,7 +136,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections { var calculator = SelectedItem as LimitCurvesCalculator; var inputData = calculator.InputData; - ShowInteractionDiagramByInputData(inputData); + ShowInteractionDiagramByInputData(calculator); } else { @@ -151,9 +154,10 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections } } - private void ShowInteractionDiagramByInputData(LimitCurveInputData inputData) + private void ShowInteractionDiagramByInputData(LimitCurvesCalculator calculator) { - interactionDiagramLogic = new(inputData); + interactionDiagramLogic = new(calculator.InputData); + interactionDiagramLogic.TraceLogger = calculator.TraceLogger; showProgressLogic = new(interactionDiagramLogic) { WindowTitle = "Diagram creating...", diff --git a/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs b/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs index 72ecb43..0cebe7b 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs @@ -1,4 +1,5 @@ using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using System; using System.Collections.Generic; using System.ComponentModel; @@ -15,6 +16,8 @@ namespace StructureHelperCommon.Infrastructures.Interfaces Action SetProgress { get; set; } bool Result { get; set; } + ITraceLogger? TraceLogger { get; set; } + void WorkerDoWork(object sender, DoWorkEventArgs e); void WorkerProgressChanged(object sender, ProgressChangedEventArgs e); void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e); diff --git a/StructureHelperCommon/Models/Calculators/FindParameterCalculator.cs b/StructureHelperCommon/Models/Calculators/FindParameterCalculator.cs index 3e95289..f23db89 100644 --- a/StructureHelperCommon/Models/Calculators/FindParameterCalculator.cs +++ b/StructureHelperCommon/Models/Calculators/FindParameterCalculator.cs @@ -1,4 +1,5 @@ using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Models.Loggers; using System; using System.Collections.Generic; using System.Diagnostics; @@ -19,6 +20,7 @@ namespace StructureHelperCommon.Models.Calculators public IResult Result => result; public Action ActionToOutputResults { get; set; } + public ITraceLogger? TraceLogger { get; set; } public FindParameterCalculator() { @@ -58,6 +60,7 @@ namespace StructureHelperCommon.Models.Calculators int iterationNum = 0; while (step > precision) { + TraceLogger?.AddMessage($"Iteration number {iterationNum}", TraceLoggerStatuses.Debug); if (predicate(current) == true) { end = current; @@ -66,8 +69,8 @@ namespace StructureHelperCommon.Models.Calculators { start = current; } - current = (start + end) / 2; + TraceLogger?.AddMessage($"Current value {current}", TraceLoggerStatuses.Debug); step = (end - start) / 2; iterationNum++; @@ -78,11 +81,12 @@ namespace StructureHelperCommon.Models.Calculators if (iterationNum > maxIterationCount) { + TraceLogger?.AddMessage($"Recuired precision was not achieved, current step {step}, required precision {precision}", TraceLoggerStatuses.Error); result.Description = "Parameter was not found succefully: \n"; throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": violation of iteration count"); } } - + TraceLogger?.AddMessage($"Parameter value {current} was obtained"); result.Parameter = current; result.Description = "Parameter was found succefully"; result.IsValid = true; diff --git a/StructureHelperCommon/Models/Calculators/ICalculator.cs b/StructureHelperCommon/Models/Calculators/ICalculator.cs index 25b9b9f..9376164 100644 --- a/StructureHelperCommon/Models/Calculators/ICalculator.cs +++ b/StructureHelperCommon/Models/Calculators/ICalculator.cs @@ -1,4 +1,5 @@ using LoaderCalculator.Data.ResultData; +using StructureHelperCommon.Models.Loggers; using System; using System.Collections.Generic; using System.Linq; @@ -11,6 +12,7 @@ namespace StructureHelperCommon.Models.Calculators { public interface ICalculator : ICloneable { + ITraceLogger? TraceLogger { get; set; } string Name { get; set; } /// /// Method for calculating diff --git a/StructureHelperCommon/Models/Loggers/ILogger.cs b/StructureHelperCommon/Models/Loggers/ILogger.cs new file mode 100644 index 0000000..2af24d5 --- /dev/null +++ b/StructureHelperCommon/Models/Loggers/ILogger.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Loggers +{ + public interface ILogger + { + void Fatal(string message); + } +} diff --git a/StructureHelperCommon/Models/Loggers/ITraceLogger.cs b/StructureHelperCommon/Models/Loggers/ITraceLogger.cs new file mode 100644 index 0000000..d54135d --- /dev/null +++ b/StructureHelperCommon/Models/Loggers/ITraceLogger.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Loggers +{ + public interface ITraceLogger + { + List TraceLoggerEntries { get; } + void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info); + } +} diff --git a/StructureHelperCommon/Models/Loggers/ITraceLoggerEntry.cs b/StructureHelperCommon/Models/Loggers/ITraceLoggerEntry.cs new file mode 100644 index 0000000..7342376 --- /dev/null +++ b/StructureHelperCommon/Models/Loggers/ITraceLoggerEntry.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Loggers +{ + public interface ITraceLoggerEntry + { + DateTime TimeStamp { get;} + int Priority { get; set; } + } +} diff --git a/StructureHelperCommon/Models/Loggers/StringLoggerEntry.cs b/StructureHelperCommon/Models/Loggers/StringLoggerEntry.cs new file mode 100644 index 0000000..ba1b484 --- /dev/null +++ b/StructureHelperCommon/Models/Loggers/StringLoggerEntry.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Loggers +{ + public class StringLoggerEntry : ITraceLoggerEntry + { + public DateTime TimeStamp { get;} + public string Message { get; set; } + public int Priority { get; set; } + + public StringLoggerEntry() + { + TimeStamp = DateTime.Now; + } + } +} diff --git a/StructureHelperCommon/Models/Loggers/TraceLogger.cs b/StructureHelperCommon/Models/Loggers/TraceLogger.cs new file mode 100644 index 0000000..0bcb5f7 --- /dev/null +++ b/StructureHelperCommon/Models/Loggers/TraceLogger.cs @@ -0,0 +1,57 @@ +using StructureHelperCommon.Infrastructures.Exceptions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Loggers +{ + public class TraceLogger : ITraceLogger + { + const int fatal = 0; + const int error = 1000; + const int warning = 200; + const int info = 300; + const int service = 400; + const int debug = 500; + + public List TraceLoggerEntries { get; } + + public TraceLogger() + { + TraceLoggerEntries = new(); + } + + public void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info) + { + TraceLoggerEntries.Add(new StringLoggerEntry() + { + Message = message, + Priority = GetPriorityByStatus(status) + }); + } + public void AddMessage(string message, int priority) + { + TraceLoggerEntries.Add(new StringLoggerEntry() + { + Message = message, + Priority = priority + }); + } + + public static int GetPriorityByStatus(TraceLoggerStatuses status) + { + if (status == TraceLoggerStatuses.Fatal) { return fatal; } + else if (status == TraceLoggerStatuses.Error) { return error; } + else if (status == TraceLoggerStatuses.Warning) { return warning; } + else if (status == TraceLoggerStatuses.Info) { return info; } + else if (status == TraceLoggerStatuses.Service) { return service; } + else if (status == TraceLoggerStatuses.Debug) { return debug; } + else + { + throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(status)); + } + } + } +} diff --git a/StructureHelperCommon/Models/Loggers/TraceLoggerStatuses.cs b/StructureHelperCommon/Models/Loggers/TraceLoggerStatuses.cs new file mode 100644 index 0000000..28aebbc --- /dev/null +++ b/StructureHelperCommon/Models/Loggers/TraceLoggerStatuses.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Loggers +{ + public enum TraceLoggerStatuses + { + Fatal, + Error, + Warning, + Info, + Service, + Debug + } +} diff --git a/StructureHelperCommon/Models/Soils/AnchorCalculator.cs b/StructureHelperCommon/Models/Soils/AnchorCalculator.cs index 088cb3b..36d981d 100644 --- a/StructureHelperCommon/Models/Soils/AnchorCalculator.cs +++ b/StructureHelperCommon/Models/Soils/AnchorCalculator.cs @@ -1,5 +1,6 @@ using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using System; using System.Collections.Generic; using System.Linq; @@ -20,6 +21,7 @@ namespace StructureHelperCommon.Models.Soils public IResult Result => result; public Action ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public AnchorCalculator(SoilAnchor soilAnchor, IAnchorSoilProperties anchorSoilProperties) { diff --git a/StructureHelperCommon/StructureHelperCommon.csproj b/StructureHelperCommon/StructureHelperCommon.csproj index 99d72f0..13638e5 100644 --- a/StructureHelperCommon/StructureHelperCommon.csproj +++ b/StructureHelperCommon/StructureHelperCommon.csproj @@ -9,6 +9,10 @@ false + + + + ..\StructureHelper\Libraries\LoaderCalculator.dll diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculator.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculator.cs index 6170f80..35df9b6 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculator.cs @@ -2,6 +2,7 @@ using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Sections; using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Services.Forces; @@ -25,6 +26,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces public IAccuracy Accuracy { get; set; } public List ForceCombinationLists { get; private set; } public Action ActionToOutputResults { get; set; } + public ITraceLogger? TraceLogger { get; set; } public void Run() { diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceTupleCalculator.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceTupleCalculator.cs index 9b31605..0a531c7 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceTupleCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceTupleCalculator.cs @@ -3,6 +3,7 @@ using LoaderCalculator.Data.Matrix; using LoaderCalculator.Data.ResultData; using LoaderCalculator.Data.SourceData; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces { @@ -13,6 +14,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces public IResult Result { get; private set; } public Action ActionToOutputResults { get; set; } + public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public ForceTupleCalculator(IForceTupleInputData inputData) { diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/GetPredicateLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/GetPredicateLogic.cs index a9419a3..c22de18 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/GetPredicateLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/GetPredicateLogic.cs @@ -1,5 +1,6 @@ using LoaderCalculator.Data.Ndms; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using System; using System.Collections.Generic; @@ -14,6 +15,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Fac public IEnumerable Ndms { get; set; } public PredicateTypes PredicateType { get; set; } public IConvert2DPointTo3DPointLogic ConvertLogic { get; set; } + public string Name { get; set; } + public ITraceLogger? TraceLogger { get; set; } public Predicate GetPredicate() { diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/IGetPredicateLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/IGetPredicateLogic.cs index 3bab380..331982c 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/IGetPredicateLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/Factories/IGetPredicateLogic.cs @@ -1,9 +1,12 @@ -using StructureHelperCommon.Models.Shapes; +using StructureHelperCommon.Models.Loggers; +using StructureHelperCommon.Models.Shapes; namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Factories { public interface IGetPredicateLogic { + string Name { get; set; } Predicate GetPredicate(); + ITraceLogger? TraceLogger { get; set; } } } \ No newline at end of file diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/ILimitCurveLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/ILimitCurveLogic.cs index 2eebeb6..219f219 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/ILimitCurveLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/ILimitCurveLogic.cs @@ -1,4 +1,5 @@ using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using System; using System.Collections.Generic; @@ -22,5 +23,6 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces /// /// List GetPoints(IEnumerable points); + ITraceLogger? TraceLogger { get; set; } } } diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/ILimitCurveParameterLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/ILimitCurveParameterLogic.cs index e1b6603..6fbd306 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/ILimitCurveParameterLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/ILimitCurveParameterLogic.cs @@ -1,4 +1,5 @@ using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using System; using System.Collections.Generic; @@ -8,10 +9,14 @@ using System.Threading.Tasks; namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces { + /// + /// Find parameter by point and predicate + /// public interface ILimitCurveParameterLogic : IHasActionByResult, ICloneable { Predicate LimitPredicate { get; set; } IPoint2D CurrentPoint { get; set; } double GetParameter(); + ITraceLogger? TraceLogger { get; set; } } } diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveCalculator.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveCalculator.cs index 5e5ef24..9daa629 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveCalculator.cs @@ -1,5 +1,6 @@ using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using System; using System.Collections.Generic; @@ -25,6 +26,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces public IResult Result => result; public Action ActionToOutputResults { get; set; } + public ITraceLogger? TraceLogger { get; set; } public LimitCurveCalculator(ILimitCurveLogic limitCurveLogic) { @@ -45,20 +47,27 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces public void Run() { + if (TraceLogger is not null) { limitCurveLogic.TraceLogger = TraceLogger; } + TraceLogger?.AddMessage($"Calculator type: {GetType()}", TraceLoggerStatuses.Service); + TraceLogger?.AddMessage($"Start solution in calculator {Name}"); result = new LimitCurveResult(); result.IsValid = true; result.Name = Name; SurroundProcLogic.SurroundData = SurroundData; SurroundProcLogic.PointCount = PointCount; + TraceLogger?.AddMessage($"Point count {PointCount}"); surroundList = SurroundProcLogic.GetPoints(); + TraceLogger?.AddMessage($"There are {surroundList.Count()} point prepared for calculation"); try { limitCurveLogic.ActionToOutputResults = GetCurrentStepNumber; factoredList = limitCurveLogic.GetPoints(surroundList); + TraceLogger?.AddMessage($"Solution was successfully obtained for {factoredList.Count()} point"); result.Points = factoredList; } catch (Exception ex) { + TraceLogger?.AddMessage($"Calculation result is not valid: {ex.Message}", TraceLoggerStatuses.Error); result.IsValid = false; result.Description += ex.Message; } diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveLogic.cs index 240d21f..a73edfe 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveLogic.cs @@ -1,4 +1,5 @@ using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Factories; @@ -17,6 +18,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces private object lockObject = new object(); public Action ActionToOutputResults { get; set; } + public ITraceLogger? TraceLogger { get; set; } public LimitCurveLogic(ILimitCurveParameterLogic parameterLogic) { @@ -30,22 +32,25 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces /// public List GetPoints(IEnumerable points) { + if (TraceLogger is not null) { ParameterLogic.TraceLogger = TraceLogger; } result = new(); resultList = new(); + TraceLogger?.AddMessage($"Predicate name is {GetPredicateLogic.Name}"); Predicate limitPredicate = GetPredicateLogic.GetPredicate(); + //if predicate is true for point (0,0), then check other point is pointless if (limitPredicate(new Point2D()) == true) { - var range = points.Select(point => new Point2D { X = point.X * 0d, Y = point.Y * 0d }).ToList(); + TraceLogger?.AddMessage($"Predicate is true for point (0d, 0d). All point will be skiped", TraceLoggerStatuses.Warning); + var range = points.Select(point => new Point2D { X = 0d, Y = 0d }).ToList(); resultList.AddRange(range); return resultList; } pointCount = 0; - MultyThreadProc(points); - //MonoThreadProc(points); + MultiThreadProc(points); return resultList; } - private void MultyThreadProc(IEnumerable points) + private void MultiThreadProc(IEnumerable points) { Task[] tasks = new Task[points.Count()]; for (int i = 0; i < points.Count(); i++) @@ -63,53 +68,14 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces } } - private void MonoThreadProc(IEnumerable points) - { - foreach (var point in points) - { - FindParameter(point); - } - } - - private void FindParameter(IPoint2D point) - { - IPoint2D resultPoint = FindResultPoint(point); - resultList.Add(resultPoint); - lock (lockObject) - { - pointCount++; - } - result.IterationNumber = pointCount; - ActionToOutputResults?.Invoke(result); - } - private Point2D FindResultPoint(IPoint2D point) { - double parameter; - var locCurrentPoint = point.Clone() as IPoint2D; Predicate limitPredicate; lock (lockObject) { limitPredicate = GetPredicateLogic.GetPredicate(); } - var logic = ParameterLogic.Clone() as ILimitCurveParameterLogic; - logic.CurrentPoint = locCurrentPoint; - logic.LimitPredicate = limitPredicate; - - if (limitPredicate(locCurrentPoint) == false) - { - parameter = 1d; - } - else - { - parameter = logic.GetParameter(); - } - - var resultPoint = new Point2D() - { - X = locCurrentPoint.X * parameter, - Y = locCurrentPoint.Y * parameter - }; + var resultPoint = FindResultPointByPredicate(point, limitPredicate); lock (lockObject) { pointCount++; @@ -117,7 +83,39 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces result.IterationNumber = pointCount; ActionToOutputResults?.Invoke(result); return resultPoint; - //} + } + + private Point2D FindResultPointByPredicate(IPoint2D point, Predicate limitPredicate) + { + var localCurrentPoint = point.Clone() as IPoint2D; + var logic = ParameterLogic.Clone() as ILimitCurveParameterLogic; + logic.TraceLogger = new TraceLogger(); + logic.CurrentPoint = localCurrentPoint; + logic.LimitPredicate = limitPredicate; + double parameter; + + if (limitPredicate(localCurrentPoint) == false) + { + parameter = 1d; + } + else + { + parameter = logic.GetParameter(); + } + + var resultPoint = new Point2D() + { + X = localCurrentPoint.X * parameter, + Y = localCurrentPoint.Y * parameter + }; + lock (lockObject) + { + TraceLogger?.AddMessage($"Source point (X = {localCurrentPoint.X}, Y = {localCurrentPoint.Y})"); + TraceLogger?.TraceLoggerEntries.AddRange(logic.TraceLogger.TraceLoggerEntries); + TraceLogger?.AddMessage($"Parameter value {parameter} was obtained"); + TraceLogger?.AddMessage($"Calculated point (X={localCurrentPoint.X} * {parameter} = {resultPoint.X}, Y={localCurrentPoint.Y} * {parameter} = {resultPoint.Y})"); + } + return resultPoint; } } } diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveParameterLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveParameterLogic.cs index 7ca9727..9b409ee 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveParameterLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurveParameterLogic.cs @@ -1,5 +1,6 @@ using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using System; using System.Collections.Generic; @@ -15,6 +16,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces public Predicate LimitPredicate { get; set; } public IPoint2D CurrentPoint { get; set; } public Action ActionToOutputResults { get; set; } + public ITraceLogger? TraceLogger { get; set; } public LimitCurveParameterLogic() { @@ -27,6 +29,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces { Predicate = GetFactorPredicate, }; + if (TraceLogger is not null) { parameterCalculator.TraceLogger = TraceLogger; } parameterCalculator.Accuracy.IterationAccuracy = 0.001d; parameterCalculator.Run(); if (parameterCalculator.Result.IsValid == false) diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurvesCalculator.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurvesCalculator.cs index 709041d..761c093 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurvesCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/LimitCurvesCalculator.cs @@ -1,6 +1,7 @@ using LoaderCalculator.Data.Ndms; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.Models.Calculations.CalculationsResults; using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Factories; @@ -29,6 +30,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces public IResult Result => result; public Action ActionToOutputResults { get; set; } + public ITraceLogger? TraceLogger { get; set; } + public LimitCurvesCalculator() { Name = "New calculator"; @@ -36,6 +39,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces } public void Run() { + TraceLogger?.AddMessage($"Calculator type: {GetType()}", TraceLoggerStatuses.Service); + TraceLogger?.AddMessage($"Start solution in calculator {Name}"); GetNewResult(); try { @@ -46,7 +51,10 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces item.Run(); var locResult = item.Result as LimitCurveResult; result.LimitCurveResults.Add(locResult); - if (locResult.IsValid == false) { result.Description += locResult.Description; } + if (locResult.IsValid == false) + { + result.Description += locResult.Description; + } result.IterationNumber = curvesIterationCount * InputData.PointCount + locResult.IterationNumber; ActionToOutputResults?.Invoke(result); curvesIterationCount++; @@ -54,6 +62,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces } catch (Exception ex) { + TraceLogger?.AddMessage($"Calculation result is not valid: {ex.Message}", TraceLoggerStatuses.Error); result.IsValid = false; result.Description += ex; } @@ -81,6 +90,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces { string calcName = $"{primitiveSeries.Name}_{predicateEntry.Name}_{limitState}_{calcTerm}"; LimitCurveCalculator calculator = GetCalculator(ndms, predicateEntry.PredicateType, calcName); + if (TraceLogger is not null) { calculator.TraceLogger = TraceLogger; } calculators.Add(calculator); } } @@ -91,18 +101,14 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces private LimitCurveCalculator GetCalculator(List ndms, PredicateTypes predicateType, string calcName) { - var factory = new PredicateFactory() - { - Ndms = ndms, - ConvertLogic = InputData.SurroundData.ConvertLogicEntity.ConvertLogic - }; - var predicate = factory.GetPredicate(predicateType); var getPredicateLogic = new GetPredicateLogic() { + Name = calcName, Ndms = ndms, ConvertLogic = InputData.SurroundData.ConvertLogicEntity.ConvertLogic, PredicateType = predicateType }; + if (TraceLogger is not null) { getPredicateLogic.TraceLogger = TraceLogger; } var logic = new LimitCurveLogic(getPredicateLogic); var calculator = new LimitCurveCalculator(logic) { diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/StabLimitCurveLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/StabLimitCurveLogic.cs index 32ac6a9..1a6defe 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/StabLimitCurveLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/LimitCurve/StabLimitCurveLogic.cs @@ -1,4 +1,5 @@ using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using System; using System.Collections.Generic; @@ -11,6 +12,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces public class StabLimitCurveLogic : ILimitCurveLogic { public Action ActionToOutputResults { get; set; } + public ITraceLogger? TraceLogger { get; set; } public List GetPoints(IEnumerable points) { diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/Logics/InterpolationProgressLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/Logics/InterpolationProgressLogic.cs index 6ea9342..8313ace 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/Logics/InterpolationProgressLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/Logics/InterpolationProgressLogic.cs @@ -1,6 +1,7 @@ using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Loggers; using StructureHelperLogics.Services.NdmCalculations; using System; using System.Collections.Generic; @@ -23,6 +24,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.Logics public int StepCount => interpolateTuplesResult.StepCount + 1; + public ITraceLogger? TraceLogger { get; set; } + public void WorkerDoWork(object sender, DoWorkEventArgs e) { InterpolateCalculator = InterpolateService.InterpolateForceCalculator(forceCalculator, interpolateTuplesResult); diff --git a/StructureHelperLogics/NdmCalculations/Analyses/Geometry/GeometryCalculator.cs b/StructureHelperLogics/NdmCalculations/Analyses/Geometry/GeometryCalculator.cs index c1e70b1..d4bac37 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/Geometry/GeometryCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/Geometry/GeometryCalculator.cs @@ -1,6 +1,7 @@ using LoaderCalculator.Data.Matrix; using LoaderCalculator.Data.Ndms; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using StructureHelperLogics.Services.NdmPrimitives; using System; using System.Collections.Generic; @@ -19,6 +20,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.Geometry public IResult Result => geometryResult; public Action ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public GeometryCalculator(IEnumerable ndms, IStrainMatrix strainMatrix) { diff --git a/StructureHelperLogics/NdmCalculations/Buckling/ConcreteBucklingCalculator.cs b/StructureHelperLogics/NdmCalculations/Buckling/ConcreteBucklingCalculator.cs index 1064f8e..46267a1 100644 --- a/StructureHelperLogics/NdmCalculations/Buckling/ConcreteBucklingCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Buckling/ConcreteBucklingCalculator.cs @@ -3,6 +3,7 @@ using LoaderCalculator.Logics; using LoaderCalculator.Logics.Geometry; using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.Models.Materials; using StructureHelperLogics.NdmCalculations.Analyses; @@ -28,6 +29,7 @@ namespace StructureHelperLogics.NdmCalculations.Buckling public IAccuracy Accuracy { get; set; } public Action ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } private (double EtaAlongX, double EtaAlongY) GetBucklingCoefficients() { diff --git a/StructureHelperLogics/NdmCalculations/Cracking/CrackForceCalculator.cs b/StructureHelperLogics/NdmCalculations/Cracking/CrackForceCalculator.cs index b4889de..b65ff4c 100644 --- a/StructureHelperLogics/NdmCalculations/Cracking/CrackForceCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Cracking/CrackForceCalculator.cs @@ -2,6 +2,7 @@ using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Services; using StructureHelperCommon.Services.Forces; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; @@ -30,6 +31,8 @@ namespace StructureHelperLogics.NdmCalculations.Cracking public Accuracy Accuracy {get;set; } public IResult Result => result; + public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public CrackForceCalculator(IForceTupleCalculator forceTupleCalculator) { StartTuple ??= new ForceTuple(); diff --git a/StructureHelperLogics/NdmCalculations/Cracking/CrackWidthCalculator.cs b/StructureHelperLogics/NdmCalculations/Cracking/CrackWidthCalculator.cs index cce5d48..bde2a20 100644 --- a/StructureHelperLogics/NdmCalculations/Cracking/CrackWidthCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Cracking/CrackWidthCalculator.cs @@ -2,6 +2,7 @@ using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Services.Forces; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Primitives; @@ -24,6 +25,8 @@ namespace StructureHelperLogics.NdmCalculations.Cracking public CrackWidthCalculatorInputData InputData { get; set; } public IResult Result => result; + public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public void Run() { result = new() { IsValid = true, Description = ""}; diff --git a/StructureHelperLogics/NdmCalculations/Cracking/CrackWidthSimpleCalculator.cs b/StructureHelperLogics/NdmCalculations/Cracking/CrackWidthSimpleCalculator.cs index 24b503a..0903afd 100644 --- a/StructureHelperLogics/NdmCalculations/Cracking/CrackWidthSimpleCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Cracking/CrackWidthSimpleCalculator.cs @@ -1,4 +1,5 @@ using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Loggers; using System; using System.Collections.Generic; using System.Linq; @@ -16,6 +17,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking public IResult Result => result; public Action ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public void Run() { diff --git a/StructureHelperTests/UnitTests/Calcuators/LimitCurveCalculatorTest.cs b/StructureHelperTests/UnitTests/Calcuators/LimitCurveCalculatorTest.cs index 62fa90f..7ce50d8 100644 --- a/StructureHelperTests/UnitTests/Calcuators/LimitCurveCalculatorTest.cs +++ b/StructureHelperTests/UnitTests/Calcuators/LimitCurveCalculatorTest.cs @@ -16,6 +16,7 @@ namespace StructureHelperTests.UnitTests.Calcuators var calculator = new LimitCurveCalculator(new StabLimitCurveLogic()) { }; + calculator.PointCount = 12; calculator.SurroundData.XMax = xmax; calculator.SurroundData.XMin = -xmax; calculator.SurroundData.YMax = ymax; diff --git a/StructureHelperTests/UnitTests/Calcuators/LimitCurveLogicTest.cs b/StructureHelperTests/UnitTests/Calcuators/LimitCurveLogicTest.cs index d8c294a..13d0ede 100644 --- a/StructureHelperTests/UnitTests/Calcuators/LimitCurveLogicTest.cs +++ b/StructureHelperTests/UnitTests/Calcuators/LimitCurveLogicTest.cs @@ -14,9 +14,6 @@ namespace StructureHelperTests.UnitTests.Calcuators public void GetPoints_ValidPoints_ReturnsTransformedPoints() { // Arrange - var parameterLogicMock = new Mock(); - parameterLogicMock.Setup(p => p.GetParameter()).Returns(2.0); // Mocking the GetParameter method - var getPredicateLogic = new Mock(); getPredicateLogic.Setup(p => p.GetPredicate()).Returns(point => point.X >= 0.5d);// @@ -39,34 +36,9 @@ namespace StructureHelperTests.UnitTests.Calcuators for (int i = 0; i < inputPoints.Count; i++) { - Assert.AreEqual(inputPoints[i].X * 0.5, result[i].X); - Assert.AreEqual(inputPoints[i].Y * 0.5, result[i].Y); + Assert.AreEqual(0.5d, result[i].X, 0.01d); + Assert.AreEqual(inputPoints[i].Y / inputPoints[i].X * 0.5d, result[i].Y, 0.01d); } - - // Verify that GetParameter was called - parameterLogicMock.Verify(p => p.GetParameter(), Times.Exactly(inputPoints.Count)); - } - - [Test] - public void GetPoints_InvalidPredicate_ThrowsException() - { - // Arrange - var parameterLogicMock = new Mock(); - parameterLogicMock.Setup(p => p.GetParameter()).Returns(2.0); - - var getPredicateLogic = new Mock(); - getPredicateLogic.Setup(p => p.GetPredicate()).Returns(point => point.X >= 0.5d);// - - var limitCurveLogic = new LimitCurveLogic(getPredicateLogic.Object); - - var inputPoints = new List - { - new Point2D { X = 1, Y = 2 }, - new Point2D { X = 3, Y = 4 } - }; - - // Act & Assert - Assert.Throws(() => limitCurveLogic.GetPoints(inputPoints)); } } }