June 08 2015 A Development Tool for Library Code Back

Refactoring: Add Command-Line Switches

        # get_3_intersection.pl
        use strict;
        use warnings;
        use 5.10.1;
        use Test::More qw( no_plan );
        use Benchmark qw( timethis );
        use Getopt::Long;
        use lib '/home/jkeenan/gitwork/list-compare/blib/lib';
        use List::Compare::Functional qw( get_intersection );
        my ($tests_only, $benchmarks_only);
        GetOptions(
            "tests-only"        => \$tests_only,
            "benchmarks-only"   => \$benchmarks_only,
        ) or die("Error in command line arguments");
        die("Select either 'tests-only' or 'benchmarks-only' -- but not both!")
            if ($tests_only && $benchmarks_only);
        if ($benchmarks_only) { pass("Running benchmarks only") };
        if ($tests_only)      { pass("Running tests only") };
        my $medium  = [ 1001 ..   4000 ]; my $small   = [  991 ..   1010 ];
        say "List::Compare::Functional version: ", sprintf("%.5f" => $List::Compare::Functional::VERSION);
        my ($args, $expect, @int, $seen);
        $args   = [ $medium, $small ]; $expect = { map { $_ => 1 } ( 1001 .. 1010 ) };
        unless ($benchmarks_only) {
          @int    = get_intersection( $args);
          $seen   = { map { $_ => 1} @int };
          is_deeply($seen, $expect, "Got expected intersection");
        }
        unless ($tests_only) {
          timethis( 1_000, sub { get_intersection($args) } );
        }


Home Last TOC Copyright © 2015 James E Keenan Back Next