File: ints.t

package info (click to toggle)
libsort-key-perl 1.33-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid
  • size: 344 kB
  • sloc: perl: 493; ansic: 212; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 9;
use Sort::Key qw(nkeysort rnkeysort nsort rnsort
		 ikeysort rikeysort isort risort
		 ukeysort rukeysort usort rusort);

my $unstable;
BEGIN {
    if ($] >= 5.008 ) {
	eval "use sort 'stable'";
    }
    else {
	$unstable = 1;
    }
}

my @data=map { rand(2**16) - (2**15) } 1..10000;

if ($unstable) {
    $_ = int abs $_ for @data;
}

{
    use integer;
    is_deeply([nkeysort {$_} @data], [sort { int($a) <=> int($b)} @data], 'i id');
    is_deeply([nkeysort {$_*$_} @data], [sort { int($a*$a) <=> int($b*$b) } @data], 'i sqr');
    is_deeply([rnkeysort {$_*$_} @data], [sort { int($b*$b) <=> int($a*$a) } @data], 'ri sqr');
    is_deeply([rnsort @data], [sort { int($b) <=> int($a) } @data], 'i rnsort');
    is_deeply([nsort @data], [sort { int($a) <=> int($b) } @data], 'i nsort');
}
is_deeply([ikeysort {$_} @data], [sort { int($a) <=> int($b)} @data], 'i id 2');
is_deeply([rikeysort {$_} @data], [sort { int($b) <=> int($a)} @data], 'ri id 2');

@data = map { int rand(2**32) } 1..10000;

if ($unstable) {
    $_ = int $_ for @data;
}

is_deeply([ukeysort {$_} @data], [sort { int($a) <=> int($b)} @data], 'u id 2');
is_deeply([rukeysort {$_} @data], [sort { int($b) <=> int($a)} @data], 'ru id 2');