From 96ae07c7f61a47483cb5930396da014484ed090d Mon Sep 17 00:00:00 2001 From: Hugo Oliveira Date: Wed, 4 Nov 2020 11:34:14 +1100 Subject: [PATCH] feat(review): rename funcs with snake_case names This renames snake_case functions and fix the calls,signature, and docstrings of them. --- Util/File/{read_until_match.m => readUntilMatch.m} | 12 ++++++------ Util/Random/{random_between.m => randomBetween.m} | 12 ++++++------ Util/Random/{random_names.m => randomNames.m} | 6 +++--- ...om_numeric_typefun.m => randomNumericTypefun.m} | 6 +++--- .../{check_docstrings.m => checkDocstrings.m} | 10 +++++----- ...comment_eval_wrapper.m => commentEvalWrapper.m} | 8 ++++---- .../{test_docstring.m => testDocstring.m} | 14 +++++++------- 7 files changed, 34 insertions(+), 34 deletions(-) rename Util/File/{read_until_match.m => readUntilMatch.m} (83%) rename Util/Random/{random_between.m => randomBetween.m} (80%) rename Util/Random/{random_names.m => randomNames.m} (86%) rename Util/Random/{random_numeric_typefun.m => randomNumericTypefun.m} (81%) rename Util/TestUtils/{check_docstrings.m => checkDocstrings.m} (80%) rename Util/TestUtils/{comment_eval_wrapper.m => commentEvalWrapper.m} (87%) rename Util/TestUtils/{test_docstring.m => testDocstring.m} (73%) diff --git a/Util/File/read_until_match.m b/Util/File/readUntilMatch.m similarity index 83% rename from Util/File/read_until_match.m rename to Util/File/readUntilMatch.m index 9a7b4b818..ed221293b 100644 --- a/Util/File/read_until_match.m +++ b/Util/File/readUntilMatch.m @@ -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. @@ -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) % diff --git a/Util/Random/random_between.m b/Util/Random/randomBetween.m similarity index 80% rename from Util/Random/random_between.m rename to Util/Random/randomBetween.m index c3dc9d6f2..12dfc3359 100644 --- a/Util/Random/random_between.m +++ b/Util/Random/randomBetween.m @@ -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) % @@ -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))); % % diff --git a/Util/Random/random_names.m b/Util/Random/randomNames.m similarity index 86% rename from Util/Random/random_names.m rename to Util/Random/randomNames.m index aeadd5ef5..85ab39715 100644 --- a/Util/Random/random_names.m +++ b/Util/Random/randomNames.m @@ -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. @@ -15,7 +15,7 @@ % % Example: % -% rnames = random_names(1); +% rnames = randomNames(1); % assert(iscell(rnames)) % assert(~isempty(rnames)) % assert(~isempty(rnames{1})) diff --git a/Util/Random/random_numeric_typefun.m b/Util/Random/randomNumericTypefun.m similarity index 81% rename from Util/Random/random_numeric_typefun.m rename to Util/Random/randomNumericTypefun.m index 23bae581a..0f1c09db8 100644 --- a/Util/Random/random_numeric_typefun.m +++ b/Util/Random/randomNumericTypefun.m @@ -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. % @@ -13,7 +13,7 @@ % % Example: % -% rntype = random_numeric_typefun(1); +% rntype = randomNumericTypefun(1); % assert(length(rntype)==1); % assert(isfunctionhandle(rntype{1})); % diff --git a/Util/TestUtils/check_docstrings.m b/Util/TestUtils/checkDocstrings.m similarity index 80% rename from Util/TestUtils/check_docstrings.m rename to Util/TestUtils/checkDocstrings.m index f693dc5e0..2416b835c 100644 --- a/Util/TestUtils/check_docstrings.m +++ b/Util/TestUtils/checkDocstrings.m @@ -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. % @@ -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)); % @@ -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 @@ -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); diff --git a/Util/TestUtils/comment_eval_wrapper.m b/Util/TestUtils/commentEvalWrapper.m similarity index 87% rename from Util/TestUtils/comment_eval_wrapper.m rename to Util/TestUtils/commentEvalWrapper.m index efd51e1b0..2bf2b5d30 100644 --- a/Util/TestUtils/comment_eval_wrapper.m +++ b/Util/TestUtils/commentEvalWrapper.m @@ -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 @@ -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:')); % diff --git a/Util/TestUtils/test_docstring.m b/Util/TestUtils/testDocstring.m similarity index 73% rename from Util/TestUtils/test_docstring.m rename to Util/TestUtils/testDocstring.m index 398d64ec2..95fbdca71 100644 --- a/Util/TestUtils/test_docstring.m +++ b/Util/TestUtils/testDocstring.m @@ -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. % @@ -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)) % @@ -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);