1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2007-2008 - INRIA - Allan CORNET <allan.cornet@inria.fr>
4//
5//  This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// <-- CLI SHELL MODE -->
8// =============================================================================
9// unit tests length
10// =============================================================================
11// = Empty matrix ==============================================================
12l = length([]);
13if (l <> 0) then bugmes();quit;end;
14// = integer ===================================================================
15N = 321;
16l = length(N);
17if (l <> 1) then bugmes();quit;end;
18// = Matrix of integer =========================================================
19N = 321;
20M = 32;
21PARAMIN = [N,M;M,N];
22l = length(PARAMIN);
23if (l <> size(PARAMIN,"*") ) then bugmes();quit;end;
24// = String ====================================================================
25STRING = "Scilab";
26l = length(STRING);
27if (l <> 6 ) then bugmes();quit;end;
28// = Matrix of Strings =========================================================
29STRING1 = "Scilab";
30STRING2 = "Strings";
31PARAMIN = [STRING1,STRING2;STRING2,STRING1];
32l = length(PARAMIN);
33LS1 = length(STRING1);
34LS2 = length(STRING2);
35if (LS1 <> 6 ) then bugmes();quit;end;
36if (LS2 <> 7 ) then bugmes();quit;end;
37if (l <> [ LS1, LS2; LS2 , LS1 ]) then bugmes();quit;end
38// = List (of strings) =========================================================
39STRING1 = "Scilab";
40STRING2 = "5.x";
41m=list();
42m(1)=STRING1;
43m(2)=STRING2;
44if length(m) <> 2  then bugmes();quit;end
45// = List (mixed) ==============================================================
46l = list(1,["a" "b"],[1 2 3 4],%T);
47if length(l) <> 4  then bugmes();quit;end
48// = mlist =====================================================================
49M = mlist(["V","name","value"],["a","b","c"],[1 2 3]);
50if length(M) <> 3  then bugmes();quit;end
51// = tlist =====================================================================
52Sys=tlist(["lss";"A";"B";"C";"D";"X0";"dt"],1,2,3,4,5,"c");
53if length(Sys) <> 7  then bugmes();quit;end
54// = Matrix of Strings =========================================================
55STRING1 = "Scilab";
56STRING2 = "5.x";
57LS1 = length(STRING1);
58LS2 = length(STRING2);
59if length([STRING1,STRING2]) <> [LS1,LS2] then bugmes();quit;end
60// = Matrix of Strings =========================================================
61if length("abd")<>3 then bugmes();quit;end
62if length(emptystr())<>0 then bugmes();quit;end
63if or(length(["abd";emptystr()])<>[3;0]) then bugmes();quit;end
64if or(length(string(ones(10,10)))<>1) then bugmes();quit;end
65// = with a file ===============================================================
66fd = mopen(SCI+"/modules/string/tests/unit_tests/text.txt","r");
67txt = mgetl( fd );
68mclose( fd );
69if length(txt(1)) <> 280  then bugmes();quit;end
70S = size(txt);
71if length(txt(S(1)-1)) <> 106  then bugmes();quit;end
72if length(txt(S(1))) <> 0  then bugmes();quit;end
73// = an hypermatrix (double) ===================================================
74A = rand(2,5,2,3,2);
75assert_checkequal(length(A), size(A,"*"));
76A = matrix(1:24, [2,3,4]);
77assert_checkequal(length(A), size(A,"*"));
78// = an hypermatrix (string) ===================================================
79clear S;
80S(:,:,1) = ["a","ab";"abc","abcd"];
81S(:,:,2) = ["dcba", "cba"; "ba", "a"];
82ref(:,:,1) = [1 2;3 4];
83ref(:,:,2) = [4 3;2 1];
84assert_checkequal(length(S), ref);
85// = an sparse ===================================================
86sp = sparse([1 2 3;4 5 6]);
87assert_checkequal(length(sp), 6);
88sp = sparse(eye(12,2));
89assert_checkequal(length(sp), 24);
90sp = sparse(eye(2,12));
91assert_checkequal(length(sp), 24);
92