Experimental Image::BoxFind module:    Image/t/07-determine_pixpat_transverse.t


     # Test file created outside of h2xs framework.
# Run this like so: `perl Image-BoxFind.t'
#   doom@kzsu.stanford.edu     2007/10/20 23:12:54

use warnings;
use strict;
$|=1;
my $DEBUG = 0;

use Test::More;
BEGIN { plan tests => 13 };

use Data::Dumper;
use File::Basename qw( basename );

use FindBin qw( $Bin );
use lib "$Bin/../..";
my $lib = "$Bin/../..";

BEGIN { #1
  use_ok( 'Image::BoxFind' );
}

# 2
ok(1, "Traditional: If we made it this far, we're ok.");

{
  my $test_name = "average_array_of_colors";
  my $bf = Image::BoxFind->new( {
                                  DEBUG      => $DEBUG,
                                } );

  my @colors = ('10878,10900,10878,0',
                '10790,10749,10702,0',
                '9292,9232,9204,0',
                '6826,6826,6826,0',
               );

  my $expected = '9446,9427,9402,0';

  my $result = $bf->average_array_of_colors(\@colors);
  is( $result, $expected ,"Testing $test_name" );


  @colors = (  '10878,10900,10878,0',
               '10790,10749,10702,0',
               '9292,9232,9204,0',
               '6826,6826,6826,0',
               '10878,10900,10878,0',
               '10790,10749,10702,0',
               '9292,9232,9204,0',
               '6826,6826,6826,0',
               '10878,10900,10878,0',
               '10790,10749,10702,0',
               '9292,9232,9204,0',
               '6826,6826,6826,0',
               );

  $expected = '9446,9427,9402,0';

  $result = $bf->average_array_of_colors(\@colors);
  is( $result, $expected ,"Testing $test_name" );
}

{
  my $test_name = "determine_pixpat_transverse";
  my $image_file = "$Bin/dat/images/simple_test.jpeg";
  my $basename = basename( $image_file );
  my $bf = Image::BoxFind->new( { image_file => $image_file,
                                  DEBUG      => $DEBUG,
                                } );

#  $bf->set_spotsize_x( 3 );
#  $bf->set_spotsize_y( 4 );

  $bf->set_forward_horizon( 3 );
  $bf->set_transverse_horizon( 4 );

  $bf->set_direction('x_plus');
  my $result = $bf->determine_pixpat_transverse( 10, 10 );
  $bf->debug( "determine_pixpat_transverse: " . Dumper($result) . "\n" );

  my $white = '65535,65535,65535,0';
  my $expected = [ $white, $white, $white, $white ];
  is_deeply( $result, $expected
             ,"Testing $test_name on $basename 3x4 x+ (10,10) white bg" );
}

{
  my $test_name = "determine_pixpat_transverse";
  my $image_file = "$Bin/dat/images/simple_test.png";
  my $basename = basename( $image_file );
  my $bf = Image::BoxFind->new( { image_file => $image_file,
                                  DEBUG      => $DEBUG,
                                } );

  $bf->set_forward_horizon( 3 );
  $bf->set_transverse_horizon( 4 );

  $bf->set_direction('x_plus');
  my $result = $bf->determine_pixpat_transverse( 100, 7 );
  $bf->debug( "determine_pixpat_transverse: " . Dumper($result) . "\n" );

  my $expected = [
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '52000,61937,54313,0',
          '45232,60138,48702,0'
        ];
  is_deeply( $result, $expected
       ,"Testing $test_name on $basename 3x4 x+ (100,7) above green box" );
}

