Blame t/author-lib-boolean-_is_even.t

Packit Service 3bf9d6
#!perl
Packit Service 3bf9d6
Packit Service 3bf9d6
BEGIN {
Packit Service 3bf9d6
    unless ($ENV{AUTHOR_TESTING}) {
Packit Service 3bf9d6
        require Test::More;
Packit Service 3bf9d6
        Test::More::plan(skip_all =>
Packit Service 3bf9d6
                         'these tests are for testing by the author');
Packit Service 3bf9d6
    }
Packit Service 3bf9d6
}
Packit Service 3bf9d6
Packit Service 3bf9d6
use strict;
Packit Service 3bf9d6
use warnings;
Packit Service 3bf9d6
Packit Service 3bf9d6
use Test::More tests => 1597;
Packit Service 3bf9d6
Packit Service 3bf9d6
###############################################################################
Packit Service 3bf9d6
# Read and load configuration file and backend library.
Packit Service 3bf9d6
Packit Service 3bf9d6
use Config::Tiny ();
Packit Service 3bf9d6
Packit Service 3bf9d6
my $config_file = 't/author-lib.ini';
Packit Service 3bf9d6
my $config = Config::Tiny -> read('t/author-lib.ini')
Packit Service 3bf9d6
  or die Config::Tiny -> errstr();
Packit Service 3bf9d6
Packit Service 3bf9d6
# Read the library to test.
Packit Service 3bf9d6
Packit Service 3bf9d6
our $LIB = $config->{_}->{lib};
Packit Service 3bf9d6
Packit Service 3bf9d6
die "No library defined in file '$config_file'"
Packit Service 3bf9d6
  unless defined $LIB;
Packit Service 3bf9d6
die "Invalid library name '$LIB' in file '$config_file'"
Packit Service 3bf9d6
  unless $LIB =~ /^[A-Za-z]\w*(::\w+)*\z/;
Packit Service 3bf9d6
Packit Service 3bf9d6
# Load the library.
Packit Service 3bf9d6
Packit Service 3bf9d6
eval "require $LIB";
Packit Service 3bf9d6
die $@ if $@;
Packit Service 3bf9d6
Packit Service 3bf9d6
###############################################################################
Packit Service 3bf9d6
Packit Service 3bf9d6
can_ok($LIB, '_is_even');
Packit Service 3bf9d6
Packit Service 3bf9d6
use lib 't';
Packit Service 3bf9d6
use Math::BigInt::Lib::TestUtil qw< randstr >;
Packit Service 3bf9d6
Packit Service 3bf9d6
# Generate test data.
Packit Service 3bf9d6
Packit Service 3bf9d6
my @data;
Packit Service 3bf9d6
Packit Service 3bf9d6
for (my $x = 0 ; $x <= 100 ; ++ $x) {
Packit Service 3bf9d6
    push @data, [ $x, $x % 2 == 0 ];
Packit Service 3bf9d6
}
Packit Service 3bf9d6
Packit Service 3bf9d6
for (my $n = 3 ; $n <= 300 ; ++ $n) {
Packit Service 3bf9d6
    my $x = randstr($n, 10);            # random big integer
Packit Service 3bf9d6
    my $b = substr($x, -1, 1) % 2 == 0;
Packit Service 3bf9d6
    push @data, [ $x, $b ];
Packit Service 3bf9d6
}
Packit Service 3bf9d6
Packit Service 3bf9d6
# List context.
Packit Service 3bf9d6
Packit Service 3bf9d6
for (my $i = 0 ; $i <= $#data ; ++ $i) {
Packit Service 3bf9d6
    my ($in0, $out0) = @{ $data[$i] };
Packit Service 3bf9d6
Packit Service 3bf9d6
    my ($x, @got);
Packit Service 3bf9d6
Packit Service 3bf9d6
    my $test = qq|\$x = $LIB->_new("$in0"); |
Packit Service 3bf9d6
             . qq|\@got = $LIB->_is_even(\$x);|;
Packit Service 3bf9d6
Packit Service 3bf9d6
    diag("\n$test\n\n") if $ENV{AUTHOR_DEBUGGING};
Packit Service 3bf9d6
Packit Service 3bf9d6
    eval $test;
Packit Service 3bf9d6
    is($@, "", "'$test' gives emtpy \$\@");
Packit Service 3bf9d6
Packit Service 3bf9d6
    subtest "_is_even() in list context: $test", sub {
Packit Service 3bf9d6
        plan tests => 3,
Packit Service 3bf9d6
Packit Service 3bf9d6
        cmp_ok(scalar @got, "==", 1,
Packit Service 3bf9d6
               "'$test' gives one output arg");
Packit Service 3bf9d6
Packit Service 3bf9d6
        is(ref($got[0]), "",
Packit Service 3bf9d6
           "'$test' output arg is a scalar");
Packit Service 3bf9d6
Packit Service 3bf9d6
        ok($got[0] && $out0 || !$got[0] && !$out0,
Packit Service 3bf9d6
           "'$test' output arg has the right value");
Packit Service 3bf9d6
    };
Packit Service 3bf9d6
}
Packit Service 3bf9d6
Packit Service 3bf9d6
# Scalar context.
Packit Service 3bf9d6
Packit Service 3bf9d6
for (my $i = 0 ; $i <= $#data ; ++ $i) {
Packit Service 3bf9d6
    my ($in0, $out0) = @{ $data[$i] };
Packit Service 3bf9d6
Packit Service 3bf9d6
    my ($x, $got);
Packit Service 3bf9d6
Packit Service 3bf9d6
    my $test = qq|\$x = $LIB->_new("$in0"); |
Packit Service 3bf9d6
             . qq|\$got = $LIB->_is_even(\$x);|;
Packit Service 3bf9d6
Packit Service 3bf9d6
    diag("\n$test\n\n") if $ENV{AUTHOR_DEBUGGING};
Packit Service 3bf9d6
Packit Service 3bf9d6
    eval $test;
Packit Service 3bf9d6
    is($@, "", "'$test' gives emtpy \$\@");
Packit Service 3bf9d6
Packit Service 3bf9d6
    subtest "_is_even() in scalar context: $test", sub {
Packit Service 3bf9d6
        plan tests => 2,
Packit Service 3bf9d6
Packit Service 3bf9d6
        is(ref($got), "",
Packit Service 3bf9d6
           "'$test' output arg is a scalar");
Packit Service 3bf9d6
Packit Service 3bf9d6
        ok($got && $out0 || !$got && !$out0,
Packit Service 3bf9d6
           "'$test' output arg has the right value");
Packit Service 3bf9d6
    };
Packit Service 3bf9d6
}