From: Charlotte HECQUET Date: Fri, 26 Apr 2013 12:47:46 +0000 (+0200) Subject: * Bug #8687 fixed - typeof() function failed on uint8, depending on the format (... X-Git-Tag: 5.5.0-beta-1~734 X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=commitdiff_plain;h=f34b75a4aa1bbc1f488acf1ab2470e056f7fcd1e * Bug #8687 fixed - typeof() function failed on uint8, depending on the format (+ unit test added). Change-Id: I1d599d5c561a0f76a31de3ef3312e368b33758ff --- diff --git a/scilab/CHANGES_5.5.X b/scilab/CHANGES_5.5.X index 539f3a6..4b2b09c 100644 --- a/scilab/CHANGES_5.5.X +++ b/scilab/CHANGES_5.5.X @@ -108,6 +108,8 @@ Bug fixes * Bug #8680 fixed - Output argument "end" of the regexp function has been changed. +* Bug #8687 fixed - typeof() function failed on uint8, depending on the format (+ unit test added). + * Bug #8824 fixed - taucs_chfact returned a segfault (not the case in mode nwni). * Bug #8862 fixed - mget and mput couldn't read and write 64 bit data from 78 diff --git a/scilab/modules/core/macros/typeof.sci b/scilab/modules/core/macros/typeof.sci index f81bbdf..756ceb6 100644 --- a/scilab/modules/core/macros/typeof.sci +++ b/scilab/modules/core/macros/typeof.sci @@ -8,57 +8,62 @@ // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt function [tf]=typeof(object) -if exists("object","local")==0 then - error(msprintf(_("%s: Wrong value for input argument #%d: Defined variable expected.\n"),"typeof", 1)) -end -select type(object) -case 1 then tf='constant'; -case 2 then tf='polynomial'; -case 4 then tf='boolean'; -case 5 then tf='sparse'; -case 6 then tf='boolean sparse'; -case 7 then tf='Matlab sparse'; -case 8 then - it=inttype(object) - tf='' - if int(it/10)==1 then - tf='u' - it=modulo(it,10) - end - tf=tf+'int'+string(8*it) -case 9 then tf='handle'; -case 10 then tf='string'; -case 11 then tf='function'; -case 13 then tf='function'; -case 14 then tf='library'; -case 128 then tf='pointer'; -case 129 then tf='size implicit'; -case 15 then tf='list'; -case 16 then - o1=object(1); - select o1(1) - case 'r' then - tf='rational'; - case 'lss' then - tf='state-space'; - else - tf=o1(1) - end -case 17 then - o1=getfield(1,object) - select o1(1) - case 'hm' then - tf='hypermat'; - else - tf=o1(1) - end - else - [tp,nm]=typename() - k=find(tp==type(object)) - if k<>[] then - tf=nm(k(1)) - else - tf='unknown'; - end - end + if exists("object","local")==0 then + error(msprintf(_("%s: Wrong value for input argument #%d: Defined variable expected.\n"),"typeof", 1)) + end + select type(object) + case 1 then tf='constant'; + case 2 then tf='polynomial'; + case 4 then tf='boolean'; + case 5 then tf='sparse'; + case 6 then tf='boolean sparse'; + case 7 then tf='Matlab sparse'; + case 8 then + it=inttype(object) + tf='' + f=format(); + format('v'); + if int(it/10)==1 then + tf='u' + it=modulo(it,10) + end + tf=tf+'int'+string(8*it); + if f(1) == 0 then + format('e'); + end + case 9 then tf='handle'; + case 10 then tf='string'; + case 11 then tf='function'; + case 13 then tf='function'; + case 14 then tf='library'; + case 128 then tf='pointer'; + case 129 then tf='size implicit'; + case 15 then tf='list'; + case 16 then + o1=object(1); + select o1(1) + case 'r' then + tf='rational'; + case 'lss' then + tf='state-space'; + else + tf=o1(1) + end + case 17 then + o1=getfield(1,object) + select o1(1) + case 'hm' then + tf='hypermat'; + else + tf=o1(1) + end + else + [tp,nm]=typename() + k=find(tp==type(object)) + if k<>[] then + tf=nm(k(1)) + else + tf='unknown'; + end + end endfunction diff --git a/scilab/modules/core/tests/nonreg_tests/bug_8687.dia.ref b/scilab/modules/core/tests/nonreg_tests/bug_8687.dia.ref new file mode 100644 index 0000000..f7e448b --- /dev/null +++ b/scilab/modules/core/tests/nonreg_tests/bug_8687.dia.ref @@ -0,0 +1,21 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- Non-regression test for bug 8687 --> +// +// <-- CLI SHELL MODE --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=8687 +// +// <-- Short Description --> +// Typeof() function fails on uint8, depending on the format. +format("e",10); +f_ref=format(); +assert_checkequal(typeof(uint8(1:4)),"uint8"); +f_res=format(); +assert_checkequal(f_res,f_ref); diff --git a/scilab/modules/core/tests/nonreg_tests/bug_8687.tst b/scilab/modules/core/tests/nonreg_tests/bug_8687.tst new file mode 100644 index 0000000..0af26b0 --- /dev/null +++ b/scilab/modules/core/tests/nonreg_tests/bug_8687.tst @@ -0,0 +1,22 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- Non-regression test for bug 8687 --> +// +// <-- CLI SHELL MODE --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=8687 +// +// <-- Short Description --> +// Typeof() function fails on uint8, depending on the format. + +format("e",10); +f_ref=format(); +assert_checkequal(typeof(uint8(1:4)),"uint8"); +f_res=format(); +assert_checkequal(f_res,f_ref); diff --git a/scilab/modules/core/tests/unit_tests/typeof.dia.ref b/scilab/modules/core/tests/unit_tests/typeof.dia.ref new file mode 100644 index 0000000..c4757e9 --- /dev/null +++ b/scilab/modules/core/tests/unit_tests/typeof.dia.ref @@ -0,0 +1,94 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- TEST WITH GRAPHICS --> +// unit test for typeof() +// constant +assert_checkequal(typeof(1),"constant"); +assert_checkequal(typeof([1,1]),"constant"); +assert_checkequal(typeof([1;1]),"constant"); +assert_checkequal(typeof([1,1;1,1]),"constant"); +assert_checkequal(typeof([1+%i,1+%i;1,1]),"constant"); +// polynomial +assert_checkequal(typeof(poly(0,"s")),"polynomial"); +// boolean +assert_checkequal(typeof(%t),"boolean"); +assert_checkequal(typeof([%t,%t;%f,%f]),"boolean"); +assert_checkequal(typeof("s"=="s"),"boolean"); +// sparse +assert_checkequal(typeof(sparse([0,1,0,1:1,0,1,0])),"sparse"); +// boolean sparse +assert_checkequal(typeof(sparse([1,1;2,2;3,3],[%t,%t,%t])),"boolean sparse"); +// Matlab sparse +X=sparse(rand(2,2)); Y=mtlb_sparse(X); +assert_checkequal(typeof(Y),"Matlab sparse"); +// int +assert_checkequal(typeof(int8(1:4)),"int8"); +assert_checkequal(typeof(uint8(1:4)),"uint8"); +assert_checkequal(typeof(int16(1:4)),"int16"); +assert_checkequal(typeof(uint16(1:4)),"uint16"); +assert_checkequal(typeof(int32(1:4)),"int32"); +assert_checkequal(typeof(uint32(1:4)),"uint32"); +format("e"); +assert_checkequal(typeof(uint8(1:4)),"uint8"); // bug 8687 +format("v"); +// handle +plot(); +f=gcf(); +assert_checkequal(typeof(f),"handle"); +a=gca(); +assert_checkequal(typeof(a),"handle"); +e=gce(); +assert_checkequal(typeof(e),"handle"); +assert_checkequal(typeof(a.children(1)),"handle"); +close +// string +assert_checkequal(typeof("s"),"string"); +assert_checkequal(typeof("string"),"string"); +assert_checkequal(typeof(["s","s"]),"string"); +// function +deff('[x]=myplus(y,z)','x=y+z'); +assert_checkequal(typeof(myplus),"function"); +// library +assert_checkequal(typeof(elementary_functionslib),"library"); +assert_checkequal(typeof(corelib),"library"); +// pointer +a=rand(5,5);b=rand(5,1);A=sparse(a); +[h,rk]=lufact(A); +x=lusolve(h,b);a*x-b; +ludel(h); +assert_checkequal(typeof(h),"pointer"); +// size implicit +assert_checkequal(typeof(1:1:$), "size implicit"); +// list +assert_checkequal(typeof(list(1,2)),"list"); +t = tlist(["listtype","field1","field2"], [], []); +assert_checkequal(typeof(t),t(1)(1)); +M = mlist(['V','name','value'],['a','b','c'],[1 2 3]); +M1=getfield(1,M); +assert_checkequal(typeof(M),M1(1)); +// rational, state-space +assert_checkequal(typeof(1/poly(0,"s")),"rational"); +A=[0,1;0,0];B=[1;1];C=[1,1]; +S1=syslin('c',A,B,C); +assert_checkequal(typeof(S1),"state-space"); +S2=syslin('d',A,B,C); +assert_checkequal(typeof(S2),"state-space"); +S3=syslin(1,A,B,C); +assert_checkequal(typeof(S3),"state-space"); +assert_checkequal(typeof(tf2ss(1/poly(0,"s"))),"state-space"); +// hypermat +assert_checkequal(typeof(hypermat([2 3 2 2],1:24)),"hypermat"); +A=[1,2,3;4,5,6]; +A(:,:,2)=[1,2,3;4,5,6]; +assert_checkequal(typeof(A),"hypermat"); +// fptr +assert_checkequal(typeof(abs),"fptr"); +// cell +assert_checkequal(typeof(cell(3)),"ce"); +//structure +assert_checkequal(typeof(struct('jour',25,'mois','DEC','annee',2006)),"st"); diff --git a/scilab/modules/core/tests/unit_tests/typeof.tst b/scilab/modules/core/tests/unit_tests/typeof.tst new file mode 100644 index 0000000..a127ad2 --- /dev/null +++ b/scilab/modules/core/tests/unit_tests/typeof.tst @@ -0,0 +1,113 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- TEST WITH GRAPHICS --> +// unit test for typeof() + +// constant +assert_checkequal(typeof(1),"constant"); +assert_checkequal(typeof([1,1]),"constant"); +assert_checkequal(typeof([1;1]),"constant"); +assert_checkequal(typeof([1,1;1,1]),"constant"); +assert_checkequal(typeof([1+%i,1+%i;1,1]),"constant"); + +// polynomial +assert_checkequal(typeof(poly(0,"s")),"polynomial"); + +// boolean +assert_checkequal(typeof(%t),"boolean"); +assert_checkequal(typeof([%t,%t;%f,%f]),"boolean"); +assert_checkequal(typeof("s"=="s"),"boolean"); + +// sparse +assert_checkequal(typeof(sparse([0,1,0,1:1,0,1,0])),"sparse"); + +// boolean sparse +assert_checkequal(typeof(sparse([1,1;2,2;3,3],[%t,%t,%t])),"boolean sparse"); + +// Matlab sparse +X=sparse(rand(2,2)); Y=mtlb_sparse(X); +assert_checkequal(typeof(Y),"Matlab sparse"); + +// int +assert_checkequal(typeof(int8(1:4)),"int8"); +assert_checkequal(typeof(uint8(1:4)),"uint8"); +assert_checkequal(typeof(int16(1:4)),"int16"); +assert_checkequal(typeof(uint16(1:4)),"uint16"); +assert_checkequal(typeof(int32(1:4)),"int32"); +assert_checkequal(typeof(uint32(1:4)),"uint32"); +format("e"); +assert_checkequal(typeof(uint8(1:4)),"uint8"); // bug 8687 +format("v"); + +// handle +plot(); +f=gcf(); +assert_checkequal(typeof(f),"handle"); +a=gca(); +assert_checkequal(typeof(a),"handle"); +e=gce(); +assert_checkequal(typeof(e),"handle"); +assert_checkequal(typeof(a.children(1)),"handle"); +close + +// string +assert_checkequal(typeof("s"),"string"); +assert_checkequal(typeof("string"),"string"); +assert_checkequal(typeof(["s","s"]),"string"); + +// function +deff('[x]=myplus(y,z)','x=y+z'); +assert_checkequal(typeof(myplus),"function"); + +// library +assert_checkequal(typeof(elementary_functionslib),"library"); +assert_checkequal(typeof(corelib),"library"); + +// pointer +a=rand(5,5);b=rand(5,1);A=sparse(a); +[h,rk]=lufact(A); +x=lusolve(h,b);a*x-b; +ludel(h); +assert_checkequal(typeof(h),"pointer"); + +// size implicit +assert_checkequal(typeof(1:1:$), "size implicit"); + +// list +assert_checkequal(typeof(list(1,2)),"list"); +t = tlist(["listtype","field1","field2"], [], []); +assert_checkequal(typeof(t),t(1)(1)); +M = mlist(['V','name','value'],['a','b','c'],[1 2 3]); +M1=getfield(1,M); +assert_checkequal(typeof(M),M1(1)); + +// rational, state-space +assert_checkequal(typeof(1/poly(0,"s")),"rational"); +A=[0,1;0,0];B=[1;1];C=[1,1]; +S1=syslin('c',A,B,C); +assert_checkequal(typeof(S1),"state-space"); +S2=syslin('d',A,B,C); +assert_checkequal(typeof(S2),"state-space"); +S3=syslin(1,A,B,C); +assert_checkequal(typeof(S3),"state-space"); +assert_checkequal(typeof(tf2ss(1/poly(0,"s"))),"state-space"); + +// hypermat +assert_checkequal(typeof(hypermat([2 3 2 2],1:24)),"hypermat"); +A=[1,2,3;4,5,6]; +A(:,:,2)=[1,2,3;4,5,6]; +assert_checkequal(typeof(A),"hypermat"); + +// fptr +assert_checkequal(typeof(abs),"fptr"); + +// cell +assert_checkequal(typeof(cell(3)),"ce"); + +//structure +assert_checkequal(typeof(struct('jour',25,'mois','DEC','annee',2006)),"st");