-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_add_one.m
68 lines (58 loc) · 1.41 KB
/
test_add_one.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function tests = test_add_one
tests = functiontests(localfunctions);
end
function test_normal1(testCase)
x = 1;
actSol = add_one(x);
expSol = 2;
verifyEqual(testCase, actSol, expSol)
end
function test_normal_pi(testCase)
x = pi;
actSol = add_one(x);
expSol = pi + 1;
verifyEqual(testCase, actSol, expSol)
end
function test_irrationalNr(testCase)
x = 3 + i;
actSol = add_one(x);
expSol = 4 + i;
verifyEqual(testCase, actSol, expSol)
end
function test_negative(testCase)
x = -5;
actSol = add_one(x);
expSol = -4;
verifyEqual(testCase, actSol, expSol)
end
function test_matrix(testCase)
x = [1, 2; 3, 4];
actSol = add_one(x);
expSol = [2, 3; 4, 5];
verifyEqual(testCase, actSol, expSol)
end
function test_empty(testCase)
x = [];
y = add_one(x);
actSol = +isempty(y); % plus converts logical to double
expSol = 1;
verifyEqual(testCase, actSol, expSol)
end
function test_nan(testCase)
x = nan;
y = add_one(x);
actSol = +isnan(y); % plus converts logical to double
expSol = 1;
verifyEqual(testCase, actSol, expSol)
end
function test_stringError(testCase)
x = 'Hello world';
try
y = add_one(x);
actSol = 0;
catch
actSol = 1;
end
expSol = 1;
verifyEqual(testCase, actSol, expSol)
end