Right.  You may or may not know that I'm working on a testing module for 
GD (depending if you read my journal[1] or not)

Last week I hit a wall in terms of my interface design.  Consider is:

 is
 isnt
     Checks the colour of the pixel.  This can either be
     compared to a colour index or a three digit rgb value.
     The last argument is an optional test comment.

     $tester->is(10,10,$red,"pixel is red");
     $tester->is(10,10,255,0,0,"pixel is red");
     $tester->isnt(10,10,$red,"pixel isn't red");
     $tester->isnt(10,10,255,0,0, "pixel isn't red");

Great!  Simple, and DWIM.  Now consider has:

  has
  hasnt
     Checks if a region has or hasn't (contains, or does
     not contain) at least one pixel of the defined colour.
     The arguments are the top x and y coordinates and the
     width and the height of the region to be checked, and
     the colour to be checked again.  Like is and isnt the
     colour can be specified either as a colour index or a
     three digit rgb value, and the last argument test
     comment.

  $tester->has(10,10,50,50,$red,"has a red pixel");
  $tester->has(10,10,50,50,255,0,0,"has a red pixel");
  $tester->hasnt(10,10,50,50,$red,"hasn't a red pixel");
  $tester->hasnt(10,10,50,50,255,0,0,"hasn't a red pixel");

This is great!  Or is it?  Contrast that against GD's rectangle method:

  GD::Image::rectangle($x1,$y1,$x2,$y2,$color)
     This draws a rectangle with the specified color.
     (x1,y1) and (x2,y2) are the upper left and lower right
     corners respectively.  Both real color indexes and the
     special colors gdBrushed, gdStyled and gdStyledBrushed
     are accepted.

Stop! Right, GD uses two pair coordinates, where I use width and height!  
Argh! What do I do now?

  - Change to use GD's system?  Not really how my brain works

  - Change to using a named argument pair.  e.g.

     $tester->has(x       => 10,
                  y       => 10,
                  width   => 50,
                  height  => 50,
                  red     => 255,
                  green   => 0,
                  blue    => 0,
                  comment => "has a red pixel");

    This allows me to use both, by allowing people to say x2, y2 instead 
    of width and height (and doing different things, obviously.)  But 
    effing[2] hull[3] is it overly verbose.

    Worse off, I'd have to change things like 'is' to be consistent too,
    and there's not any ambiguity with that method...

  - Optionally use name value pair.  This is very very messy but might
    be my best option.  Look out though, has can take 5,6,7 or 8 
    arguments depending if you've got a comment and colour indexes or not.

What do people do in situations like this?  Normally at this point I'd 
start saying "well you should be using more objects" and have colour and 
rectangle as objects, but I'm doing testing here and that's not really 
appropriate 

Help!  Any advice gratefully received.

Mark.

[1] http://use.perl.org/~2shortplanks/journal/
[2] see other thread.
[3] see [2]
-- 
s''  Mark Fowler                                     London.pm   Bath.pm
     http://www.twoshortplanks.com/              [EMAIL PROTECTED]
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/  +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}


Reply via email to