Skip to content

Commit

Permalink
feat(review): rename funcs with snake_case names
Browse files Browse the repository at this point in the history
This renames snake_case functions and fix
the calls,signature, and docstrings of them.
  • Loading branch information
ocehugo committed Nov 4, 2020
1 parent a07372f commit 96ae07c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions Util/File/read_until_match.m → Util/File/readUntilMatch.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [clines, number_of_lines] = read_until_match(fid, pattern, is_regex, preallocsize)
%function [clines, number_of_lines] = read_until_match(fid, pattern, is_regex, preallocsize)
function [clines, number_of_lines] = readUntilMatch(fid, pattern, is_regex, preallocsize)
%function [clines, number_of_lines] = readUntilMatch(fid, pattern, is_regex, preallocsize)
%
% Read a file, line by line, until a pattern is found, returning
% all lines read and the total number of lines.
Expand All @@ -21,28 +21,28 @@
%
% Example:
% % create
% tmpfile = [tempdir 'test_read_until_match.txt'];
% tmpfile = [tempdir 'test_readUntilMatch.txt'];
% fid = fopen(tmpfile,'w');
% fprintf(fid,'%c\n%c\n%c\n',['a','X','c']);
% fclose(fid);
%
% % full read
% fid = fopen(tmpfile,'r');
% [text,lc] = read_until_match(fid,'X');
% [text,lc] = readUntilMatch(fid,'X');
% assert(isequal(text{1},'a'))
% assert(isequal(text{2},'X'))
% assert(lc==2)
%
% % partial read
% fid = fopen(tmpfile,'r');
% [text,lc] = read_until_match(fid,'a');
% [text,lc] = readUntilMatch(fid,'a');
% assert(isequal(text{1},'a'))
% assert(length(text)==1)
% assert(lc==1)
%
% % empty case
% fid = fopen(tmpfile,'r');
% [text,lc] = read_until_match(fid,'Z');
% [text,lc] = readUntilMatch(fid,'Z');
% assert(isempty(text));
% assert(lc==4)
%
Expand Down
12 changes: 6 additions & 6 deletions Util/Random/random_between.m → Util/Random/randomBetween.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [arr] = random_between(a,b,n,type)
% function [arr] = random_between(a,b,n,type)
function [arr] = randomBetween(a,b,n,type)
% function [arr] = randomBetween(a,b,n,type)
%
% Draw n numbers from the a-b range (inclusive)
%
Expand All @@ -17,19 +17,19 @@
%
% Example:
% %from: https://www.mathworks.com/help/matlab/math/floating-point-numbers-within-specific-range.html
% arr=random_between(0,1,10);
% arr=randomBetween(0,1,10);
% assert(min(arr)>0 && max(arr)<1)
%
% % random int
% arr=random_between(0,5,100,'int');
% arr=randomBetween(0,5,100,'int');
% assert(all(double(int64(arr))==arr))
%
% % random logical
% arr=random_between(0,1,100,'logical');
% arr=randomBetween(0,1,100,'logical');
% assert(min(arr)==0 && max(arr)==1)
%
% % random constant
% arr=random_between(1,1,10,'int');
% arr=randomBetween(1,1,10,'int');
% assert(isequal(arr,ones(1,10)));
%
%
Expand Down
6 changes: 3 additions & 3 deletions Util/Random/random_names.m → Util/Random/randomNames.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function rnames = random_names(n, len)
%function rnames = random_names(n, len)
function rnames = randomNames(n, len)
%function rnames = randomNames(n, len)
%
% Create `n` random names in a cell, where each
% name is `len` limited.
Expand All @@ -15,7 +15,7 @@
%
% Example:
%
% rnames = random_names(1);
% rnames = randomNames(1);
% assert(iscell(rnames))
% assert(~isempty(rnames))
% assert(~isempty(rnames{1}))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function rntype = random_numeric_typefun(n)
%function rntype= random_numeric_typefun(n)
function rntype = randomNumericTypefun(n)
%function rntype= randomNumericTypefun(n)
%
% Create `n` random numeric function handles in a cell.
%
Expand All @@ -13,7 +13,7 @@
%
% Example:
%
% rntype = random_numeric_typefun(1);
% rntype = randomNumericTypefun(1);
% assert(length(rntype)==1);
% assert(isfunctionhandle(rntype{1}));
%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [ok, wrong_files] = check_docstrings(folder)
% function [ok, wrong_files] = check_docstrings(folder)
function [ok, wrong_files] = checkDocstrings(folder)
% function [ok, wrong_files] = checkDocstrings(folder)
%
% Check all matlab source file IMOS docstrings in a folder.
%
Expand All @@ -15,7 +15,7 @@
% Example:
%
% folder = [toolboxRootPath 'Util/TestUtils']
% [ok,wrong_files] = check_docstrings(folder);
% [ok,wrong_files] = checkDocstrings(folder);
% assert(ok)
% assert(isempty(wrong_files));
%
Expand All @@ -27,7 +27,7 @@
files = rdir(folder);
srcfiles = cell2mat(cellfun(@is_matlab,files,'UniformOutput',false));
matlab_files = files(srcfiles);
self_calling = contains(matlab_files,'check_docstrings.m');
self_calling = contains(matlab_files,'checkDocstrings');
if any(self_calling)
matlab_files(self_calling) = [];
end
Expand All @@ -37,7 +37,7 @@
for k=1:nfiles
file = matlab_files{k};
fprintf('%s: checking %s\n',mfilename,file)
[oks(k),~] = test_docstring(file);
[oks(k),~] = testDocstring(file);
end

