Attachment 'nimtest.py'

Download

   1 #!/usr/bin/env python
   2 
   3 import unittest
   4 from nim import *
   5 
   6 class GameTests(unittest.TestCase):
   7     def testEmptyGame(self):
   8         game = Game([])
   9         self.assertEquals(len(game.board), 0)
  10 
  11     def testGameWithOnePileOfOneMatch(self):
  12         game = Game([1])
  13         self.assertEquals(len(game.board), 1)
  14         self.assertEquals(game.board[0], 1)
  15 
  16     def testGameWithTwoPiles(self):
  17         game = Game([1, 1])
  18         self.assertEquals(len(game.board), 2)
  19         
  20     def testTakeOneMatchFromOnePile(self):
  21         game = Game([1])
  22         win = game.takeMatches(matches=1, pile=0)
  23         self.assertEquals(game.board[0], 0)
  24         self.assertEquals(win, True)
  25         self.assertEquals(len(game.board), 1)
  26 
  27     def testTakeOneMatchFromTwoPiles(self):
  28         game = Game([1, 6])
  29         win = game.takeMatches(matches=1, pile=0)
  30         self.assertEquals(game.board[1], 6)
  31         self.assertEquals(win, False)
  32         self.assertEquals(len(game.board), 2)
  33 
  34     def testTakeTwoMatchesWhenTheresOnlyOne(self):
  35         game = Game([1])
  36         self.assertRaises(NotEnoughMatchesError, game.takeMatches, matches=2, pile=0)
  37 
  38     def testTakeNegativeMatches(self):
  39         game = Game([1])
  40         try:
  41             win = game.takeMatches(matches=-1, pile=0)
  42             self.fail()
  43         except MustTakePositiveMatchesError, e:
  44             # Expected
  45             pass
  46 
  47     def testTakeZeroMatches(self):
  48         game = Game([1])
  49         try:
  50             win = game.takeMatches(matches=0, pile=0)
  51             self.fail()
  52         except MustTakePositiveMatchesError, e:
  53             # Expected
  54             pass
  55 
  56     
  57 
  58 if __name__ == "__main__":
  59     unittest.main()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-08-22 11:57:03, 47.0 KB) [[attachment:Unit-testing.ppt]]
  • [get | view] (2005-08-23 09:36:41, 19.1 KB) [[attachment:autocode.sxi]]
  • [get | view] (2009-10-14 02:15:46, 2381.8 KB) [[attachment:fs_and_filelike.tar.gz]]
  • [get | view] (2005-08-23 09:27:43, 0.6 KB) [[attachment:nim.py]]
  • [get | view] (2005-08-23 09:28:10, 1.6 KB) [[attachment:nimtest.py]]
  • [get | view] (2009-12-09 00:01:57, 16.7 KB) [[attachment:promise.odp]]
  • [get | view] (2005-08-23 09:30:09, 108.1 KB) [[attachment:twisted.sxi]]
  • [get | view] (2010-02-01 11:49:31, 95.5 KB) [[attachment:withrestart.pdf]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

Unable to edit the page? See the FrontPage for instructions.