Attachment 'todd_gijs_test.py'

Download

   1 import reversi
   2 
   3 from nose.tools import assert_equals
   4 
   5 TEST_BOARD = ["....",
   6               ".bw.",
   7               ".wb.",
   8               "...."]
   9 
  10 TEST_BOARD2 = ['....',
  11                '.w..',
  12                'bww.',
  13                'wb..']
  14 
  15 
  16 def test_simple():
  17     assert_equals(reversi.legal_moves(TEST_BOARD, "w"), set([(0, 1), (1, 0), (2, 3), (3, 2)]))
  18     assert_equals(reversi.legal_moves(TEST_BOARD2, "w"), set([(1, 0), (3, 2)]))
  19 
  20 def test_find_pieces():
  21     assert_equals(reversi.find_pieces(TEST_BOARD, 'b'), set([(1, 1), (2, 2)]))
  22     assert_equals(reversi.find_pieces(TEST_BOARD, 'w'), set([(2, 1), (1, 2)]))
  23     assert_equals(reversi.find_pieces(TEST_BOARD2, 'b'), set([(2, 0), (3, 1)]))
  24 
  25 def test_check_direction():
  26     assert_equals(reversi.check_direction(TEST_BOARD, (1, 1), (0, 1)), (1, 3))
  27     assert_equals(reversi.check_direction(TEST_BOARD, (2, 2), (-1, -1)), None)
  28     assert_equals(reversi.check_direction(TEST_BOARD, (2, 1), (1, 0)), None)
  29     assert_equals(reversi.check_direction(TEST_BOARD, (2, 1), (-1, 0)), (0, 1))
  30     assert_equals(reversi.check_direction(TEST_BOARD2, (2, 0), (0, 1)), (2, 3))
  31     assert_equals(reversi.check_direction(TEST_BOARD2, (2, 0), (0, -1)), None)
  32 
  33 def test_find_valid_paths():
  34     assert_equals(reversi.find_valid_paths(TEST_BOARD, (1, 1), ), set([(1, 3), (3, 1)]))
  35     assert_equals(reversi.find_valid_paths(TEST_BOARD, (1, 2)), set([(1, 0), (3, 2)]))
  36     assert_equals(reversi.find_valid_paths(TEST_BOARD, (2, 1)), set([(2, 3), (0, 1)]))
  37     assert_equals(reversi.find_valid_paths(TEST_BOARD, (2, 2)), set([(2, 0), (0, 2)]))
  38     assert_equals(reversi.find_valid_paths(TEST_BOARD2, (2, 0)), set([(2, 3), (0, 2)]))
  39     assert_equals(reversi.find_valid_paths(TEST_BOARD2, (2, 1)), set([]))
  40 
  41 if __name__ == '__main__':
  42     import nose
  43     nose.run()

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.

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

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