File: test_squares.t

package info (click to toggle)
libregexp-common-perl 2011121001-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 860 kB
  • sloc: perl: 10,291; makefile: 2
file content (69 lines) | stat: -rwxr-xr-x 1,471 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl

use strict;
use lib  qw {blib/lib};

use Config;
use Regexp::Common;
use t::Common '5.008';

use warnings;

my $bits64 = $Config {use64bitint};
#
# CPAN testers claim it fails on 5.8.8 and darwin 9.0.
#
$bits64 = 0 if $Config {osname} eq 'darwin' &&
               $Config {osvers} eq '9.0'    &&
               $] == 5.008008;

my $MAX = $bits64 ? do {no warnings; "9000000000000000"}
                  : 0x7FFFFFFF;


sub create_parts;

my $square = $RE {num} {square};

my @tests  = (
   [square => $square => {square => NORMAL_PASS | FAIL}]
);

my ($good, $bad) = create_parts;

run_tests version   =>  "Regexp::Common::number",
          tests     =>  \@tests,
          good      =>  $good,
          bad       =>  $bad,
          query     =>  sub {$_ [1] -> [0]},
          wanted    =>  sub {$_ [1]};

my %c;
sub _1 {{
    my $x = int rand sqrt $MAX;
    redo if $c {$x} ++ || $x <= 100;
    $x = sprintf "%d" => $x;
    $x = ("0" x (1 + int rand 10)) . $x if rand (10) < 1;
    $x;
}}
my %d;
sub _2 {{
    my $x = int rand $MAX;
    redo if $d {$x} ++ || $x == (int sqrt ($x)) ** 2;
    sprintf "%d" => $x;
}}

sub create_parts {
    my (@good, @bad);

    $good [0] = [map {$_ * $_} 0 .. 100];
    push @{$good [0]} => 2147395600;
    push @{$good [0]} => map {sprintf "%d", _1 () ** 2} 1 .. 400;
    $bad  [0] = [-1, 0.1, "fnord", "f16", map {sprintf "%d" => _2} 1 .. 200];
    push @{$bad [0]} => 2147483647;

  (\@good, \@bad);
}


__END__