Skip to content

Commit c0c3a7c

Browse files
committed
test:parent own file
1 parent 31f7271 commit c0c3a7c

18 files changed

+124
-125
lines changed

test/TestFileImpure.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@
3838
methods(TestClassSetup)
3939

4040
function setup_path(tc)
41-
import matlab.unittest.fixtures.PathFixture
42-
cwd = fileparts(mfilename("fullpath"));
43-
top = fullfile(cwd, "..");
44-
tc.applyFixture(PathFixture(top))
41+
top = fullfile(fileparts(mfilename("fullpath")), "..");
42+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
4543
end
4644

4745
function classSetup(tc, classToTest)

test/TestFilePure.m

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
{"a/b/c.txt.gz", "c.txt.gz"}
1818
};
1919

20-
p_parent
21-
2220
p_stem ={{"/a/b/c", "c"}, {"/a/b/c/", ""}, {"a/b/c/", ""}, {"a/b/c.txt", "c"}, {"a/b/c.txt.gz", "c.txt"}}
2321

2422
p_join = {{"", "", ""}, ...
@@ -70,7 +68,7 @@
7068

7169
methods (TestParameterDefinition, Static)
7270

73-
function [p_root, p_root_name, p_parent] = init_relative_to(classToTest) %#ok<INUSD>
71+
function [p_root, p_root_name] = init_relative_to(classToTest) %#ok<INUSD>
7472

7573
p_root = {{"", ""}, ...
7674
{"a/b", ""}, ...
@@ -84,37 +82,11 @@
8482
{"/etc", ""}, ...
8583
{"c:/etc", ""}};
8684

87-
p_parent = {
88-
{"", "."}, ...
89-
{".", "."}, ...
90-
{"..", "."}, ...
91-
{"../..", ".."}, ...
92-
{"a/", "."}, ...
93-
{"a/b", "a"}, ...
94-
{"a/b/", "a"}, ...
95-
{"ab/.parent", "ab"}, ...
96-
{"ab/.parent.txt", "ab"}, ...
97-
{"a/b/../.parent.txt", "a/b/.."}, ...
98-
{"a/////b////c", "a/b"}, ...
99-
{"c:/", "."}, ...
100-
{"c:\", "."}, ...
101-
{"c:/a/b", "c:/a"}, ...
102-
{"c:\a/b", "c:\a"}
103-
};
104-
10585
if ispc
106-
p_parent{12}{2} = "c:/";
107-
p_parent{13}{2} = "c:/";
108-
p_parent{14}{2} = "c:/a";
109-
p_parent{15}{2} = "c:/a";
110-
p_parent{end+1} = {"c:/a", "c:/"};
111-
p_parent{end+1} = {"c:", "c:/"};
112-
11386
p_root{5}{2} = "c:";
11487
p_root{6}{2} = "c:/";
11588

11689
p_root_name{4}{2} = "c:";
117-
11890
end
11991

12092
end
@@ -143,10 +115,8 @@ function classSetup(tc, classToTest)
143115
end
144116

145117
function setup_path(tc)
146-
import matlab.unittest.fixtures.PathFixture
147-
cwd = fileparts(mfilename("fullpath"));
148-
top = fullfile(cwd, "..");
149-
tc.applyFixture(PathFixture(top))
118+
top = fullfile(fileparts(mfilename("fullpath")), "..");
119+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
150120
end
151121

152122
end
@@ -170,16 +140,10 @@ function test_join(tc, p_join)
170140
tc.verifyEqual(stdlib.join(p_join{1}, p_join{2}), p_join{3})
171141
end
172142

173-
174143
function test_filename(tc, p_filename)
175144
tc.verifyEqual(stdlib.filename(p_filename{1}), string(p_filename{2}))
176145
end
177146

178-
179-
function test_parent(tc, p_parent)
180-
tc.verifyEqual(stdlib.parent(p_parent{1}), p_parent{2}, p_parent{1})
181-
end
182-
183147
function test_suffix(tc, p_suffix)
184148
tc.verifyEqual(stdlib.suffix(p_suffix{1}), string(p_suffix{2}))
185149
end

test/TestHDF4.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
methods (TestClassSetup)
88

99
function setup_path(tc)
10-
import matlab.unittest.fixtures.PathFixture
11-
cwd = fileparts(mfilename("fullpath"));
12-
top = fullfile(cwd, "..");
13-
tc.applyFixture(PathFixture(top))
10+
top = fullfile(fileparts(mfilename("fullpath")), "..");
11+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
1412
end
1513

1614
function setup_file(tc)

test/TestHDF5.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313

1414
methods(TestClassSetup)
1515
function setup_path(tc)
16-
import matlab.unittest.fixtures.PathFixture
17-
cwd = fileparts(mfilename("fullpath"));
18-
top = fullfile(cwd, "..");
19-
tc.applyFixture(PathFixture(top))
16+
top = fullfile(fileparts(mfilename("fullpath")), "..");
17+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
2018
end
2119

2220
function setup_file(tc)

test/TestHash.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
methods(TestClassSetup)
99

1010
function setup_path(tc)
11-
import matlab.unittest.fixtures.PathFixture
12-
cwd = fileparts(mfilename("fullpath"));
13-
top = fullfile(cwd, "..");
14-
tc.applyFixture(PathFixture(top))
11+
top = fullfile(fileparts(mfilename("fullpath")), "..");
12+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
1513

1614
tc.assumeTrue(stdlib.has_java)
1715
end

test/TestIni.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
methods (TestClassSetup)
44
function setup_path(tc)
5-
import matlab.unittest.fixtures.PathFixture
6-
cwd = fileparts(mfilename("fullpath"));
7-
top = fullfile(cwd, "..");
8-
tc.applyFixture(PathFixture(top))
5+
top = fullfile(fileparts(mfilename("fullpath")), "..");
6+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
97
end
108
end
119

test/TestJava.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
methods(TestClassSetup)
44

55
function setup_path(tc)
6-
import matlab.unittest.fixtures.PathFixture
7-
cwd = fileparts(mfilename("fullpath"));
8-
top = fullfile(cwd, "..");
9-
tc.applyFixture(PathFixture(top))
6+
top = fullfile(fileparts(mfilename("fullpath")), "..");
7+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
108

119
tc.assumeTrue(stdlib.has_java)
1210
end

test/TestNetCDF.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
methods (TestClassSetup)
88
function setup_path(tc)
9-
import matlab.unittest.fixtures.PathFixture
10-
cwd = fileparts(mfilename("fullpath"));
11-
top = fullfile(cwd, "..");
12-
tc.applyFixture(PathFixture(top))
9+
top = fullfile(fileparts(mfilename("fullpath")), "..");
10+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
1311
end
1412

1513
function setup_file(tc)

test/TestParent.m

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
classdef TestParent < matlab.unittest.TestCase
2+
3+
properties (TestParameter)
4+
p_parent
5+
end
6+
7+
methods (TestClassSetup)
8+
% TestClassSetup runs this once per class instead of TestMethodSetup that
9+
% runs once per test, which is much slower and unnecessary
10+
function setup_path(tc)
11+
top = fullfile(fileparts(mfilename("fullpath")), "..");
12+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
13+
end
14+
end
15+
16+
17+
methods(TestParameterDefinition, Static)
18+
19+
function p_parent = init_parent()
20+
21+
p_parent = {
22+
{"", "."}, ...
23+
{".", "."}, ...
24+
{"..", "."}, ...
25+
{"../..", ".."}, ...
26+
{"a/", "."}, ...
27+
{"a/b", "a"}, ...
28+
{"a/b/", "a"}, ...
29+
{"ab/.parent", "ab"}, ...
30+
{"ab/.parent.txt", "ab"}, ...
31+
{"a/b/../.parent.txt", "a/b/.."}, ...
32+
{"a/////b////c", "a/b"}, ...
33+
{"c:/", "."}, ...
34+
{"c:\", "."}, ...
35+
{"c:/a/b", "c:/a"}, ...
36+
{"c:\a/b", "c:\a"}
37+
};
38+
39+
if ispc
40+
p_parent{12}{2} = "c:/";
41+
p_parent{13}{2} = "c:/";
42+
p_parent{14}{2} = "c:/a";
43+
p_parent{15}{2} = "c:/a";
44+
p_parent{end+1} = {"c:/a", "c:/"};
45+
p_parent{end+1} = {"c:", "c:/"};
46+
47+
end
48+
49+
end
50+
end
51+
52+
53+
methods (Test)
54+
function test_parent(tc, p_parent)
55+
tc.verifyEqual(stdlib.parent(p_parent{1}), p_parent{2}, p_parent{1})
56+
end
57+
end
58+
59+
end

test/TestRelative.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
p_relative_to
99
p_proximate_to
1010
p_is_subdir
11-
1211
end
1312

1413
properties
@@ -101,10 +100,8 @@ function classSetup(tc, classToTest)
101100
end
102101

103102
function setup_path(tc)
104-
import matlab.unittest.fixtures.PathFixture
105-
cwd = fileparts(mfilename("fullpath"));
106-
top = fullfile(cwd, "..");
107-
tc.applyFixture(PathFixture(top))
103+
top = fullfile(fileparts(mfilename("fullpath")), "..");
104+
tc.applyFixture(matlab.unittest.fixtures.PathFixture(top))
108105
end
109106

110107
end

0 commit comments

Comments
 (0)