MatrixBerryCore
mlunit_test_string.m
Go to the documentation of this file.
1 classdef mlunit_test_string < matlab.unittest.TestCase
2  properties
3  end
4 
5  methods
6  function self = mlunit_test_string(varargin)
7  self = self@matlab.unittest.TestCase(varargin{:});
8  end
9  %
10  end
11  methods (Test)
12  %
13  function test_shortcapstr(self)
14  check('one2oneContr','o2oC');
15  check('plainIV','pIV');
16  check('one2oneContr_plainIV','o2oC_pIV');
17  check('vertical spread','vs');
18  %
19  function check(inpStr,expStr)
20  import mxberry.core.string.shortcapstr;
21  resStr=shortcapstr(inpStr);
22  self.verifyEqual(resStr,expStr);
23  end
24  end
25  function self=test_splitpart(self)
26  inpStr='aaa..bbb..';
27  try
28  mxberry.core.string.splitpart(inpStr,'..',4);
29  self.verifyEqual(true,false);
30  catch meObj
31  self.verifyEqual(~isempty(strfind(meObj.identifier,':wrongInput')),true);
32  end
33  %
34  resStr=mxberry.core.string.splitpart(inpStr,'..',3);
35  self.verifyEqual('',resStr);
36  %
37  self.verifyEqual(mxberry.core.string.splitpart(inpStr,'..',2),'bbb');
38  self.verifyEqual(mxberry.core.string.splitpart(inpStr,'..','first'),'aaa');
39  inpStr='aaa';
40  self.verifyEqual(mxberry.core.string.splitpart(inpStr,'..','first'),'aaa');
41  self.verifyEqual(mxberry.core.string.splitpart(inpStr,'..','last'),'aaa');
42  end
43  function self=test_catwithsep(self)
44  outStr=mxberry.core.string.catwithsep({'aaa','bbb'},'__');
45  self.verifyEqual(outStr,'aaa__bbb');
46  end
47  function self=test_catcellstrwithsep(self)
48  outCVec=mxberry.core.string.catcellstrwithsep(...
49  {'aa','bb';'aaa','bbb';'a','b'},'-');
50  self.verifyEqual(true,...
51  isequal(outCVec,{'aa-bb';'aaa-bbb';'a-b'}));
52  end
53  function test_sepcellstrbysep(self)
54  inpCMat={'aa','bb';'aaa','bbb';'a','b'};
55  sepStr='-';
56  check();
57  sepStr=' ';
58  check();
59  sepStr='-+';
60  check();
61  %
62  function check()
63  outCVec=mxberry.core.string.catcellstrwithsep(...
64  inpCMat,sepStr);
65  %
66  resCMat=mxberry.core.string.sepcellstrbysep(outCVec,sepStr);
67  self.verifyEqual(true,isequal(resCMat,inpCMat));
68  end
69  end
70  end
71 end
function sepcellstrbysep(in inpCVec, in sepStr)
SEPCELLSTRBYSEP splits elements of input cell column vector of strings using a specified separator an...
function catcellstrwithsep(in inpCMat, in sepStr)
CATCELLSTRWITHSEP contatenates columns of input cell matrix of strings using a specified separator an...
function splitpart(in inpStr, in delimStr, in fieldNum)
SPLITPART splits string on delimiter and return the given field (counting from one) ...
function shortcapstr(in longName)
function catwithsep(in inpStrList, in sepStr)
CATWITHSEP concatenates input cell array of strings inserting a specified separator between the strin...