-
Notifications
You must be signed in to change notification settings - Fork 287
/
ParameterizedTestExample.m
32 lines (24 loc) · 1.05 KB
/
ParameterizedTestExample.m
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
classdef ParameterizedTestExample < matlab.unittest.TestCase
% Creates 12 test points, one test point for the 15th day of every month of 2021
% Copyright 2022 The MathWorks, Inc.
properties (TestParameter)
monthNum = num2cell(1:12);
dayNum = {15};
yearNum = {2021};
end
methods (Test)
function testDayofyear(testCase,monthNum,dayNum,yearNum)
% Convert numeric values to mm/dd/yyyy string
% Note: MATLAB will automatically convert numbers to strings
% when performing number+string arithmetic
dateStr = monthNum + "/" + dayNum + "/" + yearNum;
% Compute expected result
dt = datetime(dateStr,"Format","MM/dd/uuuu");
doyExpected = day(dt,"dayofyear");
% Compute actual result
doyActual = dayofyear(dateStr);
% Verify that the actual result matches the expected result
testCase.verifyEqual(doyActual,doyExpected)
end
end
end