This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: 5.003_06 is available (results on ULTRIX)
[perl5.git] / t / op / sort.t
1 #!./perl
2
3 # $RCSfile: sort.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:24 $
4
5 print "1..10\n";
6
7 sub backwards { $a lt $b ? 1 : $a gt $b ? -1 : 0 }
8
9 @harry = ('dog','cat','x','Cain','Abel');
10 @george = ('gone','chased','yz','punished','Axed');
11
12 $x = join('', sort @harry);
13 print ($x eq 'AbelCaincatdogx' ? "ok 1\n" : "not ok 1\n");
14 print "# x = '$x'\n";
15
16 $x = join('', sort( backwards @harry));
17 print ($x eq 'xdogcatCainAbel' ? "ok 2\n" : "not ok 2\n");
18 print "# x = '$x'\n";
19
20 $x = join('', sort @george, 'to', @harry);
21 print ($x eq 'AbelAxedCaincatchaseddoggonepunishedtoxyz'?"ok 3\n":"not ok 3\n");
22 print "# x = '$x'\n";
23
24 @a = ();
25 @b = reverse @a;
26 print ("@b" eq "" ? "ok 4\n" : "not ok 4 (@b)\n");
27
28 @a = (1);
29 @b = reverse @a;
30 print ("@b" eq "1" ? "ok 5\n" : "not ok 5 (@b)\n");
31
32 @a = (1,2);
33 @b = reverse @a;
34 print ("@b" eq "2 1" ? "ok 6\n" : "not ok 6 (@b)\n");
35
36 @a = (1,2,3);
37 @b = reverse @a;
38 print ("@b" eq "3 2 1" ? "ok 7\n" : "not ok 7 (@b)\n");
39
40 @a = (1,2,3,4);
41 @b = reverse @a;
42 print ("@b" eq "4 3 2 1" ? "ok 8\n" : "not ok 8 (@b)\n");
43
44 @a = (10,2,3,4);
45 @b = sort {$a <=> $b;} @a;
46 print ("@b" eq "2 3 4 10" ? "ok 9\n" : "not ok 9 (@b)\n");
47
48 $sub = 'backwards';
49 $x = join('', sort $sub @harry);
50 print ($x eq 'xdogcatCainAbel' ? "ok 10\n" : "not ok 10\n");
51