def test_result_from_game_score(tc): gs = gameplay.Game_score('b', 1) result = gameplay.Result.from_game_score(gs) tc.assertEqual(result.sgf_result, 'B+1') tc.assertIsNone(result.detail) tc.assertEqual(result.winning_colour, 'b') tc.assertEqual(result.losing_colour, 'w') tc.assertIs(result.is_jigo, False) tc.assertIs(result.is_forfeit, False) tc.assertIs(result.is_unknown, False)
def test_result_from_game_score_no_margin(tc): gs = gameplay.Game_score('b', None) result = gameplay.Result.from_game_score(gs) tc.assertEqual(result.sgf_result, 'B+') tc.assertEqual(result.detail, "unknown margin") tc.assertEqual(result.winning_colour, 'b') tc.assertEqual(result.losing_colour, 'w') tc.assertIs(result.is_jigo, False) tc.assertIs(result.is_forfeit, False) tc.assertIs(result.is_unknown, False)
def __init__(self, size, moves): self._size = size self._move_iters = {} for colour in 'b', 'w': self._move_iters[colour] = iter( [x for (c, x) in moves if c == colour]) self.enabled_get_last_move_comment = set() self.score_to_return = gameplay.Game_score("w", 99) self.log = [] self.board_scored = None self.reject_vertex = None self.reject_as_error = False
def test_game_score(tc): gs1 = gameplay.Game_score('b', 1) tc.assertEqual(gs1.winner, 'b') tc.assertEqual(gs1.margin, 1) tc.assertIsNone(gs1.get_detail()) gs2 = gameplay.Game_score('w', None) tc.assertEqual(gs2.winner, 'w') tc.assertEqual(gs2.margin, None) tc.assertEqual(gs2.get_detail(), "unknown margin") gs3 = gameplay.Game_score(None, None) tc.assertEqual(gs3.winner, None) tc.assertEqual(gs3.margin, None) tc.assertEqual(gs3.get_detail(), "no score reported") gs4 = gameplay.Game_score(None, 0) tc.assertEqual(gs4.winner, None) tc.assertEqual(gs4.margin, 0) tc.assertIsNone(gs4.get_detail()) tc.assertRaisesRegexp(ValueError, r"^negative margin$", gameplay.Game_score, 'b', -1) tc.assertRaisesRegexp(ValueError, r"winner is set but margin is zero", gameplay.Game_score, 'b', 0) tc.assertRaisesRegexp(ValueError, r"no winner, but nonzero margin", gameplay.Game_score, None, 1)