-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestMapNested.m
More file actions
158 lines (109 loc) · 2.97 KB
/
TestMapNested.m
File metadata and controls
158 lines (109 loc) · 2.97 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
%% TestNestedMap.m
%
% Description : Quick and dirty script for testing 'MapNested'-class.
% Simple syntax test/presentation of the class
%
%
% Author :
% Roland Ritt
%
% History :
% \change{1.0}{10 April 2017}{Original}
%
% --------------------------------------------------
% (c) 2017, Roland Ritt
clear
close all hidden
clc;
testMap = MapNested(); % create new MapNested- object
% assign values to keys
testMap('A') = 5;
testMap('C', 'd', 1, 'u') = 'hallo';
testMap({'C', 'd', 1, 'v'}) = 'servus';
% retrieve values
if (testMap('A')~=5)
error('Test ''A'' went wrong');
end
if (testMap('C', 'd', 1, 'u')~= 'hallo')
error('Test ''C d 1 i'' went wrong');
end
if (testMap({'C', 'd', 1, 'v'}) ~= 'servus')
error('Test ''C d 1 v'' went wrong');
end
if ~isKey(testMap, {'C', 'd'})
error('test is Key');
end
if isKey(testMap, {'C', 'f'})
error('test is Key');
end
if isKey(testMap, {'C', 'f', 'g', 'h'})
error('test is Key');
end
if isKey(testMap, {'E', 'f', 'g', 'h'})
error('test is Key');
end
testMap = setValueNested(testMap, {'ad', 'c'}, 7);
testMap = setValueNested(testMap, {'ad', 'e'}, 8);
if (getValueNested(testMap, {'ad', 'c'}) ~= 7)
error('Test ''ad c'' went wrong');
end
if (getValueNested(testMap, {'ad', 'e'})~= 8)
error('Test ''ad e'' went wrong');
end
% override value ('A' = 5, with a map)
testMap = setValueNested(testMap, {'A', 'x'}, 10);
keys(testMap)
if getValueNested(testMap, {'A', 'x'}) ~= 10
error('Test ''A x'' went wrong');
end
try
val5 = getValueNested(testMap, {'B', 'x'});
catch ME
if ME.message ~= 'key ''B'' is not a key'
error('Test wrong key went wrong');
end
end
if ~isequal(keys(testMap),{'A', 'C', 'ad'})
error('Test ''keys'' function went wrong');
end
if ~isequal(keys(testMap('C')) ,{'d'})
error('Test ''keys'' function went wrong');
end
try
values(testMap('C'));
catch
error('Test ''values'' function went wrong');
end
% test remove Key
testMap('C') = [];
if ~isequal(keys(testMap),{'A', 'ad'})
error('Test remove when assigning an empty array went wrong');
end
remove(testMap, 'A')
if ~isequal(keys(testMap),{ 'ad'})
error('Test remove when use remove function went wrong');
end
M = MapNested();
M(1, 'a') = 'a string value';
M(1, 'b') = 287.2;
M(2) = [1 2 3; 4 5 6];
try
M(2, 'x', pi) = {'a' 'cell' 'array'};
catch ME
if ~isequal(ME.message, 'Something went wrong in indexing')
error('Test assign cell array went wrong');
end
end
try
M('s') = 4;
catch ME
if ~isequal(ME.message, 'Something went wrong in indexing')
error('Test assign cell array went wrong');
end
end
if ~isequal(M.keys, {1,2})
error('Test ''.''-assignment went wrong');
end
if ~isequal(M.values{2} , [1 2 3; 4 5 6])
error('Test ''.''-assignment went wrong');
end