1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2008 - DIGITEO - Allan CORNET
4//
5//  This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// <-- CLI SHELL MODE -->
8// <-- Non-regression test for bug 3567 -->
9//
10// <-- Bugzilla URL -->
11// http://bugzilla.scilab.org/show_bug.cgi?id=3567
12//
13// <-- Short Description -->
14// gsort called with a complex array
15warning("off");
16c = [1 2 3]+%i;
17v = gsort(c);
18ref_v = [ 3. + %i      2. + %i      1. + %i  ];
19if or(v <> ref_v) then bugmes();quit;end
20x = [5 8 1; 1 9 4];
21y = [4 1 8; 1 4 9];
22c = x+y*%i;
23[v,ind] = gsort(c);
24C = abs(c);
25[v2,ind2] = gsort(C);
26ref_ind = [     4.    3.    1.  ;    6.    5.    2. ];
27ref_v = [  9. + 4.*%i    8. + %i      5. + 4.*%i  ;    4. + 9.*%i    1. + 8.*%i    1. + %i  ];
28if or(ref_ind <> ind) then bugmes();quit;end
29if or(ref_v <> v) then bugmes();quit;end
30if or(ref_ind <> ind2) then bugmes();quit;end
31x = [3  1  5 ; 2 9 8];
32y = [2  4  1 ; 4 1 3];
33c = x+y*%i;
34C = abs(c);
35ref_values = [ 9. + %i      5. + %i      1. + 4.*%i  ;   8. + 3.*%i    2. + 4.*%i    3. + 2.*%i ];
36ref_indices = [     4.    5.    3.  ;    6.    2.    1.];
37[values_1,indices_1] = gsort(c);
38if or(ref_values <> values_1) then bugmes();quit;end
39if or(ref_indices <> indices_1) then bugmes();quit;end
40ref_indices_C = [     4.    5.    3.  ;    6.    2.    1.];
41[values_C, indices_C] = gsort(C);
42if or(indices_C <> ref_indices_C) then bugmes();quit;end
43[values_2,indices_2] = gsort(c,'g');
44if or(values_1 <> values_2) then bugmes();quit;end
45if or(indices_1 <> indices_2) then bugmes();quit;end
46ref_values_3 = [  3. + 2.*%i    2. + 4.*%i    8. + 3.*%i  ;    1. + 4.*%i    5. + %i      9. + %i  ];
47ref_indices_3 = [    1.    2.    6.  ;    3.    5.    4.];
48[values_3,indices_3] = gsort(c,'g','i');
49if or(ref_values_3 <> values_3) then bugmes();quit;end
50if or(ref_indices_3 <> indices_3) then bugmes();quit;end
51[values_4,indices_4] = gsort(c,'g','d');
52if or(ref_values <> values_4) then bugmes();quit;end
53if or(ref_indices <> indices_4) then bugmes();quit;end
54[values_gsort,indices_gsort] = gsort(c);
55[values_sort,indices_sort] = gsort(c);
56if or(values_gsort <> values_sort) then bugmes();quit;end
57if or(indices_gsort <> indices_sort) then bugmes();quit;end
58x = [3,1,5];
59y = [2,4,1];
60c = x+y*%i;
61ierr = execstr("v = gsort(c,''lr'');","errcatch");
62if ierr <> 0 then bugmes();quit;end
63ierr = execstr("v = gsort(c,''l'');","errcatch");
64if ierr <> 999 then bugmes();quit;end
65ierr = execstr("v = gsort(c,''lc'');","errcatch");
66if ierr <> 0 then bugmes();quit;end
67ierr = execstr("v = gsort(c,''rc'');","errcatch");
68if ierr <> 999 then bugmes();quit;end
69ierr = execstr("v = gsort(c,''r'');","errcatch");
70if ierr <> 0 then bugmes();quit;end
71ierr = execstr("v = gsort(c,''c'');","errcatch");
72if ierr <> 0 then bugmes();quit;end
73