From e238e266e97c1a3b90528936a96a9d0bf00b8775 Mon Sep 17 00:00:00 2001 From: "Garrett E. Granroth" Date: Mon, 11 Sep 2023 11:40:43 -0400 Subject: [PATCH] streamlined tests --- .../+unit_tests/unittest_spinw_spec2MDHisto.m | 85 ++++++++----------- 1 file changed, 37 insertions(+), 48 deletions(-) diff --git a/+sw_tests/+unit_tests/unittest_spinw_spec2MDHisto.m b/+sw_tests/+unit_tests/unittest_spinw_spec2MDHisto.m index 2b103d28b..1511d2730 100644 --- a/+sw_tests/+unit_tests/unittest_spinw_spec2MDHisto.m +++ b/+sw_tests/+unit_tests/unittest_spinw_spec2MDHisto.m @@ -1,63 +1,52 @@ classdef unittest_spinw_spec2MDHisto < sw_tests.unit_tests.unittest_super + properties + swModel = []; + tmpdir = ''; + testfilename = ''; + nsteps = {100}; + end - properties(TestParameter) - nsteps={100}; + properties (TestParameter) + testpars = struct(... + 'test_1_0_0', struct('q0', [0 0 0], 'qdir', [1 0 0], 'proj', [[1 0 0]' [0 1 0]' [0 0 1]'], 'nxs', 'test100mdh.nxs'), ... + 'test_1_1_0', struct('q0', [0 0 0], 'qdir', [1 1 0], 'proj', [[1 1 0]' [1 -1 0]' [0 0 1]'], 'nxs', 'test110mdh.nxs'), ... + 'test_1_1_1', struct('q0', [0 0 0], 'qdir', [1 1 1], 'proj', [[1 1 1]' [1 -1 0]' [1 1 -2]'], 'nxs', 'test111mdh.nxs'), ... + 'test_1_1_2', struct('q0', [0 0 2], 'qdir', [1 1 0], 'proj', [[1 1 0]' [1 -1 0]' [0 0 1]'], 'nxs', 'test112mdh.nxs'), ... + 'test_1_1_2_2', struct('q0', [0 0 2], 'qdir', [1 1 0], 'proj', [[1 -1 0]' [1 1 0]' [0 0 1]'], 'nxs', 'test112_2mdh.nxs'), ... + 'test_2_2_2', struct('q0', [2 2 2], 'qdir', [1 1 0], 'proj', [[1 1 0]' [1 -1 0]' [0 0 1]'], 'nxs', 'test222mdh.nxs')); end - methods (Test) - function test_1_0_0(testCase) - q0 = [0 0 0]; - qdir = [1 0 0]; - spec = sw_egrid(spinwave(sw_model('triAF', 1), {q0 q0+qdir testCase.nsteps{1}})); - proj = [qdir(:) [0 1 0]' [0 0 1]']; - dproj = [norm((qdir-q0))/testCase.nsteps{1}, 1e-6, 1e-6]; - sw_spec2MDHisto(spec, proj, dproj, 'tmp/test100mdh.nxs'); - end - function test_1_1_0(testCase) - q0 = [0 0 0]; - qdir = [1 1 0]; - spec = sw_egrid(spinwave(sw_model('triAF', 1), {q0 q0+qdir testCase.nsteps{1}})); - proj = [qdir(:) [1 -1 0]' [0 0 1]']; - dproj = [norm((qdir-q0))/testCase.nsteps{1}, 1e-6, 1e-6]; - sw_spec2MDHisto(spec, proj, dproj, 'tmp/test110mdh.nxs'); + methods (TestClassSetup) + function setup_model(testCase) + testCase.swModel = sw_model('triAF', 1); end - - function test_1_1_1(testCase) - q0 = [0 0 0]; - qdir = [1 1 1]; - spec = sw_egrid(spinwave(sw_model('triAF', 1), {q0 q0+qdir testCase.nsteps{1}})); - proj = [qdir(:) [1 -1 0]' [1 1 -2]']; - dproj = [norm((qdir-q0))/testCase.nsteps{1}, 1e-6, 1e-6]; - sw_spec2MDHisto(spec, proj, dproj, 'tmp/test111mdh.nxs'); - end - function test_1_1_2(testCase) - q0 = [0 0 2]; - qdir = [1 1 0]; - spec = sw_egrid(spinwave(sw_model('triAF', 1), {q0 q0+qdir testCase.nsteps{1}})); - proj = [qdir(:) [1 -1 0]' [0 0 1]']; - dproj = [norm((qdir-q0))/testCase.nsteps{1}, 1e-6, 1e-6]; - sw_spec2MDHisto(spec, proj, dproj, 'tmp/test112mdh.nxs'); + function setup_tempdir(testCase) + testCase.tmpdir = tempdir; end - function test_1_1_2_2(testCase) - q0 = [0 0 2]; - qdir = [1 1 0]; - spec = sw_egrid(spinwave(sw_model('triAF', 1), {q0 q0+qdir testCase.nsteps{1}})); - proj = [[1 -1 0]' qdir(:) [0 0 1]']; - dproj = [1e-6, norm((qdir-q0))/testCase.nsteps{1}, 1e-6]; - sw_spec2MDHisto(spec, proj, dproj, 'tmp/test112_2mdh.nxs'); + end + + methods (TestMethodTeardown) + function remove_tmpdir(testCase) + delete(testCase.testfilename); end - function test_2_2_2(testCase) - q0 = [2 2 2]; - qdir = [1 1 0]; - spec = sw_egrid(spinwave(sw_model('triAF', 1), {q0 q0+qdir testCase.nsteps{1}})); - proj = [qdir(:) [1 -1 0]' [0 0 1]']; + end + + methods (Test) + function test_qdirs(testCase, testpars) + q0 = testpars.q0; + qdir = testpars.qdir; + proj = testpars.proj; + testCase.disable_warnings('spinw:spinwave:NonPosDefHamiltonian'); + spec = sw_egrid(spinwave(testCase.swModel, {q0 q0+qdir testCase.nsteps{1}})); dproj = [norm((qdir-q0))/testCase.nsteps{1}, 1e-6, 1e-6]; - sw_spec2MDHisto(spec, proj, dproj, 'tmp/test222mdh.nxs'); + testCase.testfilename = fullfile(testCase.tmpdir, testpars.nxs); + sw_spec2MDHisto(spec, proj, dproj, testCase.testfilename); end + function test_non_ortho(testCase) q0 = [0 0 2]; qdir = [1 1 0]; - spec = sw_egrid(spinwave(sw_model('triAF', 1), {q0 q0+qdir testCase.nsteps{1}})); + spec = sw_egrid(spinwave(testCase.swModel, {q0 q0+qdir testCase.nsteps{1}})); proj = [qdir(:) [1 0 0]' [0 0 1]']; dproj = [1e-6, norm((qdir-q0))/testCase.nsteps{1}, 1e-6]; verifyError(testCase,@() sw_spec2MDHisto(spec, proj, dproj, 'tmp/test_blank.nxs'), "read_struct:nonorthogonal")