Skip to content

Commit 04ecbb3

Browse files
committed
Update Startup and add tests
1 parent 75f427c commit 04ecbb3

File tree

6 files changed

+164
-1
lines changed

6 files changed

+164
-1
lines changed

HelperFunctions/Startup.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
% Open the overview file
33
locDir = pwd;
44
if contains(locDir,filesep+"MATLAB Drive")
5-
open("NavigationOverview.mlx")
5+
open("Navigation.mlx")
66
else
77
open("Overview.html")
88
end

tests/functionTests.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
% Run these tests with runMyTests
2+
%
3+
% Alternately, run these tests with
4+
% results = runtests(tests)
5+
% table(results)
6+
classdef functionTests < matlab.unittest.TestCase
7+
8+
methods(Test)
9+
function checkStartup(testCase)
10+
Startup
11+
end
12+
13+
function checkOverview(testCase)
14+
OpenOverview
15+
end
16+
17+
end % methods
18+
19+
end % classdef

tests/model2t.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function dydt = model2t(t,y,L,g)
2+
theta = y(1);
3+
omega = y(2);
4+
dydt = [omega; ...
5+
-g/L*sin(theta)];
6+
end

tests/model3t.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function dydt = model3t(t,y,L,g,M,b,c)
2+
theta = y(1);
3+
omega = y(2);
4+
if omega < 0
5+
c = -c;
6+
end
7+
dydt = [omega; ...
8+
(-g*M*L*sin(theta)-b*omega-c*omega^2)/(M*L^2)];
9+
end

tests/model4t.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function dydt = model4t(t,y,L,g,M,m,b,c)
2+
theta = y(1);
3+
omega = y(2);
4+
if omega < 0
5+
c = -c;
6+
end
7+
rotInertia = m*L^2/3+M*L^2;
8+
dydt = [omega; ...
9+
(-g*(M*L+m*L/2)*sin(theta)-b*omega-c*omega^2)/rotInertia];
10+
end

tests/smokeTests.m

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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

Comments
 (0)