Experimental Image::BoxFind module:    Image/t/14-set_direction.t


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

use warnings;
use strict;
$|=1;
my $DEBUG = 0;
use Data::Dumper;

use Test::More;
BEGIN { plan tests => 8 };
use Test::Number::Delta;

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 $image_bin = "$Bin/dat/images";
my $bf_attributes = {
     pixpat_delta_method => 'has_pixpat_changed_past_threshold',
     allow_pixpat_drift  =>  1,
     pixpat_threshold    =>  500,
     rectangle_finder    =>  'boxfind_downward_via_pixpat',
     spotsize_x         => 4,
     spotsize_y         => 8,
     refocus_factor     => 4,
     forward_horizon    =>  3,
     transverse_horizon =>  7,
     edge_contrast_cutoff => 100,

     # used by 'looks_rectangular'
     fuzziness   => 5,
     minimum_height => 10,
     minimum_width  => 10,

     # used by 'roughly_raster'
     beware => 0,
     step_x => 25,
     step_y => 10,

     image_file => "$image_bin/firefox_save_as.png",

    };


{ #3
  my $test_name = 'set_direction';
  my $new_direction = 'x_plus';
  my $bf = Image::BoxFind->new( $bf_attributes );
  my $spotsize_x_0 = $bf->spotsize_x;
  my $spotsize_y_0 = $bf->spotsize_y;

  my $forward_horizon_0    = $bf->forward_horizon;
  my $transverse_horizon_0 = $bf->transverse_horizon;

  my $direction_0 = $bf->direction || '';

  $bf->set_direction( $new_direction );

  my $spotsize_x_1 = $bf->spotsize_x;
  my $spotsize_y_1 = $bf->spotsize_y;

  my $forward_horizon_1    = $bf->forward_horizon;
  my $transverse_horizon_1 = $bf->transverse_horizon;

  my $direction_1 = $bf->direction || '';

  if ($DEBUG) {
    printf "%25s %8d %8d\n", 'spotsize_x: ',         $spotsize_x_0,               $spotsize_x_1;
    printf "%25s %8d %8d\n", 'spotsize_y: ',         $spotsize_y_0,               $spotsize_y_1;
    printf "%25s %8d %8d\n", 'forward_horizon: ',    $forward_horizon_0,    $forward_horizon_1;
    printf "%25s %8d %8d\n", 'transverse_horizon: ', $transverse_horizon_0, $transverse_horizon_1;
    printf "%25s %8s %8s\n", 'direction: ',          $direction_0,          $direction_1;
  }

  is( $direction_1, $new_direction, "Testing $test_name direction is now $new_direction");
  is( $spotsize_x_1, $forward_horizon_1, "Testing $test_name spotsize_x is now forward_horizon");
  is( $spotsize_y_1, $transverse_horizon_1, "Testing $test_name spotsize_y is now transverse_horizon");

}

{ #4
  my $test_name = 'set_direction';
  my $new_direction = 'y_plus';
  my $bf = Image::BoxFind->new( $bf_attributes );
  my $spotsize_x_0 = $bf->spotsize_x;
  my $spotsize_y_0 = $bf->spotsize_y;

  my $forward_horizon_0    = $bf->forward_horizon;
  my $transverse_horizon_0 = $bf->transverse_horizon;

  my $direction_0 = $bf->direction || '';

  $bf->set_direction( $new_direction );

  my $spotsize_x_1 = $bf->spotsize_x;
  my $spotsize_y_1 = $bf->spotsize_y;

  my $forward_horizon_1    = $bf->forward_horizon;
  my $transverse_horizon_1 = $bf->transverse_horizon;

  my $direction_1 = $bf->direction || '';

  if ($DEBUG) {
    printf "%25s %8d %8d\n", 'spotsize_x: ',         $spotsize_x_0,         $spotsize_x_1;
    printf "%25s %8d %8d\n", 'spotsize_y: ',         $spotsize_y_0,         $spotsize_y_1;
    printf "%25s %8d %8d\n", 'forward_horizon: ',    $forward_horizon_0,    $forward_horizon_1;
    printf "%25s %8d %8d\n", 'transverse_horizon: ', $transverse_horizon_0, $transverse_horizon_1;
    printf "%25s %8s %8s\n", 'direction: ',          $direction_0,          $direction_1;
  }

  is( $direction_1, $new_direction, "Testing $test_name direction is now $new_direction");
  is( $spotsize_x_1, $transverse_horizon_1, "Testing $test_name spotsize_x is now transverse_horizon");
  is( $spotsize_y_1, $forward_horizon_1, "Testing $test_name spotsize_y is now forward_horizon");

}




     

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