<commit_before>""" Tests for the AI module """

import unittest
from unittest.mock import patch

# pylint: disable=import-error
from res import types
from src import ai
from src import coordinate
from src import historynode
from src import rules
from test import helper

# pylint: disable=too-many-public-methods
class TestAI(unittest.TestCase):
    """ Tests for the AI module """

    @patch.object(ai.AI, "findBestMove")
    def test_iterativeDeepeningSearch_no_endstate(self, theMock):
        """ Test searching when there is no discoverable winning/losing move"""
        mockBestMove = historynode.HistoryNode()
        mockBestMove.score = 0
        theMock.return_value = mockBestMove
        testBoard = historynode.HistoryNode()
        aiObject = ai.AI()
        aiObject.iterativeDeepeningSearch(testBoard, True, 5)
        self.assertEqual(theMock.call_count, 3)

    @patch.object(ai.AI, "findBestMove")
    def test_iterativeDeepeningSearch_winning(self, theMock):
        """ Test searching when there is a winning move on the 1st ply"""
        mockBestMove = historynode.HistoryNode()
        mockBestMove.score = 1000
        theMock.return_value = mockBestMove
        testBoard = historynode.HistoryNode()
        aiObject = ai.AI()
        aiObject.iterativeDeepeningSearch(testBoard, True, 5)
        self.assertEqual(theMock.call_count, 1)

    def test_getHighestOrLowestScoreMove_goose(self):
        """ Sort the best move of a Goose player """
        hnObjectBigScore = historynode.HistoryNode()
        hnObjectMediumScore = historynode.HistoryNode()
        hnObjectSmallScore = historynode.HistoryNode()
        hnObjectBigScore.score = 10.0
        hnObjectMediumScore.score = 1.0
        hnObjectSmallScore.score = -5.0
        allMoves = [hnObjectMediumScore, hnObjectBigScore, hnObjectSmallScore]
        gooseTurn = True
        actualMove = ai.getHighestOrLowestScoreMove(allMoves, gooseTurn)
        self.assertEqual(actualMove.score, hnObjectBigScore.score)

    def test_getHighestOrLowestScoreMove_fox(self):
        """ Get the best move of a Fox player """
        hnObjectBigScore = historynode.HistoryNode()
        hnObjectMediumScore = historynode.HistoryNode()
        hnObjectSmallScore = historynode.HistoryNode()
        hnObjectBigScore.score = 10.0
        hnObjectMediumScore.score = 1.0
        hnObjectSmallScore.score = -5.0<commit_msg>Add findBestMove test for a drawn state<commit_after>""" Tests for the AI module """

import unittest
from unittest.mock import patch

# pylint: disable=import-error
from res import types
from src import ai
from src import coordinate
from src import historynode
from src import rules
from test import helper

# pylint: disable=too-many-public-methods
class TestAI(unittest.TestCase):
    """ Tests for the AI module """

    @patch.object(ai.AI, "findBestMove")
    def test_iterativeDeepeningSearch_no_endstate(self, theMock):
        """ Test searching when there is no discoverable winning/losing move"""
        mockBestMove = historynode.HistoryNode()
        mockBestMove.score = 0
        theMock.return_value = mockBestMove
        testBoard = historynode.HistoryNode()
        aiObject = ai.AI()
        aiObject.iterativeDeepeningSearch(testBoard, True, 5)
        self.assertEqual(theMock.call_count, 3)

    @patch.object(ai.AI, "findBestMove")
    def test_iterativeDeepeningSearch_winning(self, theMock):
        """ Test searching when there is a winning move on the 1st ply"""
        mockBestMove = historynode.HistoryNode()
        mockBestMove.score = 1000
        theMock.return_value = mockBestMove
        testBoard = historynode.HistoryNode()
        aiObject = ai.AI()
        aiObject.iterativeDeepeningSearch(testBoard, True, 5)
        self.assertEqual(theMock.call_count, 1)

    @patch.object(ai.AI, "getAllMovesForPlayer")
    def test_findBestMove_drawn_state(self, theMock):
        """ Test correct evaluation is returned in drawn state """
        theMock.return_value = []
        aiObject = ai.AI()
        hnObject = historynode.HistoryNode()
        actualValue = aiObject.findBestMove(hnObject,
                                            True,
                                            5,
                                            -10000.0,
                                            10000.0,
                                            False)
        self.assertEqual(actualValue, 0.0)

    def test_getHighestOrLowestScoreMove_goose(self):
        """ Sort the best move of a Goose player """
        hnObjectBigScore = historynode.HistoryNode()
        hnObjectMediumScore = historynode.HistoryNode()
        hnObjectSmallScore = historynode.HistoryNode()
        hnObjectBigScore.score = 10.0
        hnObjectMediumScore.score = 1.0
        hnObjectSmallScore.score = -5.0
        allMoves = [hnObjectMediumScore, hnObjectBigScore, hnObjectSmallScore]
        gooseTurn = True
        actualMove = ai.getHighestOrLowestScoreMove(allMoves, gooseTurn)
        self.assertEqual(actualMove.score, hnObjectBigScore.score)

    def test_getHighestOrLowestScoreMove_fox(self):
        """ Get the best move of a Fox player """
        hnObjectBigScore = historynode.HistoryNode()
        hnObjectMediumScore = historynode.HistoryNode()
        hnObjectSmallScore = historynode.HistoryNode()
        hnObjectBigScore.score = 10.0
        hnObjectMediumScore.score = 1.0
        hnObjectSmallScore.score = -5.0
{'fraction_non_alphanumeric': 0.08135904499540864, 'fraction_numerical': 0.011570247933884297, 'mean_word_length': 2.779319916724497, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1496462', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1471, 'n_words': 358}