<commit_before># -*- coding: utf-8 -*-
import unittest

from mahjong.hand_calculating.hand import HandCalculator
from mahjong.hand_calculating.hand_config import HandConfig
from mahjong.tile import TilesConverter


class YakuTestCase(unittest.TestCase):
    
    def test_kokushi_musou_multiple_yakuman(self):
        hand_calculator = HandCalculator()
        
        # kokushi test
        
        tiles = TilesConverter.string_to_136_array(sou='19', pin='19', man='19', honors='12345677')
        win_tile = TilesConverter.string_to_136_array(honors='1')[0]
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=False,
                    is_chiihou=False)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 1)
        self.assertTrue(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 13)
                
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=True,
                    is_chiihou=False)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 2)
        self.assertTrue(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 26)
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=False,
                    is_chiihou=True)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 2)
        self.assertTrue(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 26)
        
        # double kokushi test
        
        tiles = TilesConverter.string_to_136_array(sou='19', pin='19', man='19', honors='12345677')
        win_tile = TilesConverter.string_to_136_array(honors='7')[0]
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=False,
                    is_chiihou=False)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 1)
        self.assertFalse(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 26)
                
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=True,
                    is_chiihou=False)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 2)
        self.assertFalse(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 39)
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=False,
                    is_chiihou=True)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 2)
        self.assertFalse(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 39)
        
    def test_aka_dora(self):
        hand_calculator = HandCalculator()
        tiles = TilesConverter.string_to_136_array(sou='345', pin='456', man='12355599', has_aka_dora=True)
        win_tile = TilesConverter.string_to_136_array(man='9')[0]
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    has_aka_dora=True
                    )
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(hand_calculation.han, 1)
        
        # one red
        tiles = TilesConverter.string_to_136_array(sou='34r', pin='456', man='12355599', has_aka_dora=True)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(hand_calculation.han, 2)
        
        # two red<commit_msg>Added one more old style test<commit_after># -*- coding: utf-8 -*-
import unittest

from mahjong.hand_calculating.hand import HandCalculator
from mahjong.hand_calculating.hand_config import HandConfig
from mahjong.tile import TilesConverter


class YakuTestCase(unittest.TestCase):
    
    def test_kokushi_musou_multiple_yakuman(self):
        hand_calculator = HandCalculator()
        
        # kokushi test
        
        tiles = TilesConverter.string_to_136_array(sou='19', pin='19', man='19', honors='12345677')
        win_tile = TilesConverter.string_to_136_array(honors='1')[0]
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=False,
                    is_chiihou=False)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 1)
        self.assertTrue(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 13)
                
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=True,
                    is_chiihou=False)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 2)
        self.assertTrue(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 26)
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=False,
                    is_chiihou=True)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 2)
        self.assertTrue(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 26)
        
        # double kokushi test
        
        tiles = TilesConverter.string_to_136_array(sou='19', pin='19', man='19', honors='12345677')
        win_tile = TilesConverter.string_to_136_array(honors='7')[0]
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=False,
                    is_chiihou=False)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 1)
        self.assertFalse(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 26)
                
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=True,
                    is_chiihou=False)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 2)
        self.assertFalse(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 39)
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    is_tenhou=False,
                    is_chiihou=True)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(len(hand_calculation.yaku), 2)
        self.assertFalse(hand_config.yaku.kokushi in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.daburu_kokushi in hand_calculation.yaku)
        self.assertFalse(hand_config.yaku.tenhou in hand_calculation.yaku)
        self.assertTrue(hand_config.yaku.chiihou in hand_calculation.yaku)
        self.assertEqual(hand_calculation.han, 39)
        
    def test_aka_dora(self):
        hand_calculator = HandCalculator()
        win_tile = TilesConverter.string_to_136_array(man='9')[0]
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    has_aka_dora=True
                    )
        
        # three red old style, but not that useful
        tiles = TilesConverter.string_to_136_array(sou='345', pin='456', man='12355599', has_aka_dora=False)
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(hand_calculation.han, 4)
        
        # zero red
        tiles = TilesConverter.string_to_136_array(sou='345', pin='456', man='12355599', has_aka_dora=True)
        win_tile = TilesConverter.string_to_136_array(man='9')[0]
        
        hand_config = HandConfig(
                    is_tsumo=True,
                    has_aka_dora=True
                    )
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(hand_calculation.han, 1)
        
        # one red
        tiles = TilesConverter.string_to_136_array(sou='34r', pin='456', man='12355599', has_aka_dora=True)
        
        hand_calculation = hand_calculator.estimate_hand_value(tiles, win_tile, config=hand_config)
        self.assertIsNone(hand_calculation.error)
        self.assertEqual(hand_calculation.han, 2)
        
        # two red
{'fraction_non_alphanumeric': 0.08143021914648212, 'fraction_numerical': 0.017608612072279893, 'mean_word_length': 2.5584131326949384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2238326', 'n_tokens_mistral': 4441, 'n_tokens_neox': 4067, 'n_words': 504}