-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtgenerateSimFun.m
More file actions
66 lines (49 loc) · 2.07 KB
/
tgenerateSimFun.m
File metadata and controls
66 lines (49 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
classdef tgenerateSimFun < matlab.unittest.TestCase
properties (Access=private)
MATfilefullpath
LoadedData
end
properties (ClassSetupParameter)
MATfilename = {"test_generateSimFun.mat", string.empty}
end
properties (TestParameter)
fieldName = {"simFun","doseTable","dependenciesSimFun"}
end
methods (Test)
function testMATfileCreation(testCase)
import matlab.unittest.constraints.IsFile;
% Verify that the MAT file is created
testCase.verifyThat(testCase.MATfilefullpath, IsFile, ...
'MAT file was not created.');
end
function testSimFunctionCreation(testCase, fieldName)
import matlab.unittest.constraints.HasField;
% Verify that the MAT file contains required fields
testCase.verifyThat(testCase.LoadedData, HasField(fieldName), ...
fieldName + " should be saved in " + testCase.MATfilefullpath);
end
function testSimFunctionAcceleration(testCase)
% Verify that the SimFunction is accelerated
simFun = testCase.LoadedData.simFun;
testCase.verifyReturnsTrue(@()simFun.isAccelerated, ...
"simFun was not accelerated.");
end
end
methods (TestClassSetup)
function classSetup(testCase, MATfilename)
import matlab.unittest.fixtures.WorkingFolderFixture;
% Set up shared state for all tests.
% Generate the simulation function in a working folder
testCase.applyFixture(WorkingFolderFixture);
% Test if the simulation function is created successfully
if isempty(MATfilename)
testCase.MATfilefullpath = generateSimFun();
else
testCase.MATfilefullpath = generateSimFun(MATfilename);
% delete file with testCase.addTeardown
testCase.addTeardown(@delete,testCase.MATfilefullpath);
end
testCase.LoadedData = load(testCase.MATfilefullpath);
end
end
end