Experimental Image::BoxFind module: Image/t/00-basics-scan_right_one_pix-major_color-average_color.t
# Test file created outside of h2xs framework.
# Run this like so: `perl Image-BoxFind.t'
# doom@kzsu.stanford.edu 2007/09/29 05:22:54
#########################
use warnings;
use strict;
$|=1;
my $DEBUG = 0;
use Data::Dumper;
use Test::More;
BEGIN { plan tests => 17 };
use FindBin qw( $Bin );
use lib "$Bin/../..";
BEGIN {
use_ok( 'Image::BoxFind' );
}
ok(1, "Traditional: If we made it this far, we're ok.");
{ # *Now* it's possible to initialize object without an image_file
my $test_name = "basic instantiation";
my $bf = Image::BoxFind->new();
my $class = ref $bf;
is( $class, "Image::BoxFind", "Testing $test_name" );
}
{
my $test_name = "getting dimensions of an image";
my $image_file = "$Bin/dat/images/simple_test.jpeg";
my $bf = Image::BoxFind->new( { image_file => $image_file,
DEBUG => $DEBUG,
} );
my ($height, $width) = $bf->dimensions();
is( $height, 50 ,"Testing $test_name: height" );
is( $width, 150 ,"Testing $test_name: width" );
}
{
my $test_name = "getting background color of an image";
my $image_file = "$Bin/dat/images/simple_test.jpeg";
my $bf = Image::BoxFind->new( { image_file => $image_file,
DEBUG => $DEBUG,
} );
my $bg_color_string = $bf->background_color();
my $white = 65535;
is( $bg_color_string, "$white,$white,$white,0" ,"Testing $test_name" );
}
{
my $test_name = "scan for change in background color";
my $image_file = "$Bin/dat/images/simple_test.jpeg";
my $bf = Image::BoxFind->new( { image_file => $image_file,
DEBUG => $DEBUG,
} );
$bf->set_cursor_y( 25 );
$bf->set_cursor_x( 0 );
my $x_value = $bf->scan_right_one_pix;
is( $x_value, 15 ,"Testing $test_name: horizontally" );
$bf->set_cursor_y( 0 );
$bf->set_cursor_x( 70 );
my $y_value = $bf->scan_down_one_pix;
is( $y_value, 2 ,"Testing $test_name: vertically" );
$bf->set_cursor_y( 25 );
$y_value = $bf->scan_down_one_pix;
is( $y_value, 30 ,"Testing $test_name: restarted vertical" );
}
{
my $test_name = "major_color method";
my $image_file = "$Bin/dat/images/gimp_open_dialog.png"; # better than jpeg
my @spots = (
[ 25, 25 ],
[ 200, 200 ],
[ 200, 350 ],
[ 220, 110 ],
);
# verified via the gimp
my @expects = (
'65535,65535,65535,0',
'65535,65535,65535,0',
'57078,56172,54964,0',
'19026,27046,33824,0',
);
my $bf = Image::BoxFind->new( { image_file => $image_file,
DEBUG => $DEBUG,
} );
# currently the defaults, but this might change
$bf->set_spotsize_x( 10 );
$bf->set_spotsize_y( 10 );
foreach my $spot (@spots) {
my $expect = shift @expects ;
my ($x, $y) = @{ $spot };
$bf->set_cursor_x( $x );
$bf->set_cursor_y( $y );
my $c = $bf->major_color();
is( $c, $expect, "Testing $test_name: ($x, $y) - $expect");
}
}
{
my $test_name = "average_color method";
my $image_file = "$Bin/dat/images/gimp_open_dialog.png"; # better than jpeg
my @spots = (
[ 25, 25 ],
[ 200, 200 ],
[ 200, 350 ],
[ 220, 110 ],
);
my @expects = ( # values not yet verified TODO
'29078,29126,28581,0',
'32767,32767,32767,0',
'28539,28086,27482,0',
'19935,21059,22207,0',
);
my $bf = Image::BoxFind->new( { image_file => $image_file,
DEBUG => $DEBUG,
} );
# currently the defaults, but this might change
$bf->set_spotsize_x( 10 );
$bf->set_spotsize_y( 10 );
foreach my $spot (@spots) {
my $expect = shift @expects ;
my ($x, $y) = @{ $spot };
$bf->set_cursor_x( $x );
$bf->set_cursor_y( $y );
my $c = $bf->average_color();
is( $c, $expect, "Testing $test_name: ($x, $y) - $expect");
}
}
Joseph Brenner,
Tue Nov 27 17:40:02 2007