failed = ~all(oks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [ok, msg] = comment_eval_wrapper(cell_of_strings, line_offset, dbreak)
%function [ok, msg] = comment_eval_wrapper(cell_of_strings)
function [ok, msg] = commentEvalWrapper(cell_of_strings, line_offset, dbreak)
%function [ok, msg] = commentEvalWrapper(cell_of_strings)
%
% a closure to evaluate commented string entries
% inside a cell. The function stops at the first
Expand All @@ -20,12 +20,12 @@
%
% Example:
%
% [ok,msg] = comment_eval_wrapper({'%a=10;','%b=a-10.;'});
% [ok,msg] = commentEvalWrapper({'%a=10;','%b=a-10.;'});
% assert(ok)
% assert(isempty(msg))
%
% % Manual testing below, since nested calls will trigger a fail
% % [ok,msg] = comment_eval_wrapper({'%a?x=10;'});
% % [ok,msg] = commentEvalWrapper({'%a?x=10;'});
% % assert(~ok)
% % assert(contains(msg,'Error:'));
%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [ok, msg] = test_docstring(filename,dbreak)
% function [ok,msg] = test_docstring(filename,dbreak)
function [ok, msg] = testDocstring(filename,dbreak)
% function [ok,msg] = testDocstring(filename,dbreak)
%
% Test the Example block of an IMOS source code matlab file.
%
Expand All @@ -20,10 +20,10 @@
%
% Example:
% % test used functions
% [ok,msg] = test_docstring('comment_eval_wrapper');
% [ok,msg] = testDocstring('commentEvalWrapper');
% assert(ok)
% assert(isempty(msg))
% [ok,msg] = test_docstring('read_until_match');
% [ok,msg] = testDocstring('readUntilMatch');
% assert(ok)
% assert(isempty(msg))
%
Expand Down Expand Up @@ -52,17 +52,17 @@
%TODO: when licenses are removed from all source files, include the one below.
%docstring_end_re = '^(?!\s?%).+';

[docstring_text, block_start_line] = read_until_match(fid, docstring_start_re, use_regex);
[docstring_text, block_start_line] = readUntilMatch(fid, docstring_start_re, use_regex);
if isempty(docstring_text)
ok = false;
msg = sprintf('No docstring Example block found in %s',filename);
return
end

text_to_evaluate = read_until_match(fid, docstring_end_re, use_regex);
text_to_evaluate = readUntilMatch(fid, docstring_end_re, use_regex);
text_to_evaluate = text_to_evaluate(1:end-1); % remove docstring_end_re match

[ok, msg] = comment_eval_wrapper(text_to_evaluate, block_start_line, dbreak);
[ok, msg] = commentEvalWrapper(text_to_evaluate, block_start_line, dbreak);

if ~ok
[~, file] = fileparts(filename);
Expand Down

0 comments on commit 96ae07c

Please sign in to comment.