{
  my $test_name = "determine_pixpat_transverse";
  my $image_file = "$Bin/dat/images/firefox_save_as.png";
  my $basename = basename( $image_file );
  my $bf = Image::BoxFind->new( { image_file => $image_file,
                                  DEBUG      => $DEBUG,
                                } );

#  $bf->set_spotsize_x( 3 );
#  $bf->set_spotsize_y( 8 );

  $bf->set_forward_horizon( 3 );
  $bf->set_transverse_horizon( 8 );

  $bf->set_direction('x_plus');
  my $result = $bf->determine_pixpat_transverse( 200, 11 );
  $bf->debug( "determine_pixpat_transverse: " . Dumper($result) . "\n" );

  my $expected = [
          '61423,61423,61423,0',
          '44204,51914,58724,0',
          '34352,44375,53199,0',
          '42148,49665,56283,0',
          '46825,52839,58133,0',
          '49944,54955,59367,0',
          '52171,56467,60248,0',
          '53842,57600,60909,0'
        ];
  is_deeply( $result, $expected
        ,"Testing $test_name on $basename 3x8 x+ (200,11) 'Name' box" );


  $result = $bf->determine_pixpat_transverse( 320, 128 );
  $bf->debug( "determine_pixpat_transverse: " . Dumper($result) . "\n" );

  $expected = [
          '61423,61423,61423,0',
          '49858,49858,49858,0',
          '54570,54570,54570,0',
          '56861,56861,56861,0',
          '58185,58185,58185,0',
          '59024,59024,59024,0',
          '59587,59587,59587,0',
          '59977,59913,59881,0'
        ];
  is_deeply( $result, $expected
     ,"Testing $test_name on $basename 3x8 x+ (320,128) 'Cancel' button" );


#  $bf->set_spotsize_x( 8 );
#  $bf->set_spotsize_y( 3 );

  $bf->set_forward_horizon( 3 );
  $bf->set_transverse_horizon( 8 );

  $bf->set_direction('y_plus');
  $result = $bf->determine_pixpat_transverse( 112, 25 );
  $bf->debug( "determine_pixpat_transverse: " . Dumper($result) . "\n" );

  $expected = [
          '61423,61423,61423,0',
          '26985,42405,56026,0',
          '14649,29298,42148,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '19275,19275,19275,0',
          '32296,32296,32296,0'
        ];
  is_deeply( $result, $expected ,"Testing $test_name on $basename 8x3 y+ (112,25) 'Name' box" );

#  $bf->set_spotsize_x( 8 );
#  $bf->set_spotsize_y( 1 );

  $bf->set_forward_horizon( 1 );
  $bf->set_transverse_horizon( 8 );

  $bf->set_direction('y_plus');
  $result = $bf->determine_pixpat_transverse( 112, 25 );
  $bf->debug( "determine_pixpat_transverse: " . Dumper($result) . "\n" );

  $expected = [
          '61423,61423,61423,0',
          '26985,42405,56026,0',
          '14649,29298,42148,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '7196,7196,7196,0',
          '43176,43176,43176,0'
        ];
  is_deeply( $result, $expected ,"Testing $test_name on $basename 8x1 y+ (112,25) 'Name' box" );


  $bf->set_spotsize_x( 8 );
  $bf->set_spotsize_y( 1 );

  $bf->set_direction('y_plus');
  $result = $bf->determine_pixpat_transverse( 112, 26 );
  $bf->debug( "determine_pixpat_transverse: " . Dumper($result) . "\n" );

  $expected = [
          '61423,61423,61423,0',
          '26985,42405,56026,0',
          '14649,29298,42148,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '4883,4883,4883,0',
          '44718,44718,44718,0'
        ];
  is_deeply( $result, $expected ,"Testing $test_name on $basename 8x3 y+ (112,26) 'Name' box" );
}


{
  my $test_name = "has_pixpat_changed";
  my $bf = Image::BoxFind->new( {
                                  DEBUG      => $DEBUG,
                                } );

  my ($pixpat1, $pixpat2, $ret);

  $pixpat1 = [
          '61423,61423,61423,0',
          '26985,42405,56026,0',
          '14649,29298,42148,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '7196,7196,7196,0',
          '43176,43176,43176,0'
        ];

  @{ $pixpat2 } = @{ $pixpat1 };

  $ret = $bf->has_pixpat_changed( $pixpat1, $pixpat2 );
  is( $ret, '', "Testing $test_name with no change");

  $pixpat2 = [
          '61423,61423,61423,0',
          '26985,42406,56026,0',
          '14649,29298,42148,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '65535,65535,65535,0',
          '7196,7196,7196,0',
          '43176,43176,43176,0'
        ];

  $ret = $bf->has_pixpat_changed( $pixpat1, $pixpat2 );
  is( $ret, 1, "Testing $test_name with a slight change");
}




     

Joseph Brenner, Tue Nov 27 17:40:02 2007