Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 619a6db

Browse files
authored
Run MATLAB Tests with FreeStyle Project
1 parent da601dc commit 619a6db

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function rs = squareRoot(x)
2+
if x < 0
3+
error('SQUAREROOT:INVALIDINPUT','Negative value %d Not accepted',x);
4+
else
5+
rs = sqrt(x);
6+
end
7+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
classdef testSquareRoot < matlab.unittest.TestCase
2+
3+
methods (Test)
4+
function testOutput(testCase)
5+
testCase.verifyEqual(squareRoot(16),4);
6+
testCase.verifyEqual(squareRoot(81),9);
7+
end
8+
end
9+
10+
end
11+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
classdef testSquareRootParameterized < matlab.unittest.TestCase
2+
3+
properties (TestParameter)
4+
inputs = {4, 16, 81, 121, 49};
5+
expected_outputs = {2, 4, 9 , 11, 7};
6+
end
7+
8+
% methods (TestClassSetup)
9+
% function addTestContentToPath(~)
10+
% %cd ..;
11+
% addpath(fullfile(pwd,'source'));
12+
% end
13+
% end
14+
15+
16+
methods (Test,ParameterCombination='sequential')
17+
function testOutput(testCase,inputs,expected_outputs)
18+
testCase.verifyEqual(squareRoot(inputs),expected_outputs);
19+
end
20+
21+
function testError(testCase)
22+
testCase.verifyError(@()squareRoot(-1),'SQUAREROOT:INVALIDINPUT');
23+
end
24+
25+
end
26+
27+
28+
end
29+

0 commit comments

Comments
 (0)