Skip to content

Commit

Permalink
Add tests to increase code coverage
Browse files Browse the repository at this point in the history
Still I expect moderate coverage, since:

 • I don't know how to test the +paletteditor functions, since they
   feature a GUI... it might be impossible to include them.

 • I don't really know how to test cprintf, being its functionality
   bound to the Java runtime of GUI matlab... again, what to do?

 • Still missing some genuine spots (e.g. diverging_cmap is untested).
  • Loading branch information
beddalumia committed Aug 19, 2022
1 parent 2a6d6fc commit 89ea53d
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 10 deletions.
12 changes: 6 additions & 6 deletions +rgb/X11.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
% Make sure the function can load the data, rebuild it if necessary
disp 'Cannot load X11/rgb database. I will try to import from local X11.txt file now.'
X11_install
% Load data created by xkcd_install
% Load data created by X11_install
load([here,'/private/X11_rgb_data.mat'],'namelist','rgblist');
end

Expand Down Expand Up @@ -166,7 +166,7 @@

end

%% Web-installation subfunction:
%% installation subfunction:

function X11_install

Expand All @@ -186,13 +186,13 @@
if ~exist('X11.txt','file')
disp 'Cannot find X11.txt file.'
try
%websave('rgb.txt','https://X11.com/color/rgb.txt');
% websave('rgb.txt','https://do-not-know-a-url.txt');
catch
try
%urlwrite('https://X11.com/color/rgb.txt','rgb.txt'); %#ok <GNU>
% urlwrite('https://do-not-know-a-url.txt,'rgb.txt'); %#ok <GNU>
catch
disp('Having trouble downloading the txt file. You''ll need to download it manually')
disp('from http://X11.com/color/rgb.txt and place it in current folder. Then run again.')
disp('Having trouble finding the txt file. You''ll need to retrieve it manually')
disp('from your *nix system and place it in current folder. Then run again.')
return
end
end
Expand Down
23 changes: 23 additions & 0 deletions .test/test_X11_update.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
X11_update()

function X11_update()

disp('TESTING upgrade of X11 colors [rgb.X11]')

colorlab.enter
close all
clear

here = pwd;
root = erase(fileparts(mfilename('fullpath')),'.test');
cd(root)
cd('+rgb/private')
delete('X11_rgb_data.mat')
cd(here)

rgb.X11('white');

disp('>> All good!')
disp('------------')

end
48 changes: 44 additions & 4 deletions .test/test_all_docstrings.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,49 @@ function all_docstrings()
close all
clear

disp COLORNAMES

disp colorshow
import rgb.*
X11('show')
xkcd('show')
disp '...done!'

disp X11
X11('navyblue')
X11('SpringGreen','CornflowerBlue','sapphire','radioactive green')
x = -pi:.1:pi;
y = cos(x);
plot(x,y,'linewidth',4,'color',X11('CornflowerBlue'))
hold on
plot(x,y-1,'*','color',X11('Brown1'))
plot(x,y-2,'linewidth',4,'color',X11('SeaGreen'))
legend('cornflower','brown1 (wtf?!)','SeaGreen')
set(gca,'color',X11('seashell'))
text(-1,-2,'This text is chocolate (wtf?!).','fontweight','bold','color',...
X11('chocolate'));
close all
disp '...done!'

disp xkcd
xkcd('baby blue')
xkcd('wintergreen','sunflower yellow','sapphire','radioactive green')
x = -pi:.1:pi;
y = cos(x);
plot(x,y,'linewidth',4,'color',xkcd('cornflower'))
hold on
plot(x,y-1,'*','color',xkcd('strawberry'))
plot(x,y-2,'linewidth',4,'color',xkcd('puke green'))
legend('cornflower','strawberry','puke green')
set(gca,'color',xkcd('eggshell'))
text(-1,-2,'This text is burnt orange.','fontweight','bold','color',...
xkcd('burnt orange'));
close all
disp '...done!'

disp('>> All good!')
disp('------------')

disp COLORTOOLS

disp view_color
Expand Down Expand Up @@ -130,7 +173,7 @@ function all_docstrings()
surfc(X,Y,Z)
cmap = palette.cubehelix([],0.7,-0.7,2,1,[0.1,0.9],[0.1,0.9]);
colormap(cmap)
preset_palette(@palette.cubehelix, 3,-0.5,1.5,1); % preselect the map.
preset_palette(@palette.cubehelix,[3,-0.5,1.5,1]); % preselect the map.
cmap = palette.cubehelix([],3,-0.5,1.5,1);
assert(isequal(cmap,preset_palette))
clear; close
Expand Down Expand Up @@ -161,9 +204,6 @@ function all_docstrings()
close all force % brewer is nasty
disp '...done!'

disp('>> All good!')
disp('------------')

end

function names = matplotlib_names()
Expand Down
19 changes: 19 additions & 0 deletions .test/test_cmocean_negative.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmocean_negative()

function cmocean_negative()

disp('TESTING negative lightness [palette.cmocean]')

colorlab.enter
close all
clear

map1 = get_palette('algae',256,'negative');
map2 = palette.cmocean('algae','negative');

assert(isequal(map1,map2))

disp('>> All good!')
disp('------------')

end
20 changes: 20 additions & 0 deletions .test/test_crameri_update.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
upgrade_crameri()

function upgrade_crameri()

disp('TESTING upgrading of crameri [private function]')

here = pwd;
root = erase(fileparts(mfilename('fullpath')),'.test');
cd(root)
cd('crameri')
disp('Release 7 [zenodo::5501399]')
crameri_update(7,5501399)
disp('Release 6 [zenodo::4153113]')
crameri_update('6','4153113')
cd(here)

disp('>> All good!')
disp('------------')

end
14 changes: 14 additions & 0 deletions .test/test_install.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
install()

function install()

disp('TESTING (un)install procedures [+colorlab]')

colorlab.vista
colorlab.enter
colorlab.leave

disp('>> All good!')
disp('------------')

end
23 changes: 23 additions & 0 deletions .test/test_xkcd_update.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
xkcd_update()

function xkcd_update()

disp('TESTING upgrade of xkcd colors [rgb.xkcd]')

colorlab.enter
close all
clear

here = pwd;
root = erase(fileparts(mfilename('fullpath')),'.test');
cd(root)
cd('+rgb/private')
delete('xkcd_rgb_data.mat')
cd(here)

rgb.xkcd('white');

disp('>> All good!')
disp('------------')

end

0 comments on commit 89ea53d

Please sign in to comment.