From 06d289711c2831a316a4d56e9359d9b171cf8638 Mon Sep 17 00:00:00 2001 From: hayakawa Date: Fri, 1 Mar 2024 15:17:02 -0800 Subject: [PATCH] Added more unit tests in ForwardSolverViewModelTest and cleaned up comments in PlotViewModel. --- .../Panels/ForwardSolverViewModelTests.cs | 98 ++++++++++++++++++- Vts.Gui.Wpf/ViewModel/Panels/PlotViewModel.cs | 7 +- 2 files changed, 96 insertions(+), 9 deletions(-) diff --git a/Vts.Gui.Wpf.Test/ViewModel/Panels/ForwardSolverViewModelTests.cs b/Vts.Gui.Wpf.Test/ViewModel/Panels/ForwardSolverViewModelTests.cs index bd6dbcb..9aff00c 100644 --- a/Vts.Gui.Wpf.Test/ViewModel/Panels/ForwardSolverViewModelTests.cs +++ b/Vts.Gui.Wpf.Test/ViewModel/Panels/ForwardSolverViewModelTests.cs @@ -15,7 +15,7 @@ public class ForwardSolverViewModelTests /// Verifies that ForwardSolverViewModel default constructor instantiates sub viewmodels /// [Test] - public void verify_default_constructor_sets_properties_correctly() + public void Verify_default_constructor_sets_properties_correctly() { // WindowViewModel needs to be instantiated for default constructor var windowViewModel = new WindowViewModel(); @@ -67,11 +67,100 @@ public void Verify_ExecuteForwardSolverCommand_returns_correct_values() Assert.AreEqual(s1, textOutputViewModel.Text); } + /// + /// Verifies that ForwardSolverViewModel returns correct multi-region tissue values + /// + [Test] + public void Verify_ExecuteForwardSolverCommand_multi_region_tissue_returns_correct_values() + { + // WindowViewModel needs to be instantiated for default constructor + var windowViewModel = new WindowViewModel(); + var viewModel = windowViewModel.ForwardSolverVM; + viewModel.ForwardSolverTypeOptionVM.SelectedValue = ForwardSolverType.TwoLayerSDA; + viewModel.SolutionDomainTypeOptionVM.SelectedValue = SolutionDomainType.ROfFx; + viewModel.ForwardAnalysisTypeOptionVM.SelectedValue = ForwardAnalysisType.R; + viewModel.ExecuteForwardSolverCommand.Execute(null); + var plotViewModel = windowViewModel.PlotVM; + const int i1 = 1; + const double d2 = 0.0100; + // s1 should be "Plot View: plot cleared due to independent axis variable change + // Forward Solver: Vts.Gui.Wpf.ViewModel.MultiRegionTissueViewModel" + var s1 = StringLookup.GetLocalizedString("Message_PlotViewCleared") + "\r" + + StringLookup.GetLocalizedString("Label_ForwardSolver") + + "Vts.Gui.Wpf.ViewModel.MultiRegionTissueViewModel\r"; + // s2 should be "R(ρ) [Unitless] versus fx [1/mm]" + var s2 = StringLookup.GetLocalizedString("Label_ROfRho") + " [Unitless] " + + StringLookup.GetLocalizedString("Label_Versus") + " fx [1/mm]"; + // s3 should be "Model - 2 layer SDA\rμa1 = 0.0100\rμs'1=1.0000\rμa2 = 0.0100\r μs'2=1.0000" + var s3 = "\r" + StringLookup.GetLocalizedString("Label_Model2LayerSDA") + "\r" + + StringLookup.GetLocalizedString("Label_MuA1") + "=" + + d2.ToString("N4", CultureInfo.CurrentCulture) + "\r" + + StringLookup.GetLocalizedString("Label_MuSPrime1") + "=" + + i1.ToString("N4", CultureInfo.CurrentCulture) + "\r" + + StringLookup.GetLocalizedString("Label_MuA2") + "=" + + d2.ToString("N4", CultureInfo.CurrentCulture) + "\r" + + StringLookup.GetLocalizedString("Label_MuSPrime2") + "=" + + i1.ToString("N4", CultureInfo.CurrentCulture); + Assert.AreEqual(s3, plotViewModel.Labels[0]); + Assert.AreEqual(s2, plotViewModel.Title); + var textOutputViewModel = windowViewModel.TextOutputVM; + Assert.AreEqual(s1, textOutputViewModel.Text); + } + + /// + /// Verifies that ForwardSolverViewModel returns correct complex derivative values + /// + [Test] + public void Verify_ExecuteForwardSolverCommand_complex_derivative_returns_correct_values() + { + // WindowViewModel needs to be instantiated for default constructor + var windowViewModel = new WindowViewModel(); + var viewModel = windowViewModel.ForwardSolverVM; + viewModel.ForwardSolverTypeOptionVM.SelectedValue = ForwardSolverType.MonteCarlo; + viewModel.SolutionDomainTypeOptionVM.SelectedValue = SolutionDomainType.ROfFxAndFt; + viewModel.ForwardAnalysisTypeOptionVM.SelectedValue = ForwardAnalysisType.dRdMua; + viewModel.ExecuteForwardSolverCommand.Execute(null); + var plotViewModel = windowViewModel.PlotVM; + const double d1 = 0.01; + const int i1 = 1; + const double g = 0.8; + const double n = 1.4; + const double d2 = 0.0100; + const double d3 = 1.0000; + const double d4 = 0; + // s1 should be "Plot View: plot cleared due to independent axis variable change + // Forward Solver: μa = 0.01 μs'=1 g=0.8 n=1.4; Units = 1/mm" + var s1 = StringLookup.GetLocalizedString("Message_PlotViewCleared") + "\r" + + StringLookup.GetLocalizedString("Label_ForwardSolver") + + StringLookup.GetLocalizedString("Label_MuA") + "=" + + d1.ToString(CultureInfo.CurrentCulture) + " " + + StringLookup.GetLocalizedString("Label_MuSPrime") + "=" + + i1.ToString(CultureInfo.CurrentCulture) + " g=" + + g.ToString(CultureInfo.CurrentCulture) + " n=" + + n.ToString(CultureInfo.CurrentCulture) + "; " + + StringLookup.GetLocalizedString("Label_Units") + " = 1/mm\r"; + // s2 should be "R(ρ) [GHz-1] versus fx [1/mm]" + var s2 = StringLookup.GetLocalizedString("Label_ROfRho") + " [GHz-1] " + + StringLookup.GetLocalizedString("Label_Versus") + " fx [1/mm]"; + // "ft" is not in Strings.resx + var s3 = "\r" + StringLookup.GetLocalizedString("Label_ModelScaledMC") + "\r" + + StringLookup.GetLocalizedString("Label_MuA") + "=" + + d2.ToString("N4", CultureInfo.CurrentCulture) + " \r" + + StringLookup.GetLocalizedString("Label_MuSPrime") + "=" + + d3.ToString("N4", CultureInfo.CurrentCulture) + " \rft = " + + d4.ToString("N0", CultureInfo.CurrentCulture) + " " + + StringLookup.GetLocalizedString("Measurement_GHz"); + Assert.AreEqual(s3, plotViewModel.Labels[0]); + Assert.AreEqual(s2, plotViewModel.Title); + var textOutputViewModel = windowViewModel.TextOutputVM; + Assert.AreEqual(s1, textOutputViewModel.Text); + } + /// /// Verifies that ForwardSolverViewModel disallows spectral panel inputs for TwoLayerSDA selection /// [Test] - public void verify_TwoLayerSDA_selection_does_not_display_usespectralpanelinputs_checkbox() + public void Verify_TwoLayerSDA_selection_does_not_display_usespectralpanelinputs_checkbox() { // WindowViewModel needs to be instantiated for default constructor var windowViewModel = new WindowViewModel(); @@ -83,12 +172,13 @@ public void verify_TwoLayerSDA_selection_does_not_display_usespectralpanelinputs Assert.IsFalse(viewModel.SolutionDomainTypeOptionVM.EnableMultiAxis); Assert.IsFalse(viewModel.SolutionDomainTypeOptionVM.EnableSpectralPanelInputs); } + /// /// Verifies that ForwardSolverViewModel disallows time-dependent solution domain options /// for DistributedGaussianSourceSDA selection /// [Test] - public void verify_DistributedGaussianSourceSDA_selection_does_not_display_time_dependent_solution_domain_options() + public void Verify_DistributedGaussianSourceSDA_selection_does_not_display_time_dependent_solution_domain_options() { // WindowViewModel needs to be instantiated for default constructor var windowViewModel = new WindowViewModel(); @@ -101,5 +191,7 @@ public void verify_DistributedGaussianSourceSDA_selection_does_not_display_time_ Assert.IsFalse(viewModel.SolutionDomainTypeOptionVM.IsROfFxAndTimeEnabled); Assert.IsFalse(viewModel.SolutionDomainTypeOptionVM.IsROfFxAndFtEnabled); } + + } } diff --git a/Vts.Gui.Wpf/ViewModel/Panels/PlotViewModel.cs b/Vts.Gui.Wpf/ViewModel/Panels/PlotViewModel.cs index b7aa078..c7d6492 100644 --- a/Vts.Gui.Wpf/ViewModel/Panels/PlotViewModel.cs +++ b/Vts.Gui.Wpf/ViewModel/Panels/PlotViewModel.cs @@ -564,7 +564,7 @@ private void Plot_SetAxesLabels_Executed(object sender) if (sender is PlotAxesLabels labels) { _clearPlot = false; - // set CurrentIndependtVariableAxis prior to setting Title because property + // set CurrentIndependentVariableAxis prior to setting Title because property // might ClearPlot including Title if (CurrentIndependentVariableAxis != labels.IndependentAxis.AxisType) { @@ -1015,11 +1015,6 @@ private void GenerateComplexDerivativePlot(DataPointCollection dataPointCollecti { case PlotToggleType.Phase: y = -(dp.PhaseDerivative * (180 / Math.PI)); - //// force phase to be between 0 and 360 - //if (y < 0) - //{ - // y += 360; - //} switch (PlotNormalizationTypeOptionVm.SelectedValue) { case PlotNormalizationType.RelativeToCurve: