Lingua-ENG-Inflect

 view release on metacpan or  search on metacpan

t/numwords.t  view on Meta::CPAN

#!/usr/bin/env perl

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

######################### We start with some black magic to print on failure.

# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)

BEGIN { $| = 1; print "1..896\n"; }
END {print "not ok 1\n" unless $loaded;}
use Lingua::ENG::Inflect qw( :ALL );
$loaded = 1;
print "ok 1\n";

my $count = 2;
sub ok($;$$)
{
	my $ok = $_[0];
	print "not " unless $ok;
	print "ok $count";
	print "\t# $_[1]" if $_[1];
	print " -> $_[2]" if $_[2];
	print "\n";
	$count++;
	return $ok;
}

######################### End of black magic.

sub test_eq($$)
{
	PL_eq($_[0],$_[1])    ||
	PL_N_eq($_[0],$_[1])  ||
	PL_V_eq($_[0],$_[1])  ||
	PL_ADJ_eq($_[0],$_[1]);
}


for my $thresh (0..20) {
    for my $n (0..20) {
        my $threshed = NUMWORDS($n, threshold=>$thresh);
        my $numwords = NUMWORDS($n);

        if ($n <= $thresh) {
            ok ( $numwords eq $threshed => "Wordified $n (<= $thresh)");
        }
        else {
            $threshed =~ s/\D//gxms;
            ok ( $threshed == $n => "Preserved $n (above $thresh)");
        }
    }
}

ok NUMWORDS(    999, threshold=>500) eq      '999',     ' 999 -> 999';
ok NUMWORDS(   1000, threshold=>500) eq    '1,000',     '1000 -> 1,000';
ok NUMWORDS(  10000, threshold=>500) eq   '10,000',    '10000 -> 10,000';
ok NUMWORDS( 100000, threshold=>500) eq  '100,000',   '100000 -> 100,000';
ok NUMWORDS(1000000, threshold=>500) eq '1,000,000', '1000000 -> 1,000,000';

ok NUMWORDS(    999.3, threshold=>500) eq      '999.3',     ' 999.3 -> 999.3';
ok NUMWORDS(   1000.3, threshold=>500) eq    '1,000.3',     '1000.3 -> 1,000.3';
ok NUMWORDS(  10000.3, threshold=>500) eq   '10,000.3',    '10000.3 -> 10,000.3';
ok NUMWORDS( 100000.3, threshold=>500) eq  '100,000.3',   '100000.3 -> 100,000.3';
ok NUMWORDS(1000000.3, threshold=>500) eq '1,000,000.3', '1000000.3 -> 1,000,000.3';

ok NUMWORDS(    999, threshold=>500, comma=>0) eq      '999',     ' 999 -> 999';
ok NUMWORDS(   1000, threshold=>500, comma=>0) eq    '1000',     '1000 -> 1000';
ok NUMWORDS(  10000, threshold=>500, comma=>0) eq   '10000',    '10000 -> 10000';
ok NUMWORDS( 100000, threshold=>500, comma=>0) eq  '100000',   '100000 -> 100000';
ok NUMWORDS(1000000, threshold=>500, comma=>0) eq '1000000', '1000000 -> 1000000';

ok NUMWORDS(    999.3, threshold=>500, comma=>0) eq      '999.3',     ' 999.3 -> 999.3';
ok NUMWORDS(   1000.3, threshold=>500, comma=>0) eq    '1000.3',     '1000.3 -> 1000.3';
ok NUMWORDS(  10000.3, threshold=>500, comma=>0) eq   '10000.3',    '10000.3 -> 10000.3';
ok NUMWORDS( 100000.3, threshold=>500, comma=>0) eq  '100000.3',   '100000.3 -> 100000.3';
ok NUMWORDS(1000000.3, threshold=>500, comma=>0) eq '1000000.3', '1000000.3 -> 1000000.3';



( run in 1.333 second using v1.01-cache-2.11-cpan-800906f7e73 )