Skip to content

Commit

Permalink
streamlined tests
Browse files Browse the repository at this point in the history
  • Loading branch information
granrothge committed Sep 11, 2023
1 parent 99adabc commit e238e26
Showing 1 changed file with 37 additions and 48 deletions.
85 changes: 37 additions & 48 deletions +sw_tests/+unit_tests/unittest_spinw_spec2MDHisto.m
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit e238e26

Please sign in to comment.