Skip to content
Browse files

import Data-Random 0.05 from CPAN

git-cpan-module:   Data-Random
git-cpan-version:  0.05
git-cpan-authorid: ADEO
git-cpan-file:     authors/id/A/AD/ADEO/Data-Random-0.05.tar.gz
  • Loading branch information...
1 parent 67910fa commit e2826dbb97240b93e8eef4942ed885fe3660afe5 Adekunle Olonoh committed with schwern Feb 22, 2003
Showing with 45,888 additions and 203 deletions.
  1. +5 −0 Changes
  2. +3 −0 MANIFEST
  3. +1 −1 README
  4. +209 −0 README.linux.words
  5. +29 −0 README2.linux.words
  6. +8 −8 Random.pm
  7. +7 −4 Random/WordList.pm
  8. +45,427 −0 Random/dict
  9. +83 −80 t/rand_date.t
  10. +102 −99 t/rand_datetime.t
  11. +14 −11 t/rand_image.t
View
5 Changes
@@ -1,5 +1,10 @@
Revision history for Data::Random.
+0.05 Thu Feb 20 2003
+ - added default wordlist (copy of linux.words)
+ - fixed tests again so they don't fail if Date::Calc or
+ GD are not installed
+
0.04 Tue Feb 26 2002
- removed false dependency on Perl 5.005_62
- only load Data::Random::WordList when needed
View
3 MANIFEST
@@ -1,9 +1,12 @@
Changes
MANIFEST
README
+README.linux.words
+README2.linux.words
Makefile.PL
Random.pm
Random/WordList.pm
+Random/dict
t/rand_chars.t
t/rand_date.t
t/rand_datetime.t
View
2 README
@@ -13,4 +13,4 @@ The module also uses Date::Calc for rand_date() and rand_datetime(), and GD for
--
-Adekunle Olonoh <olonoh@yahoo.com>
+Adekunle Olonoh <koolade@users.sourceforge.net>
View
209 README.linux.words
@@ -0,0 +1,209 @@
+#!/bin/sh -xe
+# README.linux.words - file used to create linux.words
+# Created: Wed Mar 10 09:12:49 1993 by faith@cs.unc.edu (Rik Faith)
+# Revised: Sat Mar 13 17:02:08 1993 by faith@cs.unc.edu
+#
+# Care was taken to be sure that the linux.words list was free of
+# copyright. This makes linux.words a suitable /usr/dict/words
+# replacement for the Linux community.
+#
+# Since the majority of the words are from Tanenbaum's minix.dict file,
+# the notice from Barry Brachman, included below, should accompany any
+# redistribution of this list.
+
+# Here is a detailed explaination of how I created the linux.words file.
+#
+# This README.words file is actually a shell script that you can use to
+# recreate the linux.words file from original sources.
+#
+# First, I started with minix.dict
+# from cs.ubc.ca:/pub/local/src/sp-1.5/wordlists-1.0.tar.Z
+#
+# The following is from the NOTES file in wordlists-1.0.tar.Z:
+
+# NOTES> These word lists were collected by Barry Brachman
+# NOTES> <brachman@cs.ubc.ca> at the University of British Columbia. They
+# NOTES> may be freely distributed as long as this notice accompanies them.
+# NOTES>
+# NOTES> ==================================================================
+# NOTES> Info for minix.dict:
+# NOTES>
+# NOTES> Article 1997 of comp.os.minix:
+# NOTES> From: ast@botter.UUCP
+# NOTES> Subject: A spelling checker for MINIX
+# NOTES> Date: 6 Jan 88 22:28:22 GMT
+# NOTES> Reply-To: ast@cs.vu.nl (Andy Tanenbaum)
+# NOTES> Organization: VU Informatica, Amsterdam
+# NOTES>
+# NOTES> This dictionary is NOT based on the UNIX dictionary so it is free
+# NOTES> of AT&T copyright. I built the dictionary from three sources.
+# NOTES> First, I started by sorting and uniq'ing some public domain
+# NOTES> dictionaries. Second, as some of you probably know, I have
+# NOTES> written somewhere between 3 and 6 books (depending on precisely
+# NOTES> what you count) and an additional 50 published papers on operating
+# NOTES> systems, networks, compilers, languages, etc. This data base,
+# NOTES> which is online, is nonnegligible :-) Finally, I added a number of
+# NOTES> words that I thought ought to be in the dictionary including all
+# NOTES> the U.S. states, all the European and some other major countries,
+# NOTES> principal U.S. and world cities, and a bunch of technical terms.
+# NOTES> I don't want my spelling checker to barf on arpanet, diskless,
+# NOTES> modem, login, internetwork, subdirectory, superuser, vlsi, or
+# NOTES> winchester just because Webster wouldn't approve of them. All in
+# NOTES> all, the dictionary is over 40,000 words. If you have any
+# NOTES> suggestions for additions or deletions, please post them. But
+# NOTES> please be sure you are not infringing on anyone's copyright in
+# NOTES> doing so.
+# NOTES>
+# NOTES> Andy Tanenbaum (ast@cs.vu.nl)
+
+# The main problem with minix.dict is that many proper names are not
+# capitalized. So, I got english.tar.Z from ftp.uu.net:/doc/dictionaries,
+# which is a mirror of nic.funet.fi:/pub/unix/security/dictionaries.
+#
+# Here is part of the README file for english.tar.Z:
+
+# README>
+# README> FILE: english.words
+# README> VERSION: DEC-SRC-92-04-05
+# README>
+# README> EDITOR
+# README>
+# README> Jorge Stolfi <stolfi@src.dec.com>
+# README> DEC Systems Research Center
+# README>
+# README> AUTHORS OF ORIGIONAL WORDLISTS
+# README>
+# README> Andy Tanenbaum <ast@cs.vu.nl>
+# README> Barry Brachman <brachman@cs.ubc.ca>
+# README> Geoff Kuenning <geoff@itcorp.com>
+# README> Henk Smit <henk@cs.vu.nl>
+# README> Walt Buehring <buehring%ti-csl@csnet-relay>
+#
+# [stuff seleted]
+#
+# README> AUXILIARY LISTS
+# README>
+# README> In the same directory as englis.words there are a few
+# README> complementary word lists, all derived from the same sources
+# README> [1--8] as the main list:
+# README>
+# README> english.names
+# README>
+# README> A list of common English proper names and their derivatives.
+# README> The list includes: person names ("John", "Abigail",
+# README> "Barrymore"); countries, nations, and cities ("Germany",
+# README> "Gypsies", "Moscow"); historical, biblical and mythological
+# README> figures ("Columbus", "Isaiah", "Ulysses"); important
+# README> trademarked products ("Xerox", "Teflon"); biological genera
+# README> ("Aerobacter"); and some of their derivatives ("Germans",
+# README> "Xeroxed", "Newtonian").
+# README>
+# README> misc.names
+# README>
+# README> A list of foreign-sounding names of persons and places
+# README> ("Antonio", "Albuquerque", "Balzac", "Stravinski"), extracted
+# README> from the lists [1--8]. (The distinction betweeen
+# README> "English-sounding" and "foreign-sounding" is of course rather
+# README> arbitrary).
+# README>
+# README> org.names
+# README>
+# README> A short lists names of corporations and other institutions
+# README> ("Pepsico", "Amtrak", "Medicare"), and a few derivatives.
+# README>
+# README> The file also includes some initialisms --- acronyms and
+# README> abbreviations that are generally pronounced as words rather
+# README> than spelled out ("NASA", "UNESCO").
+# README>
+# README> english.abbrs
+# README>
+# README> A list of common abbreviations ("etc.", "Dr.", "Wed."),
+# README> acronyms ("A&M", "CPU", "IEEE"), and measurement symbols
+# README> ("ft", "cm", "ns", "kHz").
+# README>
+# README> english.trash
+# README>
+# README> A list of words from the original wordlists
+# README> that I decided were either wrong or unsuitable for inclusion
+# README> in the file english.words or any of the other auxiliary
+# README> lists. It includes
+# README>
+# README> typos ("accupy", "aquariia", "automatontons")
+# README> spelling errors ("abcissa", "alleviater", "analagous")
+# README> bogus derived forms ("homeown", "unfavorablies", "catched")
+# README> uncapitalized proper names ("afghanistan",
+# README> "algol", "decnet")
+# README> uncapitalized acronyms ("apl", "ccw", "ibm")
+# README> unpunctuated abbreviations ("amp", "approx", "etc")
+# README> British spellings ("advertize", "archaeology")
+# README> archaic words ("bedight")
+# README> rare variants ("babirousa")
+# README> unassimilated foreign words ("bambino", "oui", "caballero")
+# README> mis-hyphenated compounds ("babylike", "backarrows")
+# README> computer keywords and slang ("lconvert", "noecho", "prog")
+# README>
+# README> (I apologize for excluding British spellings. I should have
+# README> split the list in three sublists--- common English, British,
+# README> American---as ispell does. But there are only so many hours
+# README> in a day...)
+# README>
+# README> english.maybe
+# README>
+# README> A list of about 5,000 lowercase words from the "mts.dict"
+# README> wordlist [6] that weren't included in english.words.
+# README>
+# README> This list seems to include lots of "trash", like
+# README> uncapitalized proper names and weird words. It would
+# README> take me several days to sort this mess, so I decided to
+# README> leave it as a separate file. Use at your own risk...
+#
+# [stuff deleted]
+#
+# README> (NON-)COPYRIGHT STATUS
+# README>
+# README> To the best of my knowledge, all the files I used to build these
+# README> wordlists were available for public distribution and use, at least
+# README> for non-commercial purposes. I have confirmed this assumption with
+# README> the authors of the lists, whenever they were known.
+# README>
+# README> Therefore, it is safe to assume that the wordlists in this
+# README> package can also be freely copied, distributed, modified, and
+# README> used for personal, educational, and research purposes. (Use of
+# README> these files in commercial products may require written
+# README> permission from DEC and/or the authors of the original lists.)
+# README>
+# README> Whenever you distribute any of these wordlists, please distribute
+# README> also the accompanying README file. If you distribute a modified
+# README> copy of one of these wordlists, please include the original README
+# README> file with a note explaining your modifications. Your users will
+# README> surely appreciate that.
+# README>
+# README> (NO-)WARRANTY DISCLAIMER
+# README>
+# README> These files, like the original wordlists on which they are
+# README> based, are still very incomplete, uneven, and inconsitent, and
+# README> probably contain many errors. They are offered "as is" without
+# README> any warranty of correctness or fitness for any particular
+# README> purpose. Neither I nor my employer can be held responsible for
+# README> any losses or damages that may result from their use.
+
+# subtract english.trash
+cat minix.dict english.trash english.trash | sort | uniq -u > dict.1
+# subtract english.maybe
+cat dict.1 english.maybe english.maybe | sort | uniq -u > dict.2
+
+# build subtraction list of proper names and abbreviations
+cat english.names misc.names org.names computer.names english.abbrs > sub.1
+tr 'A-Z' 'a-z' < sub.1 | sort | uniq -u > sub.2
+
+# subtract proper names with incorrect capitalization
+cat dict.2 sub.2 sub.2 | sort | uniq -u > dict.3
+
+# build proper name list without possessives
+cat english.names misc.names org.names computer.names | fgrep -v \'s > names.1
+
+# add in proper names (use sort twice to get uppercase before lowercase)
+cat dict.3 names.1 | sort | sort -df | uniq > linux.words
+
+# clean up
+rm dict.[123] sub.[12] names.1
View
29 README2.linux.words
@@ -0,0 +1,29 @@
+#!/bin/sh -xe
+# README2.linux.words - second file used to create linux.words
+# Created: Sun Oct 10 18:50:53 1993 by faith@cs.unc.edu (Rik Faith)
+# Revised: Sun Oct 10 21:26:01 1993 by faith@cs.unc.edu
+#
+
+# As noted in README.linux.words, extreme care was taken to be sure that
+# the linux.words list was free of copyright. This was done so that
+# linux.words would be a suitable /usr/dict/words replacement for the Linux
+# community. After the initial release of linux.words, Greg Alt
+# (galt@asylum.cs.utah.edu) and Josh Richardson (josh@gatelink.com) sent me
+# several short lists of words that were not in my original list. They
+# obtained these lists by analyzing FAQs and online text material,
+# including the Federalist Papers. The results were manually analyzed by
+# them before sending the lists to me. In addition, I removed some words
+# which were not listed in The American Heritage Dictionary (Second College
+# Edition, Houghton Mifflin Co., 1991). This method of obtaining words
+# (from documents, not from word lists) is also "safe" from the copyright
+# standpoint. Therefore, I am merging these lists in with (version 1) of
+# linux.words to create the second version of linux.words.
+
+# move version 1 list
+mv linux.words dict.4
+
+# add in proper names (use sort twice to get uppercase before lowercase)
+cat dict.4 extra.words | sort | sort -df | uniq > linux.words
+
+# clean up
+rm dict.4
View
16 Random.pm
@@ -48,7 +48,7 @@ use vars qw(
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
@EXPORT = qw();
-$Data::Random::VERSION = '0.04';
+$Data::Random::VERSION = '0.05';
################################################################################
# - Subroutines
@@ -62,12 +62,12 @@ sub rand_words {
# Get the options hash
my %options = @_;
- # Make sure the wordlist param was specified
- cluck('a wordlist must be specified') && return if !$options{'wordlist'};
-
# Initialize max and min vars
$options{'min'} ||= 1;
$options{'max'} ||= 1;
+
+ # Initialize the wordlist param
+ $options{'wordlist'} ||= '';
# Make sure the max and min vars are OK
cluck('min value cannot be larger than max value') && return
@@ -544,7 +544,7 @@ Data::Random - Perl module to generate random data
use Data::Random qw(:all);
- my @random_words = rand_words( wordlist => '/usr/dict/words', size => 10 );
+ my @random_words = rand_words( size => 10 );
my @random_chars = rand_chars( set => 'all', min => 5, max => 8 );
@@ -579,7 +579,7 @@ This returns a list of random words given a wordlist. See below for possible pa
=item *
-wordlist - the path to the wordlist file. A lot of systems have one at /usr/dict/words. You can also optionally supply a Data::Random::WordList object to keep a persistent wordlist.
+wordlist - the path to the wordlist file. A lot of systems have one at /usr/dict/words. You can also optionally supply a Data::Random::WordList object to keep a persistent wordlist. The default is the wordlist distributed with this module.
=item *
@@ -827,11 +827,11 @@ fgcolor - the foreground color of the image. The value must be a reference to a
=head1 VERSION
-0.04
+0.05
=head1 AUTHOR
-Adekunle Olonoh, olonoh@yahoo.com
+Adekunle Olonoh, koolade@users.sourceforge.net
=head1 CREDITS
View
11 Random/WordList.pm
@@ -14,11 +14,12 @@ package Data::Random::WordList;
################################################################################
#require 5.005_62;
use FileHandle;
+use File::Basename qw(dirname);
################################################################################
# - Global Constants and Variables
################################################################################
-$Data::Random::WordList::VERSION = '0.04';
+$Data::Random::WordList::VERSION = '0.05';
################################################################################
# - Subroutines
@@ -33,6 +34,8 @@ sub new {
# Check if what was passed in was a prototype reference or a class name
my $class = ref($proto) || $proto;
+
+ $options{'wordlist'} ||= dirname($INC{'Data/Random.pm'}).'/Random/dict';
# Create a new filehandle object
my $fh = new FileHandle $options{'wordlist'}
@@ -150,7 +153,7 @@ Returns a reference to a new Data::Random::WordList object. Use the "wordlist"
=item *
-wordlist - the path to the wordlist file.
+wordlist - the path to the wordlist file. If a path isn't supplied, the wordlist distributed with this module is used.
=back 4
@@ -164,11 +167,11 @@ Closes the filehandle associated with the word list. It's good practice to do t
=head1 VERSION
-0.04
+0.05
=head1 AUTHOR
-Adekunle Olonoh, olonoh@yahoo.com
+Adekunle Olonoh, koolade@users.sourceforge.net
=head1 COPYRIGHT
View
45,427 Random/dict
45,427 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
163 t/rand_date.t
@@ -1,5 +1,5 @@
use strict;
-use Test;
+use Test::More;
BEGIN { plan tests => 5 }
@@ -9,120 +9,123 @@ use Data::Random qw( rand_date );
# Try to load Date::Calc
eval q{ use Date::Calc };
-# If the module cannot be loaded, skip tests
-print "1..0 # Skipped: Date::Calc not installed\n" and exit if $@;
+SKIP: {
-# Get today's date
-my ( $year, $month, $day ) = Date::Calc::Today();
+ # If the module cannot be loaded, skip tests
+ skip('Date::Calc not installed', 5) if $@;
-# Test default w/ no params -- should return a date between today and 1 year from now
-{
- my $pass = 1;
+ # Get today's date
+ my ( $year, $month, $day ) = Date::Calc::Today();
- my $max_days =
- Date::Calc::Delta_Days( $year, $month, $day,
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
+ # Test default w/ no params -- should return a date between today and 1 year from now
+ {
+ my $pass = 1;
- my $i = 0;
- while ( $pass && $i < $max_days ) {
- my $date = rand_date();
+ my $max_days =
+ Date::Calc::Delta_Days( $year, $month, $day,
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
- my $delta =
- Date::Calc::Delta_Days( $year, $month, $day, split ( /\-/, $date ) );
+ my $i = 0;
+ while ( $pass && $i < $max_days ) {
+ my $date = rand_date();
- $pass = 0 unless $delta >= 0 && $delta <= $max_days;
+ my $delta =
+ Date::Calc::Delta_Days( $year, $month, $day, split ( /\-/, $date ) );
- $i++;
+ $pass = 0 unless $delta >= 0 && $delta <= $max_days;
+
+ $i++;
+ }
+
+ ok($pass);
}
- ok($pass);
-}
+ # Test min option
+ {
+ my $pass = 1;
-# Test min option
-{
- my $pass = 1;
+ my $max_days = Date::Calc::Delta_Days( 1978, 9, 21, 1979, 9, 21 );
- my $max_days = Date::Calc::Delta_Days( 1978, 9, 21, 1979, 9, 21 );
+ my $i = 0;
+ while ( $pass && $i < $max_days ) {
+ my $date = rand_date( min => '1978-9-21' );
- my $i = 0;
- while ( $pass && $i < $max_days ) {
- my $date = rand_date( min => '1978-9-21' );
+ my $delta =
+ Date::Calc::Delta_Days( 1978, 9, 21, split ( /\-/, $date ) );
- my $delta =
- Date::Calc::Delta_Days( 1978, 9, 21, split ( /\-/, $date ) );
+ $pass = 0 unless $delta >= 0 && $delta <= $max_days;
- $pass = 0 unless $delta >= 0 && $delta <= $max_days;
+ $i++;
+ }
- $i++;
+ ok($pass);
}
- ok($pass);
-}
+ # Test max option
+ {
+ my $pass = 1;
-# Test max option
-{
- my $pass = 1;
+ my $max_days =
+ Date::Calc::Delta_Days( $year, $month, $day,
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
- my $max_days =
- Date::Calc::Delta_Days( $year, $month, $day,
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
+ my $i = 0;
+ while ( $pass && $i < $max_days ) {
+ my $date =
+ rand_date( max =>
+ join ( '-',
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) ) );
- my $i = 0;
- while ( $pass && $i < $max_days ) {
- my $date =
- rand_date( max =>
- join ( '-',
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) ) );
+ my $delta =
+ Date::Calc::Delta_Days( $year, $month, $day, split ( /\-/, $date ) );
- my $delta =
- Date::Calc::Delta_Days( $year, $month, $day, split ( /\-/, $date ) );
+ $pass = 0 unless $delta >= 0 && $delta <= $max_days;
- $pass = 0 unless $delta >= 0 && $delta <= $max_days;
+ $i++;
+ }
- $i++;
+ ok($pass);
}
- ok($pass);
-}
+ # Test min + max options
+ {
+ my $pass = 1;
-# Test min + max options
-{
- my $pass = 1;
+ my $max_days =
+ Date::Calc::Delta_Days( $year, $month, $day,
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
- my $max_days =
- Date::Calc::Delta_Days( $year, $month, $day,
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
+ my $i = 0;
+ while ( $pass && $i < $max_days ) {
+ my $date = rand_date(
+ min => "$year-$month-$day",
+ max =>
+ join ( '-',
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) )
+ );
- my $i = 0;
- while ( $pass && $i < $max_days ) {
- my $date = rand_date(
- min => "$year-$month-$day",
- max =>
- join ( '-',
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) )
- );
+ my $delta =
+ Date::Calc::Delta_Days( $year, $month, $day, split ( /\-/, $date ) );
- my $delta =
- Date::Calc::Delta_Days( $year, $month, $day, split ( /\-/, $date ) );
+ $pass = 0 unless $delta >= 0 && $delta <= $max_days;
- $pass = 0 unless $delta >= 0 && $delta <= $max_days;
+ $i++;
+ }
- $i++;
+ ok($pass);
}
- ok($pass);
-}
-
-# Test min + max options using "now"
-{
- my $pass = 1;
+ # Test min + max options using "now"
+ {
+ my $pass = 1;
- my $date = rand_date( min => 'now', max => 'now' );
+ my $date = rand_date( min => 'now', max => 'now' );
- my ( $new_year, $new_month, $new_day ) = split ( /\-/, $date );
+ my ( $new_year, $new_month, $new_day ) = split ( /\-/, $date );
- $pass = 0
- unless $new_year == $year && $new_month == $month && $new_day == $day;
+ $pass = 0
+ unless $new_year == $year && $new_month == $month && $new_day == $day;
- ok($pass);
+ ok($pass);
+ }
}
View
201 t/rand_datetime.t
@@ -1,5 +1,5 @@
use strict;
-use Test;
+use Test::More;
BEGIN { plan tests => 5 }
@@ -9,137 +9,140 @@ use Data::Random qw( rand_datetime );
# Try to load Date::Calc
eval q{ use Date::Calc };
-# If the module cannot be loaded, skip tests
-print "1..0 # Skipped: Date::Calc not installed\n" and exit if $@;
+SKIP: {
-# Get today's date
-my ( $year, $month, $day ) = Date::Calc::Today();
+ # If the module cannot be loaded, skip tests
+ skip('Date::Calc not installed', 5) if $@;
-# Test default w/ no params -- should return a date between today and 1 year from now
-{
- my $pass = 1;
+ # Get today's date
+ my ( $year, $month, $day ) = Date::Calc::Today();
- my $max_days =
- Date::Calc::Delta_Days( $year, $month, $day,
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
+ # Test default w/ no params -- should return a date between today and 1 year from now
+ {
+ my $pass = 1;
- my $i = 0;
- while ( $pass && $i < $max_days ) {
- my $date = rand_datetime();
-
- my $delta =
+ my $max_days =
Date::Calc::Delta_Days( $year, $month, $day,
- ( $date =~ /^(\d+)-(\d+)-(\d+)/ ) );
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
- $pass = 0
- unless $delta >= 0 && $delta <= $max_days
- && _to_secs( ( split ( / /, $date ) )[1] );
+ my $i = 0;
+ while ( $pass && $i < $max_days ) {
+ my $date = rand_datetime();
+
+ my $delta =
+ Date::Calc::Delta_Days( $year, $month, $day,
+ ( $date =~ /^(\d+)-(\d+)-(\d+)/ ) );
+
+ $pass = 0
+ unless $delta >= 0 && $delta <= $max_days
+ && _to_secs( ( split ( / /, $date ) )[1] );
+
+ $i++;
+ }
- $i++;
+ ok($pass);
}
- ok($pass);
-}
+ # Test min option
+ {
+ my $pass = 1;
-# Test min option
-{
- my $pass = 1;
+ my $max_days = Date::Calc::Delta_Days( 1978, 9, 21, 1979, 9, 21 );
- my $max_days = Date::Calc::Delta_Days( 1978, 9, 21, 1979, 9, 21 );
+ my $i = 0;
+ while ( $pass && $i < $max_days ) {
+ my $date = rand_datetime( min => '1978-9-21 4:0:0' );
- my $i = 0;
- while ( $pass && $i < $max_days ) {
- my $date = rand_datetime( min => '1978-9-21 4:0:0' );
+ my $delta =
+ Date::Calc::Delta_Days( 1978, 9, 21,
+ ( $date =~ /^(\d+)-(\d+)-(\d+)/ ) );
- my $delta =
- Date::Calc::Delta_Days( 1978, 9, 21,
- ( $date =~ /^(\d+)-(\d+)-(\d+)/ ) );
+ $pass = 0
+ unless $delta >= 0 && $delta <= $max_days
+ && _to_secs( ( split ( / /, $date ) )[1] );
- $pass = 0
- unless $delta >= 0 && $delta <= $max_days
- && _to_secs( ( split ( / /, $date ) )[1] );
+ $i++;
+ }
- $i++;
+ ok($pass);
}
- ok($pass);
-}
+ # Test max option
+ {
+ my $pass = 1;
-# Test max option
-{
- my $pass = 1;
+ my $max_days =
+ Date::Calc::Delta_Days( $year, $month, $day,
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
- my $max_days =
- Date::Calc::Delta_Days( $year, $month, $day,
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
+ my $i = 0;
+ while ( $pass && $i < $max_days ) {
+ my $date =
+ rand_datetime( max =>
+ join ( '-',
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) )
+ . ' 0:0:0' );
- my $i = 0;
- while ( $pass && $i < $max_days ) {
- my $date =
- rand_datetime( max =>
- join ( '-',
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) )
- . ' 0:0:0' );
+ my $delta =
+ Date::Calc::Delta_Days( $year, $month, $day,
+ ( $date =~ /^(\d+)-(\d+)-(\d+)/ ) );
- my $delta =
- Date::Calc::Delta_Days( $year, $month, $day,
- ( $date =~ /^(\d+)-(\d+)-(\d+)/ ) );
+ $pass = 0
+ unless $delta >= 0 && $delta <= $max_days
+ && _to_secs( ( split ( / /, $date ) )[1] );
- $pass = 0
- unless $delta >= 0 && $delta <= $max_days
- && _to_secs( ( split ( / /, $date ) )[1] );
+ $i++;
+ }
- $i++;
+ ok($pass);
}
- ok($pass);
-}
+ # Test min + max options
+ {
+ my $pass = 1;
-# Test min + max options
-{
- my $pass = 1;
-
- my $max_days =
- Date::Calc::Delta_Days( $year, $month, $day,
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
-
- my $i = 0;
- while ( $pass && $i < $max_days ) {
- my $date = rand_datetime(
- min => "$year-$month-$day 12:0:0",
- max =>
- join ( '-',
- Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) )
- . ' 12:0:0'
- );
-
- my $delta =
+ my $max_days =
Date::Calc::Delta_Days( $year, $month, $day,
- ( $date =~ /^(\d+)-(\d+)-(\d+)/ ) );
-
- $pass = 0
- unless $delta >= 0 && $delta <= $max_days
- && _to_secs( ( split ( / /, $date ) )[1] );
-
- $i++;
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) );
+
+ my $i = 0;
+ while ( $pass && $i < $max_days ) {
+ my $date = rand_datetime(
+ min => "$year-$month-$day 12:0:0",
+ max =>
+ join ( '-',
+ Date::Calc::Add_Delta_YMD( $year, $month, $day, 1, 0, 0 ) )
+ . ' 12:0:0'
+ );
+
+ my $delta =
+ Date::Calc::Delta_Days( $year, $month, $day,
+ ( $date =~ /^(\d+)-(\d+)-(\d+)/ ) );
+
+ $pass = 0
+ unless $delta >= 0 && $delta <= $max_days
+ && _to_secs( ( split ( / /, $date ) )[1] );
+
+ $i++;
+ }
+
+ ok($pass);
}
- ok($pass);
-}
-
-# Test min + max options using "now"
-{
- my $pass = 1;
+ # Test min + max options using "now"
+ {
+ my $pass = 1;
- my $date = rand_datetime( min => 'now', max => 'now' );
+ my $date = rand_datetime( min => 'now', max => 'now' );
- my ( $new_year, $new_month, $new_day ) = ( $date =~ /^(\d+)-(\d+)-(\d+)/ );
+ my ( $new_year, $new_month, $new_day ) = ( $date =~ /^(\d+)-(\d+)-(\d+)/ );
- $pass = 0
- unless $new_year == $year && $new_month == $month && $new_day == $day
- && _to_secs( ( split ( / /, $date ) )[1] );
+ $pass = 0
+ unless $new_year == $year && $new_month == $month && $new_day == $day
+ && _to_secs( ( split ( / /, $date ) )[1] );
- ok($pass);
+ ok($pass);
+ }
}
sub _to_secs {
View
25 t/rand_image.t
@@ -1,5 +1,5 @@
use strict;
-use Test;
+use Test::More;
BEGIN { plan tests => 1 }
@@ -12,19 +12,22 @@ use vars qw( $imagefile );
# Try to load GD
eval q{ use GD };
-# If the module cannot be loaded, skip tests
-print "1..0 # Skipped: GD not installed\n" and exit if $@;
+SKIP: {
-$imagefile = File::Spec->tmpdir() . '/Data_Random_' . time() . '.tmp';
+ # If the module cannot be loaded, skip tests
+ skip('GD not installed', 1) if $@;
-# Test writing an image to a file
-{
- open( FILE, ">$imagefile" );
- binmode(FILE);
- print FILE rand_image( bgcolor => [ 0, 0, 0 ] );
- close(FILE);
+ $imagefile = File::Spec->tmpdir() . '/Data_Random_' . time() . '.tmp';
- ok( !( -z $imagefile ) );
+ # Test writing an image to a file
+ {
+ open( FILE, ">$imagefile" );
+ binmode(FILE);
+ print FILE rand_image( bgcolor => [ 0, 0, 0 ] );
+ close(FILE);
+
+ ok( !( -z $imagefile ) );
+ }
}
END {

0 comments on commit e2826db

Please sign in to comment.
Something went wrong with that request. Please try again.