>
> So let's say that in the unit tests.  Add assertions that we want
> those four starred points to be legal moves.
>
> #############################################
> import unittest
>
> class ReversiTests(unittest.TestCase):
>     def testIslegalMoveOnExistingSpots(self):
>         logic = ReversiGameLogic()
>         # Placing on existing spots should not be legal.
>         self.assertFalse(logic.isLegalMove(4, 3))
>         self.assertFalse(logic.isLegalMove(3, 4))
>         self.assertFalse(logic.isLegalMove(3, 3))
>         self.assertFalse(logic.isLegalMove(4, 4))
>
>
>     def testIsLegalMoveGood(self):
>         logic = ReversiGameLogic()
>         # But here are spots that should be legal.
>         self.assertTrue(logic.isLegalMove(2, 3))
>         ...  ## fill me in with the other three legal moves!
>
>
> if __name__ == '__main__':
>     unittest.main()
> ##############################################


Sorry: I sent this draft a bit too early!  There really should be at
least one more test that we need to have;  we need to check for moves
that are not legal, but for fundamental Reversi-based reasons.

For example, we *know* that playing on (1, 1) can't be legal when the
game is starting: it's an empty spot on the board, but it's not
adjacent to a line of white pieces.

This is the sort of thing that would be an appropriate to write as a test:

###################################################
import unittest

class ReversiTests(unittest.TestCase):
    def testIslegalMoveOnExistingSpots(self):
        logic = ReversiGameLogic()
        # Placing on existing spots should not be legal.
        self.assertFalse(logic.isLegalMove(4, 3))
        self.assertFalse(logic.isLegalMove(3, 4))
        self.assertFalse(logic.isLegalMove(3, 3))
        self.assertFalse(logic.isLegalMove(4, 4))


    def testIsLegalMoveGood(self):
        logic = ReversiGameLogic()
        # But here are spots that should be legal.
        self.assertTrue(logic.isLegalMove(2, 3))
        ## ... fill me in with the other three legal moves!


    def testIsLegalMoveNotAdjacentAttackLine(self):
        logic = ReversiGameLogic()
        # But here is a spot that should be illegal.
        self.assertTrue(logic.isLegalMove(1, 1))


if __name__ == '__main__':
    unittest.main()
####################################################


You'll should see that one of the tests is succeeding, which is great!
 That's what you want to see: partial success.   It means that you're
going in the right direction, and that you just need to amend what
you've got so far.


It should also point out two concrete ways in which your program isn't
quite working yet.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to