Skip to content

Commit

Permalink
Update Startup and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eszmw committed Mar 21, 2023
1 parent 75f427c commit 04ecbb3
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 1 deletion.
2 changes: 1 addition & 1 deletion HelperFunctions/Startup.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
% Open the overview file
locDir = pwd;
if contains(locDir,filesep+"MATLAB Drive")
open("NavigationOverview.mlx")
open("Navigation.mlx")
else
open("Overview.html")
end
Expand Down
19 changes: 19 additions & 0 deletions tests/functionTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
% Run these tests with runMyTests
%
% Alternately, run these tests with
% results = runtests(tests)
% table(results)
classdef functionTests < matlab.unittest.TestCase

methods(Test)
function checkStartup(testCase)
Startup
end

function checkOverview(testCase)
OpenOverview
end

end % methods

end % classdef
6 changes: 6 additions & 0 deletions tests/model2t.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function dydt = model2t(t,y,L,g)
theta = y(1);
omega = y(2);
dydt = [omega; ...
-g/L*sin(theta)];
end
9 changes: 9 additions & 0 deletions tests/model3t.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function dydt = model3t(t,y,L,g,M,b,c)
theta = y(1);
omega = y(2);
if omega < 0
c = -c;
end
dydt = [omega; ...
(-g*M*L*sin(theta)-b*omega-c*omega^2)/(M*L^2)];
end
10 changes: 10 additions & 0 deletions tests/model4t.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function dydt = model4t(t,y,L,g,M,m,b,c)
theta = y(1);
omega = y(2);
if omega < 0
c = -c;
end
rotInertia = m*L^2/3+M*L^2;
dydt = [omega; ...
(-g*(M*L+m*L/2)*sin(theta)-b*omega-c*omega^2)/rotInertia];
end
119 changes: 119 additions & 0 deletions tests/smokeTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
% Run these tests with runMyTests
% All tests so far are on code expected to run without errors
% If/when we end up with a version that _should_ error,
% please add it to this set of examples
classdef smokeTests < matlab.unittest.TestCase

properties
fc
origProj
openFilesIdx
end

methods (TestClassSetup)
function setUpPath(testCase)
testCase.origProj = matlab.project.rootProject;
testCase.openFilesIdx = length(matlab.desktop.editor.getAll);
testCase.fc = fullfile(pwd);
rootDirName = extractBefore(testCase.fc,"tests");
openProject(rootDirName);
end % function setUpPath
end % methods (TestClassSetup)

methods(Test)

function dataExists(testCase)
load("hand2.mat","x","y")
clear x y
load("car.mat","xCar","yCar")
clear xCar yCar
load("drawing.mat","x","y")
clear x y
load("lakeData.mat","lakeX","lakeY","scale")
clear lakeY lakeX scale
load("modernLakeData.mat","latScale","longScale","modLakeLat","modLakeLong")
clear latScale longScale modLakeLat modLakeLong
load("myStorm.mat","myStorm")
clear myStorm
end

function runDerivatives(testCase)
% this function runs all the code in Functions.mlx
% it also logs the final figure in the resulting output
% document while closing the figure window on teardown
import matlab.unittest.diagnostics.FigureDiagnostic;
testCase.log("Running approximatingDerivatives.mlx")
fig = figure;
testCase.addTeardown(@close,fig)
approximatingDerivatives
testCase.log(3,FigureDiagnostic(fig))
end

function runInterpolation(testCase)
% this is the simplest possible logged version of a smoke test
% that will run a file called "SharingCode.mlx"
testCase.log("Running interpolation.mlx")
interpolation
end
function runStorms(testCase)
testCase.log("Running track storms...")
trackStorms
end

function runNumericalIntegration(testCase)
testCase.log("Running Numerical Integration")
numericalIntegration
end

function runNumODEs(testCase)
testCase.log("Running Numerical ODEs")
diffEqs
end
function runPendulum(testCase)
testCase.log("Running pendulum...")
flag = 0;
try
pendulum
catch ME
if string(ME.identifier) == "MATLAB:unassignedOutputs"
flag = flag+1;
switch flag
case 1
[t2,theta2] = ode45(@(t,theta) model2t(t,theta,L,g),[t0 tEnd],[theta0 omega0]);
case 2
[t3,theta3] = ode45(@(t,theta) model3t(t,theta,L,g,M,b,c),[t0 tEnd],[theta0 omega0]);
case 3
[t4,theta4] = ode45(@(t,theta) model4t(t,theta,L,g,M,m,b,c),[t0 tEnd],[theta0 omega0]);
end
else
rethrow(ME)
end
end

end

function runNumPDEs(testCase)
testCase.log("Running Numerical PDEs")
partialDiffEqs
end
end

methods (TestClassTeardown)
function resetPath(testCase)

if isempty(testCase.origProj)
close(currentProject)
else
openProject(testCase.origProj.RootFolder)
end
myLastList = matlab.desktop.editor.getAll;
if length(myLastList)>testCase.openFilesIdx
closeNoPrompt(myLastList(testCase.openFilesIdx+1:end))
end
cd(testCase.fc)
close all force
end

end % methods (TestClassTeardown)

end

0 comments on commit 04ecbb3

Please sign in to comment.