Mercurial > repos > public > sbplib
comparison MapTest.m @ 417:effd75b113ba feature/better_map
Add tests and fix a bunch of bugs.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 02 Feb 2017 20:49:06 +0100 |
parents | |
children | a6c5e73ff44e |
comparison
equal
deleted
inserted
replaced
416:e97550b5c1e7 | 417:effd75b113ba |
---|---|
1 function tests = MatTest() | |
2 tests = functiontests(localfunctions); | |
3 end | |
4 | |
5 function kvp = getKeyValuePairs() | |
6 kvp = { | |
7 {1,3},1; | |
8 struct(), [1; 3; 4]; | |
9 [1,2; 4 3], struct(); | |
10 'Hej', struct('lol', 6); | |
11 0, 'Nej'; | |
12 }; | |
13 end | |
14 | |
15 function testSetAndGet(testCase) | |
16 keyValuePairs = getKeyValuePairs(); | |
17 | |
18 map = Map(); | |
19 | |
20 % Insert | |
21 for i = 1:length(keyValuePairs) | |
22 map(keyValuePairs{i,1}) = keyValuePairs{i,2}; | |
23 end | |
24 | |
25 % Validate output | |
26 for i = 1:length(keyValuePairs) | |
27 v = map(keyValuePairs{i,1}); | |
28 testCase.verifyEqual(v, keyValuePairs{i,2}); | |
29 end | |
30 end | |
31 | |
32 function map = exampleMap() | |
33 keyValuePairs = getKeyValuePairs(); | |
34 | |
35 map = Map(); | |
36 | |
37 % Insert | |
38 for i = 1:length(keyValuePairs) | |
39 map(keyValuePairs{i,1}) = keyValuePairs{i,2}; | |
40 end | |
41 end | |
42 | |
43 function testLength(testCase) | |
44 map = Map(); | |
45 testCase.verifyEqual(map.length, 0); | |
46 | |
47 map = exampleMap(); | |
48 testCase.verifyEqual(map.length, 5) | |
49 end | |
50 | |
51 | |
52 function testIsKey(testCase) | |
53 map = exampleMap(); | |
54 | |
55 keyValuePairs = getKeyValuePairs(); | |
56 keys = keyValuePairs(:,1); | |
57 | |
58 for i = 1:length(keys) | |
59 testCase.verifyTrue(map.isKey(keys{i})); | |
60 end | |
61 | |
62 notKeys = { | |
63 'hej', | |
64 [], | |
65 1, | |
66 {2,5}, | |
67 }; | |
68 | |
69 for i = 1:length(notKeys) | |
70 testCase.verifyFalse(map.isKey(notKeys{i})); | |
71 end | |
72 end | |
73 | |
74 | |
75 function testRemove(testCase) | |
76 map = exampleMap(); | |
77 | |
78 remove(map, struct()); | |
79 | |
80 testCase.verifyFalse(map.isKey(struct())); | |
81 end | |
82 | |
83 % function testValues(testCase) | |
84 % keyValuePairs = getKeyValuePairs(); | |
85 | |
86 % map = exampleMap(); | |
87 | |
88 % testCase.verifyEqual(values(map), keyValuePairs(:,2)'); | |
89 % end | |
90 | |
91 % function testKeys(testCase) | |
92 % keyValuePairs = getKeyValuePairs(); | |
93 | |
94 % map = exampleMap(); | |
95 | |
96 % testCase.verifyEqual(keys(map), keyValuePairs(:,1)'); | |
97 % end |