Skip to content

Commit 445cb48

Browse files
committed
Update InstanceTest.m
Update terms, refer to metadata types instead of schemas
1 parent 717db74 commit 445cb48

1 file changed

Lines changed: 31 additions & 34 deletions

File tree

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
11
classdef InstanceTest < matlab.unittest.TestCase
22
% InstanceTest - Unit test for creation and save/load of OpenMINDS instances
33

4-
% Automatically generate a test case for each schema type
4+
% Automatically generate a test case for each metadata type
55
properties (TestParameter)
6-
SchemaType = cellstr( enumeration('openminds.enum.Types') );
7-
end
8-
9-
properties
10-
ItemPreSave % Property to store the object created in the first test
11-
TempSavePath % Property to store the temporary save path
12-
CurrentSchemaType % Property to store the current schema type being tested
6+
MetadataType = cellstr( enumeration('openminds.enum.Types') );
137
end
148

159
methods (Test)
1610

17-
function testCreateSchema(testCase, SchemaType)
18-
% Get the schema class name and function handle
19-
20-
schemaType = openminds.enum.Types(SchemaType);
21-
schemaClassFunctionName = schemaType.ClassName;
22-
schemaFcn = str2func(schemaClassFunctionName);
11+
function testCreateType(testCase, MetadataType)
12+
% Get class constructor for metadata type
13+
metadataType = openminds.enum.Types(MetadataType);
14+
typeConstructor = str2func( metadataType.ClassName );
2315

2416
% Skip abstract classes
25-
mc = meta.class.fromName(schemaClassFunctionName);
17+
mc = meta.class.fromName( metadataType.ClassName );
2618
if isempty(mc) || mc.Abstract
2719
return;
2820
end
2921

30-
% Attempt to create an object of the schema class
31-
instance = schemaFcn();
22+
% Attempt to create an object of the type class for a metadata schema
23+
instance = typeConstructor();
3224
testCase.assertInstanceOf(instance, 'openminds.abstract.Schema')
3325

3426
testCase.verifyWarningFree( @(i)dispNoOutput(instance) )
@@ -37,12 +29,12 @@ function testCreateSchema(testCase, SchemaType)
3729
testCase.verifyClass(strRep, 'string')
3830

3931
% list instances if the type has controlled instances
40-
superClassNames = superclasses(schemaClassFunctionName);
32+
superClassNames = superclasses(metadataType.ClassName);
4133

4234
if any(ismember(superClassNames, ...
4335
{'openminds.internal.mixin.HasControlledInstance', ...
4436
'openminds.abstract.ControlledTerm'}))
45-
instances = feval(sprintf('%s.listInstances', schemaClassFunctionName));
37+
instances = feval(sprintf('%s.listInstances', metadataType.ClassName));
4638
if ~isempty(instances)
4739
testCase.verifyClass(instances, 'string')
4840
end
@@ -53,27 +45,28 @@ function dispNoOutput(instance) %#ok<INUSD>
5345
end
5446
end
5547

56-
function testSaveLoadForSchema(testCase, SchemaType)
57-
% Test saving and loading for a specific schema type
48+
function testSaveLoadForTypedInstance(testCase, MetadataType)
49+
% Test saving and loading for a specific metadata type
5850

59-
if strcmp( SchemaType, "None" ); return; end
51+
if strcmp( MetadataType, "None" ); return; end
52+
53+
% Get class constructor for metadata type
54+
metadataType = openminds.enum.Types(MetadataType);
55+
typeConstructor = str2func( metadataType.ClassName );
6056

61-
% Get the schema class name and function handle
62-
schemaType = openminds.enum.Types(SchemaType);
63-
schemaClassFunctionName = schemaType.ClassName;
64-
schemaFcn = str2func(schemaClassFunctionName);
65-
6657
% Skip abstract classes
67-
mc = meta.class.fromName(schemaClassFunctionName);
58+
mc = meta.class.fromName(metadataType.ClassName);
6859
if isempty(mc) || mc.Abstract
6960
return;
7061
end
7162

72-
% Attempt to create an object of the schema class
63+
% Attempt to create an object of the type class for a metadata schema
7364
try
74-
itemPreSave = schemaFcn();
65+
itemPreSave = typeConstructor();
7566
catch ME
76-
testCase.verifyFail(sprintf('Failed to create object for %s: %s', schemaClassFunctionName, ME.message));
67+
testCase.verifyFail(...
68+
sprintf('Failed to create object for %s: %s', ...
69+
metadataType.ClassName, ME.message));
7770
return;
7871
end
7972

@@ -85,21 +78,25 @@ function testSaveLoadForSchema(testCase, SchemaType)
8578
try
8679
save(tempsavepath, 'itemPreSave');
8780
catch ME
88-
testCase.verifyFail(sprintf('Failed to save object for %s: %s', schemaClassFunctionName, ME.message));
81+
testCase.verifyFail(...
82+
sprintf('Failed to save object for %s: %s', ...
83+
metadataType.ClassName, ME.message));
8984
return;
9085
end
9186

9287
% Attempt to load the object
9388
try
9489
S = load(tempsavepath, 'itemPreSave');
9590
catch ME
96-
testCase.verifyFail(sprintf('Failed to load object for %s: %s', schemaClassFunctionName, ME.message));
91+
testCase.verifyFail(...
92+
sprintf('Failed to load object for %s: %s', ...
93+
metadataType.ClassName, ME.message));
9794
return;
9895
end
9996

10097
% Verify that the loaded object matches the original object
10198
testCase.verifyEqual(S.itemPreSave, itemPreSave, ...
102-
sprintf('Loaded object does not match the original for %s', schemaClassFunctionName));
99+
sprintf('Loaded object does not match the original for %s', metadataType.ClassName));
103100
end
104101
end
105102
end

0 commit comments

Comments
 (0)