1+ % Run these tests with runMyTests
2+ % All tests so far are on code expected to run without errors
3+ % If/when we end up with a version that _should_ error,
4+ % please add it to this set of examples
5+ classdef smokeTests < matlab .unittest .TestCase
6+
7+ properties
8+ fc
9+ origProj
10+ openFilesIdx
11+ end
12+
13+ methods (TestClassSetup )
14+ function setUpPath(testCase )
15+ testCase.origProj = matlab .project .rootProject ;
16+ testCase.openFilesIdx = length(matlab .desktop .editor .getAll );
17+ testCase.fc = fullfile(pwd );
18+ rootDirName = extractBefore(testCase .fc ," tests" );
19+ openProject(rootDirName );
20+ end % function setUpPath
21+ end % methods (TestClassSetup)
22+
23+ methods (Test )
24+
25+ function dataExists(testCase )
26+ load(" hand2.mat" ," x" ," y" )
27+ clear x y
28+ load(" car.mat" ," xCar" ," yCar" )
29+ clear xCar yCar
30+ load(" drawing.mat" ," x" ," y" )
31+ clear x y
32+ load(" lakeData.mat" ," lakeX" ," lakeY" ," scale" )
33+ clear lakeY lakeX scale
34+ load(" modernLakeData.mat" ," latScale" ," longScale" ," modLakeLat" ," modLakeLong" )
35+ clear latScale longScale modLakeLat modLakeLong
36+ load(" myStorm.mat" ," myStorm" )
37+ clear myStorm
38+ end
39+
40+ function runDerivatives(testCase )
41+ % this function runs all the code in Functions.mlx
42+ % it also logs the final figure in the resulting output
43+ % document while closing the figure window on teardown
44+ import matlab .unittest .diagnostics .FigureDiagnostic ;
45+ testCase .log(" Running approximatingDerivatives.mlx" )
46+ fig = figure ;
47+ testCase .addTeardown(@close ,fig )
48+ approximatingDerivatives
49+ testCase .log(3 ,FigureDiagnostic(fig ))
50+ end
51+
52+ function runInterpolation(testCase )
53+ % this is the simplest possible logged version of a smoke test
54+ % that will run a file called "SharingCode.mlx"
55+ testCase .log(" Running interpolation.mlx" )
56+ interpolation
57+ end
58+ function runStorms(testCase )
59+ testCase .log(" Running track storms..." )
60+ trackStorms
61+ end
62+
63+ function runNumericalIntegration(testCase )
64+ testCase .log(" Running Numerical Integration" )
65+ numericalIntegration
66+ end
67+
68+ function runNumODEs(testCase )
69+ testCase .log(" Running Numerical ODEs" )
70+ diffEqs
71+ end
72+ function runPendulum(testCase )
73+ testCase .log(" Running pendulum..." )
74+ flag = 0 ;
75+ try
76+ pendulum
77+ catch ME
78+ if string(ME .identifier ) == " MATLAB:unassignedOutputs"
79+ flag = flag + 1 ;
80+ switch flag
81+ case 1
82+ [t2 ,theta2 ] = ode45(@(t ,theta ) model2t(t ,theta ,L ,g ),[t0 tEnd ],[theta0 omega0 ]);
83+ case 2
84+ [t3 ,theta3 ] = ode45(@(t ,theta ) model3t(t ,theta ,L ,g ,M ,b ,c ),[t0 tEnd ],[theta0 omega0 ]);
85+ case 3
86+ [t4 ,theta4 ] = ode45(@(t ,theta ) model4t(t ,theta ,L ,g ,M ,m ,b ,c ),[t0 tEnd ],[theta0 omega0 ]);
87+ end
88+ else
89+ rethrow(ME )
90+ end
91+ end
92+
93+ end
94+
95+ function runNumPDEs(testCase )
96+ testCase .log(" Running Numerical PDEs" )
97+ partialDiffEqs
98+ end
99+ end
100+
101+ methods (TestClassTeardown )
102+ function resetPath(testCase )
103+
104+ if isempty(testCase .origProj )
105+ close(currentProject )
106+ else
107+ openProject(testCase .origProj .RootFolder )
108+ end
109+ myLastList = matlab .desktop .editor .getAll ;
110+ if length(myLastList )>testCase .openFilesIdx
111+ closeNoPrompt(myLastList(testCase .openFilesIdx + 1 : end ))
112+ end
113+ cd(testCase .fc )
114+ close all force
115+ end
116+
117+ end % methods (TestClassTeardown)
118+
119+ end
0 commit comments