Loading ...
Sorry, an error occurred while loading the content.
 

Re: [XP] Testing experiences

Expand Messages
  • Ron Jeffries
    ... I d think Piece would know where it MIGHT go, sort of like this: Bishop listRawMoves = { x,y | exists n: X,Y = loc(): x = X+/-n; y = Y +/- n & 0
    Message 1 of 66 , Aug 1, 2000
      At 02:03 PM 8/1/2000 +0200, Johannes Brodwall wrote:
      >* When trying to Unit Test my Chessboard program, I thought it would
      >be reasonable to test Piece objects separately. The public functions
      >of Piece is currently "listMoves" and "executeMove". Both of these
      >functions are very dependent upon the ChessBoard, e.g. for looking
      >for intervening pieces.

      I'd think Piece would know where it MIGHT go, sort of like this:
      Bishop listRawMoves =
      { x,y | exists n: X,Y = loc(): x = X+/-n; y = Y +/- n & 0<=x<=7, 0<=y<=7}

      Bishop PathOK(x,y) = BoardUnoccupied(xi, yi), x<xi<X, y<yi<Y (x,y < X,Y w/o
      loss of generality)

      Bishop LegalMove(x,y) = PathOK & (BoardUnoccupied(x,y) |
      PieceAt(x,y).color() != this.color()

      Then it's "easy" to build a Board that just understands Unoccupied and
      PieceAt. I'd think those could be written and perhaps not even need tests,
      since they're nothing but a 2-d array or similar. I'd think Board would be
      a dumb repository, but I'm just guessing.

      >In other words, Piece and Board are tightly
      >coupled. Should I try and break these classes more apart? (If so,
      >any hints as to how would be appreciated).

      Pass Board as a parameter to pieces when asking them questions? That may be
      inconvenient, as it may be desirable for all pieces to know the board.
      Then, for testing, consider having "friend" setters that let you whack the
      board for testing purposes - or just create the test pieces with a
      hand-crafted board.

      Just musing ...

      Ron Jeffries
      www.XProgramming.com
    • Mark Wilden
      ... From: Robert C. Martin ... No, I hate you. :) That s a bit too clever (i.e. I m not clever enough!).
      Message 66 of 66 , Aug 14, 2000
        ----- Original Message -----
        From: "Robert C. Martin" <rmartin@...>
        > >
        > > Sorry to be dense, but what is MT?
        >
        > You're going to hate yourself. MT is an abbreviation for "empty".

        No, I hate you. :) That's a bit too clever (i.e. I'm not clever enough!).
      Your message has been successfully submitted and would be delivered to recipients shortly.