def test_score_path_too_short_for_double(self): path = [ Card(Suit.CASSIA, 3), Card(Suit.CASSIA, 4), Card(Suit.CASSIA, 7) ] self.assertEqual(score_path(path), 3)
def line(): a = Arboretum() a.add_card(Card(Suit.CASSIA, 1), Pos(0, 0)) a.add_card(Card(Suit.CASSIA, 8), Pos(7, 0)) for i in range(1, 7): a.add_card(Card(Suit.OAK, i + 1), Pos(i, 0)) return a
def test_score_path_from_one_to_eight(self): path = [ Card(Suit.CASSIA, 1), Card(Suit.JACARANDA, 2), Card(Suit.OAK, 4), Card(Suit.CASSIA, 8) ] self.assertEqual(score_path(path), 7)
def test_score_path_missed_double(self): path = [ Card(Suit.CASSIA, 3), Card(Suit.OAK, 4), Card(Suit.CASSIA, 6), Card(Suit.CASSIA, 7) ] self.assertEqual(score_path(path), 4)
def test_score_path_doubled(self): path = [ Card(Suit.CASSIA, 3), Card(Suit.CASSIA, 4), Card(Suit.CASSIA, 6), Card(Suit.CASSIA, 7) ] self.assertEqual(score_path(path), 8)
async def next_message(self, target_msg_type: str): async for message in self.ws: d = json.loads(message) if d['message_type'] != target_msg_type: continue if d['message_type'] == 'draw': return d.get('draw_target') elif d['message_type'] == 'move': return ( Card(Suit.from_str(d['play_suit']), int(d['play_val'])), Pos(x=int(d['play_x']), y=int(d['play_y'])), Card(Suit.from_str(d['discard_suit']), int(d['discard_val']))) raise RuntimeError( f"Unknown message type '{d['msg_type']}'. Message {message}")
def test_score_path_perfect_path(self): path = [Card(Suit.OAK, i) for i in range(1, 9)] self.assertEqual(score_path(path), 19)
def hands(): p1 = Player(1) p1.hand = [ Card(Suit.WILLOW, 1), Card(Suit.WILLOW, 2), Card(Suit.WILLOW, 3), Card(Suit.WILLOW, 4), Card(Suit.WILLOW, 5), Card(Suit.WILLOW, 6), Card(Suit.WILLOW, 7), ] p2 = Player(2) p2.hand = [ Card(Suit.WILLOW, 8), Card(Suit.OAK, 1), Card(Suit.OAK, 8), Card(Suit.JACARANDA, 1), Card(Suit.JACARANDA, 2), Card(Suit.JACARANDA, 3), ] return [p1, p2]
def test_score_path_to_eight(self): path = [Card(Suit.CASSIA, 2), Card(Suit.OAK, 4), Card(Suit.CASSIA, 8)] self.assertEqual(score_path(path), 5)
def test_score_path_from_one(self): path = [Card(Suit.CASSIA, 1), Card(Suit.OAK, 4), Card(Suit.CASSIA, 6)] self.assertEqual(score_path(path), 4)
def test_complicated(self): def paths_for(suit): return self.complicated().paths_for(suit) self.assertEqual(paths_for(Suit.JACARANDA), []) dogwood_paths = paths_for(Suit.DOGWOOD) self.assertIn([ Card(Suit.DOGWOOD, 1), Card(Suit.CASSIA, 4), Card(Suit.CASSIA, 5), Card(Suit.CASSIA, 6), Card(Suit.CASSIA, 7), Card(Suit.DOGWOOD, 8), ], dogwood_paths) self.assertIn([ Card(Suit.DOGWOOD, 1), Card(Suit.OAK, 2), Card(Suit.CASSIA, 3), Card(Suit.CASSIA, 4), Card(Suit.CASSIA, 5), Card(Suit.CASSIA, 6), Card(Suit.CASSIA, 7), Card(Suit.DOGWOOD, 8), ], dogwood_paths) self.assertTrue(self.all_ascending(dogwood_paths)) self.assertTrue(self.all_two_plus(dogwood_paths)) cassia_paths = paths_for(Suit.CASSIA) self.assertIn([ Card(Suit.CASSIA, 1), Card(Suit.OAK, 2), Card(Suit.CASSIA, 3), Card(Suit.CASSIA, 6), Card(Suit.CASSIA, 7), ], cassia_paths) self.assertTrue(self.all_ascending(cassia_paths)) self.assertTrue(self.all_two_plus(cassia_paths))
def test_line(self): expected = [Card(Suit.CASSIA, 1) ] + [Card(Suit.OAK, i) for i in range(2, 8)] + [Card(Suit.CASSIA, 8)] self.assertEqual(self.line().paths_for(Suit.CASSIA), [expected])
def add(suit, val, x, y): a.add_card(Card(suit, val), Pos(x, y))