MatrixBerryCore
ADiskBasedHashMapTC.m
Go to the documentation of this file.
1 classdef ADiskBasedHashMapTC < mxberry.unittest.TestCase
2  properties
3  map
4  mapFactory
5  rel1
6  rel2
7  testParamList
8  resTmpDir
9  end
10  %
11  methods
12  function self = ADiskBasedHashMapTC(varargin)
13  self = self@mxberry.unittest.TestCase(varargin{:});
14  end
15  end
16  methods (TestMethodTeardown)
17  %
18  function self = tearDown(self)
19  mxberry.io.rmdir(self.resTmpDir,'s');
20  end
21  end
22  properties (MethodSetupParameter,Abstract)
23  argList
24  end
25  methods (TestMethodSetup)
26  function self = setUp(self,argList)
27  self.mapFactory=argList{1};
29  storageRootDir=self.resTmpDir;
30  self.map=self.mapFactory.getInstance('storageBranchKey',...
31  'testBranch','storageLocationRoot',storageRootDir,...
32  argList{2:end});
33  %
34  self.rel1=struct(...
35  'gamma',{{[1 2 3],[1 2 3]}},...
36  'delta',{{[1 2 3], [4 5 6]}},...
37  'epsilon',{{'nu','mu'}},...
38  'zeta',int16([144 1]),...
39  'eta',logical([1 1]),...
40  'theta',{{'nu','nu'}},...
41  'iota',{{'nu','mu'}});
42  %
43  self.rel2=struct(...
44  'gamma',{{[1 2 3],[1 2 44545453]}},...
45  'delta',{{[1 2.676676734 3], [4.23232423423424 5 6]}},...
46  'epsilon',{{'nu','mu'}},...
47  'zeta',int8([431 2121]),...
48  'eta',logical([1 0]),...
49  'theta',{{'nu','nu'}},...
50  'iota',{{'nu','mu'}});
51  %
52  self.testParamList=[argList{2:end},...
53  {'storageLocationRoot',storageRootDir}];
54  self.map.removeAll();
55  end
56  end
57  methods (Test)
58  %
59  function self = test_constructor(self)
60  obj1=self.mapFactory.getInstance();
61  metaClass=metaclass(obj1);
62  inpParamList=mxberry.core.parseparams(...
63  self.testParamList,{'storageLocationRoot'});
64  obj2=self.mapFactory.getInstance('storageLocationRoot',...
65  fileparts(which(metaClass.Name)),inpParamList{:});
66  self.verifyEqual(strcmp(obj1.getStorageLocation(),...
67  obj2.getStorageLocation),true);
68  end
69  %
70  function self=test_putGet(self)
71  rel1=self.rel1; %#ok<*PROP>
72  rel2=self.rel2;
73  %
74  self.map=self.mapFactory.getInstance('storageBranchKey',...
75  'aaa',self.testParamList{:});
76  inpObjList={rel1,rel2};
77  keyList={'rel1','rel2'};
78  %
79  self.map.put(keyList,inpObjList);
80  valueObjList=fliplr(self.map.get(fliplr(keyList),'UniformOutput',false));
81  isEqual=all(cellfun(@isequal,inpObjList,valueObjList));
82  self.verifyEqual(isEqual,true);
83  %
84  map=self.map;
85  map.removeAll();
86  %
87  end
88  %
89  function self=test_longKeyPutGet(self)
90  rel=self.rel1;
91  self.map=self.mapFactory.getInstance('storageBranchKey',...
92  'aaa',self.testParamList{:});
93  map=self.map;
94  map.removeAll();
95  keyStr=repmat('a',namelengthmax); %#ok<NASGU>
96  self.runAndCheckError('map.put({keyStr},{rel})',':wrongInput');
97  self.runAndCheckError('map.get({keyStr})',':wrongInput');
98  %
99  keyStr=repmat('a',1,namelengthmax);
100  map.put({keyStr},{rel});
101  resObj=map.get({keyStr});
102  isEqual=isequal(rel,resObj);
103  self.verifyEqual(true,isEqual);
104  end
105  %
106  function self=test_getKeyList(self)
107  rel1=self.rel1;
108  rel2=self.rel2;
109  self.map=self.mapFactory.getInstance('storageBranchKey',...
110  'aaa',self.testParamList{:});
111  self.map.removeAll();
112  inpObjList={rel1,rel2};
113  keyList={'rel1','rel2'};
114  self.map.put(keyList,inpObjList);
115  isEqual=isequal(sort(keyList),sort(self.map.getKeyList));
116  self.verifyEqual(isEqual,true);
117  self.map.remove('rel2');
118  isEqual=isequal({'rel1'},self.map.getKeyList);
119  self.verifyEqual(isEqual,true);
120  self.map.removeAll();
121  end
122  %
123  function self=test_putGetWithoutCells(self)
124  rel1=self.rel1;
125  self.map=self.mapFactory.getInstance('storageBranchKey',...
126  'aaa',self.testParamList{:});
127  inpObjList={rel1};
128  keyList='rel1';
129  self.map.put(keyList,inpObjList);
130  valueObjList=self.map.get(keyList,'UniformOutput',false);
131  isEqual=all(cellfun(@isequal,inpObjList,valueObjList));
132  self.verifyEqual(isEqual,true);
133  inpObjList=rel1;
134  keyList={'rel1'};
135  self.map.put(keyList,inpObjList);
136  valueObjList=self.map.get(keyList,'UniformOutput',false);
137  inpObjList={inpObjList};
138  isEqual=all(cellfun(@isequal,inpObjList,valueObjList));
139  self.verifyEqual(isEqual,true);
140  end
141  %
142  function self=test_isKeyAndRemove(self)
143  rel1=self.rel1;
144  rel2=self.rel2;
145  rel3=self.rel2;
146  self.map=self.mapFactory.getInstance('storageBranchKey',...
147  'aaa',self.testParamList{:});
148  inpObjList={rel1,rel2,rel3};
149  keyList={'rel1','rel2','rel3'};
150  self.map.put(keyList,inpObjList);
151  self.map.remove(keyList{3});
152  self.verifyEqual(self.map.isKey(keyList{3}),false);
153  inpObjList=inpObjList(1:2);
154  keyList=keyList(1:2);
155  valueObjList=fliplr(self.map.get(fliplr(keyList),...
156  'UniformOutput',false));
157  isEqual=all(cellfun(@isequal,inpObjList,valueObjList));
158  self.verifyEqual(isEqual,true);
159  self.map.removeAll();
160  end
161  %
162  function self=test_removeAll(self)
163  rel1=self.rel1;
164  rel2=self.rel2;
165  inpObjList={rel1,rel2};
166  keyList={'rel1','rel2'};
167  self.map.put(keyList,inpObjList);
168  self.map.remove('rel2');
169  %
170  map1=self.mapFactory.getInstance('storageBranchKey',...
171  'testBranch2',self.testParamList{:});
172  map1.removeAll();
173  map1.put('rel1',rel1);
174  %
175  isThere1=self.map.isKey(keyList);
176  isThere2=map1.isKey(keyList);
177  self.verifyEqual(all(isThere1==isThere2),true);
178  map1.removeAll();
179  isThere=map1.isKey({'rel1'});
180  self.verifyEqual(isThere,false);
181  self.map.removeAll();
182  end
183  %
184  function self=test_getFileNameByKey(self)
185  rel1=self.rel1;
186  self.map=self.mapFactory.getInstance('storageBranchKey',...
187  'aaa',self.testParamList{:});
188  inpObjList={rel1};
189  keyList='rel1';
190  self.map.put(keyList,inpObjList);
191  self.map.getFileNameByKey(keyList);
192  end
193  end
194 end
TMPDATAMANAGER provides a basic functionality for managing temporary data folders, root folder name is determined automatically.
Definition: TmpDataManager.m:5
function repmat(in inpArray, in varargin)
function rmdir(in dirName, in sFlag)
RMDIR removes a directory (optionally recursively)
static function getDirByCallerKey(in keyName)
GETDIRBYCALLERKEY returns a unique temporary directory name based on caller name and optionally based...
function parseparams(in args, in propNameList, in nRegExpected, in nPropExpected)
PARSEPARAMS behaves exactly as a built-in Matlab function apart from the incorrect behavior of Matlab...