1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-02-18 21:32:12 +02:00
Files
coreutils/tests/sort-time/rand-gen
Jim Meyering 512e111a92 Revamp test-related Makefiles.
One side-effect of this change is that "make check" now works even if
you put "." early in your shell's search PATH (don't do that!).

Remove all test-related Makefile.am files, except those generated
by mk-script.  Instead, tests/Makefile.am now lists not only the
tests directly under tests/, but also those in tests/*/ that are
not generated by mk-script, e.g., cp/abuse, cp/acl, mv/i-1, etc.

A lot of these changes are like this:

-. $srcdir/../lang-default
+. $top_srcdir/tests/lang-default

-. $srcdir/../test-lib.sh
+. $top_srcdir/tests/test-lib.sh

* configure.ac (AC_CONFIG_FILES): Remove corresponding Makefiles.
* tests/check.mk (vc_exe_in_TESTS): Relax syntax requirements.
* tests/rwx-to-mode: Remove file.  Rewritten as...
* tests/test-lib.sh (rwx_to_mode_): ...this new function.
* tests/Makefile.am (EXTRA_DIST): Remove rwx-to-mode.
(SUBDIRS): Remove each dir with a removed Makefile.am.
(EXTRA_DIST): Add $(TESTS).
(TESTS): Add over 300 entries.
2008-04-21 00:01:51 +02:00

140 lines
3.0 KiB
Perl

#! /p/bin/perl -w
# Print n pairs of floating point values.
# Each value is in the range [0,1).
# Usage: rand n
# Copyright (C) 1997 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Use only the basename from the path to this executable in error messages.
($program_name = $0) =~ s|.*/||;
require 'newgetopt.pl';
$MAXINT = 0x7fffffff;
undef $opt_help;
undef $opt_verbose;
undef $opt_integer;
&usage if (&NGetOpt(('seed=i', 'range=s', 'help', 'items-per-line=i',
'format=s', 'integer', 'verbose')) == 0);
&usage if (defined ($opt_help));
&usage if (scalar (@ARGV) != 1 || $ARGV[0] !~ /^[0-9]+$/);
$n = $ARGV[0];
if (!defined ($opt_seed))
{
$opt_seed = time;
print STDERR "seed= $opt_seed\n" if (defined ($opt_verbose));
}
srand ($opt_seed);
# FIXME: make sure this number is positive.
$opt_items_per_line = 1 if (!defined ($opt_items_per_line));
if (defined ($opt_integer))
{
$opt_format = "%d" if (!defined ($opt_format));
if (defined ($opt_range))
{
# FIXME: allow FP endpoints even though --integer specified?
if ($opt_range =~ /^([0-9]+),([0-9]+)$/)
{
$lo = $1;
$hi = $2;
}
else
{
print STDERR ("bad argument `$opt_range' to --range option\n");
exit 2;
}
}
else
{
$lo = 0;
$hi = $MAXINT;
}
# Increase by one because we'll have to truncate to get integers.
$hi += 1;
}
else
{
$opt_format = "%.15g" if (!defined ($opt_format));
if (defined ($opt_range))
{
if ($opt_range =~ /^(-?[0-9.]+),(-?[0-9.]+)$/)
{
$lo = $1;
$hi = $2;
}
else
{
print STDERR ("bad argument `$opt_range' to --range option\n");
exit 2;
}
}
else
{
$lo = 0.0;
$hi = 1.0;
}
}
# FIXME: warn if lo > hi.
$range = $hi - $lo;
if ($opt_items_per_line == 1)
{
for ($i=0; $i < $n; $i++)
{
printf $opt_format, $lo + rand($range);
print "\n";
}
}
else
{
$separator = ' ';
for ($i=0; $i < $n; $i++)
{
for ($j=0; $j < $opt_items_per_line; $j++)
{
printf $opt_format, $lo + rand($range);
print $j == $opt_items_per_line - 1 ? "\n" : $separator;
}
}
}
exit 0;
sub usage
{
print STDERR <<EOF;
Usage: $program_name [OPTIONS] n
--help
--seed=n
--integer
--items-per-line=n
--range=i,j e.g. 3,9 or 1.5,33.9
--format='%3d'
--verbose (report the seed if it gets default value)
EOF
exit 2;
}