Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/42a inaccurate fdpm amplitude and phase derivative values with respect to mu a and mu s #54

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions Vts.Gui.Wpf.Test/Model/ComplexDerivativeDataPointTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System;
using System.Numerics;
using System.Threading;
using NUnit.Framework;
using Vts.Gui.Wpf.Model;

namespace Vts.Gui.Wpf.Test.Model
{
internal class ComplexDerivativeDataPointTests
{
/// <summary>
/// Verifies ComplexDerivativeDataPoint class sets correct values
/// </summary>
[Test]
public void Verify_ComplexDerivativeDataPoint_sets_correct_x_and_y_values()
{
var dataPoint = new ComplexDerivativeDataPoint(
0.1,
new Complex(0.2, 0.3),
new Complex(0.4, 0.5),
ForwardAnalysisType.dRdG);
Assert.AreEqual(0.1, dataPoint.X);
Assert.AreEqual(0.2,dataPoint.Y.Real);
Assert.AreEqual(0.3, dataPoint.Y.Imaginary);
Assert.AreEqual(0.4, dataPoint.Dy.Real);
Assert.AreEqual(0.5, dataPoint.Dy.Imaginary);
Assert.AreEqual(ForwardAnalysisType.dRdG, dataPoint.DerivativeVariable);

}

/// <summary>
/// Verifies ComplexDerivativeDataPoint Equals method works correctly
/// </summary>
[Test]
public void Verify_ComplexDerivativeDataPoint_equals_methods_work_correctly()
{
var dataPoint1 = new ComplexDerivativeDataPoint(
0.1,
new Complex(0.2, 0.3),
new Complex(0.4, 0.5),
ForwardAnalysisType.dRdN);
var dataPoint2 = new ComplexDerivativeDataPoint(
0.1,
new Complex(0.2, 0.4),
new Complex(0.4, 0.5),
ForwardAnalysisType.dRdN);
Assert.IsFalse(dataPoint1.Equals(dataPoint2));
var dataPoint3 = new ComplexDerivativeDataPoint(
0.1,
new Complex(0.2, 0.3),
new Complex(0.4, 0.5),
ForwardAnalysisType.dRdN);
Assert.IsTrue(dataPoint1.Equals(dataPoint3));
Assert.IsTrue(dataPoint1.Equals(dataPoint1, dataPoint3));
}

[Test]
public void Verify_to_string_value()
{
var dataPoint = new ComplexDerivativeDataPoint(
0.1,
new Complex(0.3, 0.1),
new Complex(0.4, 0.5),
ForwardAnalysisType.dRdMua);
var localizedString = $"{0.1.ToString(Thread.CurrentThread.CurrentCulture)}, (" +
$"{0.3.ToString(Thread.CurrentThread.CurrentCulture)}, " +
$"{0.1.ToString(Thread.CurrentThread.CurrentCulture)})";
Assert.AreEqual(localizedString, dataPoint.ToString());
}

[Test]
public void Verify_hash_code()
{
var dataPoint = new ComplexDerivativeDataPoint(
0.8,
new Complex(0.2, 0.5),
new Complex(0.3, 0.4),
ForwardAnalysisType.dRdMusp);
Assert.AreEqual(-1563642927, dataPoint.GetHashCode());
}

[Test]
public void Verify_hash_code_with_parameter()
{
var dataPoint1 = new ComplexDerivativeDataPoint(
0.8,
new Complex(0.2, 0.5),
new Complex(0.3, 0.6),
ForwardAnalysisType.dRdG);
var dataPoint2 = new ComplexDerivativeDataPoint(
0.8,
new Complex(0.9, 0.5),
new Complex(0.8, 0.7),
ForwardAnalysisType.dRdMusp);
Assert.IsNotNull(dataPoint1);
Assert.IsNotNull(dataPoint2);
Assert.AreEqual(867508351, dataPoint1.GetHashCode(dataPoint2));
}

[Test]
public void Verify_equals()
{
object dataPoint1 = new ComplexDerivativeDataPoint(
0.8,
new Complex(0.1, 0.2),
new Complex(0.3, 0.4),
ForwardAnalysisType.R);
object dataPoint2 = new ComplexDerivativeDataPoint(
0.8,
new Complex(0.1, 0.2),
new Complex(0.3, 0.4),
ForwardAnalysisType.R);
Assert.IsTrue(dataPoint1.Equals(dataPoint2));
}

[Test]
public void Verify_PhaseDerivative()
{
object dataPoint = new ComplexDerivativeDataPoint(
0.8,
new Complex(0.1, 0.2),
new Complex(0.3, 0.4),
ForwardAnalysisType.dRdMua);
var phaseDerivative = ((ComplexDerivativeDataPoint)dataPoint).PhaseDerivative;
Assert.IsTrue(Math.Abs(-0.399999 - phaseDerivative) < 1e-6);
}

[Test]
public void Verify_AmplitudeDerivative()
{
object dataPoint = new ComplexDerivativeDataPoint(
0.8,
new Complex(0.1, 0.2),
new Complex(0.3, 0.4),
ForwardAnalysisType.dRdMua);
var phaseDerivative = ((ComplexDerivativeDataPoint)dataPoint).AmplitudeDerivative;
Assert.IsTrue(Math.Abs(0.491934 - phaseDerivative) < 1e-6);
}
}
}
98 changes: 95 additions & 3 deletions Vts.Gui.Wpf.Test/ViewModel/Panels/ForwardSolverViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ForwardSolverViewModelTests
/// Verifies that ForwardSolverViewModel default constructor instantiates sub viewmodels
/// </summary>
[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();
Expand Down Expand Up @@ -67,11 +67,100 @@ public void Verify_ExecuteForwardSolverCommand_returns_correct_values()
Assert.AreEqual(s1, textOutputViewModel.Text);
}

/// <summary>
/// Verifies that ForwardSolverViewModel returns correct multi-region tissue values
/// </summary>
[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);
}

/// <summary>
/// Verifies that ForwardSolverViewModel returns correct complex derivative values
/// </summary>
[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);
}

/// <summary>
/// Verifies that ForwardSolverViewModel disallows spectral panel inputs for TwoLayerSDA selection
/// </summary>
[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();
Expand All @@ -83,12 +172,13 @@ public void verify_TwoLayerSDA_selection_does_not_display_usespectralpanelinputs
Assert.IsFalse(viewModel.SolutionDomainTypeOptionVM.EnableMultiAxis);
Assert.IsFalse(viewModel.SolutionDomainTypeOptionVM.EnableSpectralPanelInputs);
}

/// <summary>
/// Verifies that ForwardSolverViewModel disallows time-dependent solution domain options
/// for DistributedGaussianSourceSDA selection
/// </summary>
[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();
Expand All @@ -101,5 +191,7 @@ public void verify_DistributedGaussianSourceSDA_selection_does_not_display_time_
Assert.IsFalse(viewModel.SolutionDomainTypeOptionVM.IsROfFxAndTimeEnabled);
Assert.IsFalse(viewModel.SolutionDomainTypeOptionVM.IsROfFxAndFtEnabled);
}


}
}
Loading
Loading