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

Re: [XP] TDD question from a student

Expand Messages
  • yahoogroups@jhrothjr.com
    From: Gary F. Pollice Sent: Sunday, February 08, 2004 2:16 PM Subject: [XP] TDD question from a student
    Message 1 of 3 , Feb 8, 2004
    • 0 Attachment
      From: "Gary F. Pollice" <gpollice.at.cs.wpi.edu@...>
      Sent: Sunday, February 08, 2004 2:16 PM
      Subject: [XP] TDD question from a student


      > I've got a question a student asked during one of my classes when we were
      > discussing TDD. I have some answers, but I thought I'd ask this community
      > because you all have different experiences and I want to provide as much
      > of a complete perspective to him.
      >
      > The question is, how would you do TDD for implementing code that has
      > somewhat random behavior, such as shuffling a deck of cards. If I think
      > about how I might break this down, I can come up with some unit tests I
      > can describe and write, but the ultimate behavior is one that simply says
      > that the result is some permutation of the original sequence, including
      > the possibility of no change. Clearly, from a testing viewpoint, I would
      > run the tests some number of times to try to determine if there is random
      > behavior. But, from the TDD viewpoint, what tests would you write first in
      > order to implement a solution to such a problem.
      >
      > I'm looking forward to the answers.

      I'd mock out the random number generator.

      John Roth

      > --Gary
      > --------------------------------------------------------------------------
      ------------------
      > Gary Pollice gpollice@...
      > Professor of Practice gpollice@...
      > (alternate)
      > Worcester Polytechnic Institute Office: 508-831-6793
      > 100 Institute Road Mobile: 978-798-0019
      > Worcester, MA 01609-2280
      > http://www.cs.wpi.edu/~gpollice/
    • Steven Gordon
      It is important to see that TDD would allow you to write the vast majority of your tests so that they specify what the behavior should be with a specific card
      Message 2 of 3 , Feb 8, 2004
      • 0 Attachment
        It is important to see that TDD would allow you to write the vast majority of your tests so that they specify what the behavior should be with a specific card hand or sequence of cards (or whatever). The code to pass those tests would then assume that the specific cards were an input.

        It is only after you have driven the construction of suitable objects with deterministic tests that you should then worry about writing the object that provides random sequences of cards to these objects. If your stories do not express a specific requirement (or at least a concern) about how random the behavior of the system should be, I would expect that you would do the simplest thing and just use whatever random number generator happened to be available in the language or system. It would be wrong to assume that the customer wants you to use the time they are paying you for to research random number generators and build or integrate the best possible one, when the built-in one might be good enough.

        Steven Gordon

        ]-----Original Message-----
        ]From: Gary F. Pollice [mailto:gpollice@...]
        ]Sent: Sunday, February 08, 2004 9:16 PM
        ]To: extremeprogramming@yahoogroups.com
        ]Subject: [XP] TDD question from a student
        ]
        ]
        ]I've got a question a student asked during one of my classes
        ]when we were discussing TDD. I have some answers, but I
        ]thought I'd ask this community because you all have different
        ]experiences and I want to provide as much of a complete
        ]perspective to him.
        ]
        ]The question is, how would you do TDD for implementing code
        ]that has somewhat random behavior, such as shuffling a deck of
        ]cards. If I think about how I might break this down, I can
        ]come up with some unit tests I can describe and write, but the
        ]ultimate behavior is one that simply says that the result is
        ]some permutation of the original sequence, including the
        ]possibility of no change. Clearly, from a testing viewpoint, I
        ]would run the tests some number of times to try to determine
        ]if there is random behavior. But, from the TDD viewpoint, what
        ]tests would you write first in order to implement a solution
        ]to such a problem.
        ]
        ]I'm looking forward to the answers.
        ]
        ] --Gary
        ]---------------------------------------------------------------
        ]-----------------------------
        ]Gary Pollice gpollice@...
        ]Professor of Practice gpollice@...
        ](alternate)
        ]Worcester Polytechnic Institute Office:
        ]508-831-6793
        ]100 Institute Road Mobile: 978-798-0019
        ]Worcester, MA 01609-2280
        ]http://www.cs.wpi.edu/~gpollice/
        ]
        ]
        ]
        ]
        ]
        ]To Post a message, send it to: extremeprogramming@...
        ]
        ]To Unsubscribe, send a blank message to:
        ]extremeprogramming-unsubscribe@...
        ]
        ]ad-free courtesy of objectmentor.com
        ]Yahoo! Groups Links
        ]
        ]
        ]
        ]
        ]
        ]



        To Post a message, send it to: extremeprogramming@...

        To Unsubscribe, send a blank message to: extremeprogramming-unsubscribe@...

        ad-free courtesy of objectmentor.com
        Yahoo! Groups Links








        [Non-text portions of this message have been removed]
      • Victor
        The way I understand it, there is a parallel between TDD and acceptance tests on one hand and validation and verification on the other. TDD is deterministic.
        Message 3 of 3 , Feb 8, 2004
        • 0 Attachment
          The way I understand it, there is a parallel between TDD and acceptance
          tests on one hand and validation and verification on the other.

          TDD is deterministic. You know in advance what the expected result should
          be, and you check that the code actually achieves that result. On the other
          hand, acceptance tests are designed to ensure that the knowledge domain the
          software is designed to express is adequately represented.

          So, I would not include the test of randomness quality as part of TDD.
          However, as a separate test, I would have a profile of randomness to
          demonstrate that it is part of the application. One way of doing it is to
          run twice something like a million cycle loop and look at the distribution
          of results over the various values of the cards in each case. The results
          should be quite similar, yet different for each card, and for each run.

          This is something very easy to do in Smalltalk, because one of its
          collections is a Bag. Bags are similar to sets, in the sense that they are
          not ordered. But they accept multiple copies of the same element. A
          Smalltalk Bag keeps a tally of how many copies of the same element it has
          collected. So, you just drop the result of drawing a card into the bag, and
          at the end ask the bag how many of this result you have, for each card or
          for all the cards, and that's the distribution of outcomes.

          Victor


          >
          > ]-----Original Message-----
          > ]From: Gary F. Pollice [mailto:gpollice@...]
          > ]Sent: Sunday, February 08, 2004 9:16 PM
          > ]To: extremeprogramming@yahoogroups.com
          > ]Subject: [XP] TDD question from a student
          > ]
          > ]
          > ]I've got a question a student asked during one of my classes
          > ]when we were discussing TDD. I have some answers, but I
          > ]thought I'd ask this community because you all have different
          > ]experiences and I want to provide as much of a complete
          > ]perspective to him.
          > ]
          > ]The question is, how would you do TDD for implementing code
          > ]that has somewhat random behavior, such as shuffling a deck of
          > ]cards. If I think about how I might break this down, I can
          > ]come up with some unit tests I can describe and write, but the
          > ]ultimate behavior is one that simply says that the result is
          > ]some permutation of the original sequence, including the
          > ]possibility of no change. Clearly, from a testing viewpoint, I
          > ]would run the tests some number of times to try to determine
          > ]if there is random behavior. But, from the TDD viewpoint, what
          > ]tests would you write first in order to implement a solution
          > ]to such a problem.
          > ]
          > ]I'm looking forward to the answers.
          > ]
          > ] --Gary
          > ]---------------------------------------------------------------
          > ]-----------------------------
          > ]Gary Pollice gpollice@...
          > ]Professor of Practice gpollice@...
          > ](alternate)
          > ]Worcester Polytechnic Institute Office:
          > ]508-831-6793
          > ]100 Institute Road Mobile: 978-798-0019
          > ]Worcester, MA 01609-2280
          > ]http://www.cs.wpi.edu/~gpollice/
          > ]
          > ]
          > ]
          > ]
          > ]
          > ]To Post a message, send it to: extremeprogramming@...
          > ]
          > ]To Unsubscribe, send a blank message to:
          > ]extremeprogramming-unsubscribe@...
          > ]
          > ]ad-free courtesy of objectmentor.com
          > ]Yahoo! Groups Links
          > ]
          > ]
          > ]
          > ]
          > ]
          > ]
          >
          >
          >
          > To Post a message, send it to: extremeprogramming@...
          >
          > To Unsubscribe, send a blank message to:
          extremeprogramming-unsubscribe@...
          >
          > ad-free courtesy of objectmentor.com
          > Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >
          >
          > [Non-text portions of this message have been removed]
          >
          >
          >
          > To Post a message, send it to: extremeprogramming@...
          >
          > To Unsubscribe, send a blank message to:
          extremeprogramming-unsubscribe@...
          >
          > ad-free courtesy of objectmentor.com
          > Yahoo! Groups Links
          >
          >
          >
          >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.