-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMapTest.m
112 lines (82 loc) · 2.09 KB
/
MapTest.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
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
function tests = MatTest()
tests = functiontests(localfunctions);
end
function kvp = getKeyValuePairs()
kvp = {
{1,3},1;
struct(), [1; 3; 4];
[1,2; 4 3], struct();
'Hej', struct('lol', 6);
0, 'Nej';
};
end
function testMultiKey(testCase)
map = Map
function setMultiKey()
map(1,2) = 1;
end
function getMultiKey()
v = map(1,2);
end
testCase.verifyError(@setMultiKey,'sbplib:Map:multipleKeys')
testCase.verifyError(@getMultiKey,'sbplib:Map:multipleKeys')
end
function testSetAndGet(testCase)
keyValuePairs = getKeyValuePairs();
map = Map();
% Insert
for i = 1:length(keyValuePairs)
map(keyValuePairs{i,1}) = keyValuePairs{i,2};
end
% Validate output
for i = 1:length(keyValuePairs)
v = map(keyValuePairs{i,1});
testCase.verifyEqual(v, keyValuePairs{i,2});
end
end
function map = exampleMap()
keyValuePairs = getKeyValuePairs();
map = Map();
% Insert
for i = 1:length(keyValuePairs)
map(keyValuePairs{i,1}) = keyValuePairs{i,2};
end
end
function testLength(testCase)
map = Map();
testCase.verifyEqual(map.length, 0);
map = exampleMap();
testCase.verifyEqual(map.length, 5)
end
function testIsKey(testCase)
map = exampleMap();
keyValuePairs = getKeyValuePairs();
keys = keyValuePairs(:,1);
for i = 1:length(keys)
testCase.verifyTrue(map.isKey(keys{i}));
end
notKeys = {
'hej',
[],
1,
{2,5},
};
for i = 1:length(notKeys)
testCase.verifyFalse(map.isKey(notKeys{i}));
end
end
function testRemove(testCase)
map = exampleMap();
remove(map, struct());
testCase.verifyFalse(map.isKey(struct()));
end
% function testValues(testCase)
% keyValuePairs = getKeyValuePairs();
% map = exampleMap();
% testCase.verifyEqual(values(map), keyValuePairs(:,2)');
% end
% function testKeys(testCase)
% keyValuePairs = getKeyValuePairs();
% map = exampleMap();
% testCase.verifyEqual(keys(map), keyValuePairs(:,1)');
% end