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

#   Copyright 2010-2014 <NAME>
#
#   This file is part of pyherc.
#
#   pyherc is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   pyherc is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with pyherc.  If not, see <http://www.gnu.org/licenses/>.

"""
Module for magic related tests
"""
#pylint: disable=W0614
from pyherc.test.builders import CharacterBuilder, HealBuilder, DamageBuilder
from pyherc.test.builders import ActionFactoryBuilder
from pyherc.test.builders import SpellCastingFactoryBuilder
from pyherc.rules import cast

from hamcrest import assert_that, is_, equal_to #pylint: disable-msg=E0611
from mockito import mock, when, any, verify

class TestMagic:
    """
    Tests for magic
    """

    def __init__(self):
        """
        Default constructor
        """
        pass

    def test_damage_effect(self):
        """
        Test that a damage effect can be applied on a character
        """
        character = (CharacterBuilder()
                        .with_hit_points(15)
                        .with_max_hp(15)
                        .build())

        effect = (DamageBuilder()
                    .with_duration(0)
                    .with_frequency(0)
                    .with_tick(0)
                    .with_damage(10)
                    .with_target(character)
                    .build())

        effect.trigger(mock())

        assert_that(character.hit_points, is_(equal_to(5)))

    def test_healing_effect(self):
        """
        Test that a healing effect can be applied on a character
        """
        character = (CharacterBuilder()
                        .with_hit_points(1)
                        .with_max_hp(15)
                        .build())

        effect = (HealBuilder()
                    .with_duration(0)
                    .with_frequency(0)
                    .with_tick(0)
                    .with_healing(10)
                    .with_target(character)
                    .build())

        effect.trigger(mock())

        assert_that(character.hit_points, is_(equal_to(11)))

    def test_healing_does_not_heal_over_max_hp(self):
        """
        Test that character does not get healed over his maximum hp when getting healing effect
        """
        character = (CharacterBuilder()
                        .with_hit_points(1)
                        .with_max_hp(5)
                        .build())

        effect = (HealBuilder()
                    .with_duration(0)
                    .with_frequency(0)
                    .with_tick(0)
                    .with_healing(10)
                    .with_target(character)
                    .build())

        effect.trigger(mock())

        assert_that(character.hit_points, is_(equal_to(5)))

class TestSpellCasting:
    """
    Test spell casting
    """
    def __init__(self):
        """
        Default constructor
        """
        pass

    def test_spell_casting_executes_action(self):
        """
        Casting a spell should activate the action
        """
        magic_factory = SpellCastingFactoryBuilder().build()
        action = mock()
        when(action).is_legal().thenReturn(True)

        when(magic_factory).get_action(any()).thenReturn(action) #pylint: disable-msg=E1103

        action_factory = (ActionFactoryBuilder()
                                    .with_spellcasting_factory(magic_factory)
                                    .build())

        caster = (CharacterBuilder()
                        .build())

        cast(caster,
             direction = 1,
             spell_name = 'healing wind',
             action_factory = action_factory)

        verify(action).execute()

class TestDomains():
    """
    Tests for gaining domains
    """
    def __init__(self):
        """
        Default constructor
        """
        super().__init__()

    def test_add_spell_level(self):
        """
        Test that a spell level can be added
        """
        caster = (CharacterBuilder()
                        .with_domain('fire', 1)
                        .build())

        caster.add_spell_level('fire')

        assert_that(caster.get_spell_level('fire'), is_(equal_to(2)))<commit_msg>working on gaining domain levels relates #49<commit_after># -*- coding: utf-8 -*-

#   Copyright 2010-2014 <NAME>
#
#   This file is part of pyherc.
#
#   pyherc is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   pyherc is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with pyherc.  If not, see <http://www.gnu.org/licenses/>.

"""
Module for magic related tests
"""
#pylint: disable=W0614
from pyherc.test.builders import CharacterBuilder, HealBuilder, DamageBuilder
from pyherc.test.builders import ActionFactoryBuilder
from pyherc.test.builders import SpellCastingFactoryBuilder
from pyherc.rules import cast

from hamcrest import assert_that, is_, equal_to #pylint: disable-msg=E0611
from mockito import mock, when, any, verify

class TestMagic:
    """
    Tests for magic
    """

    def __init__(self):
        """
        Default constructor
        """
        pass

    def test_damage_effect(self):
        """
        Test that a damage effect can be applied on a character
        """
        character = (CharacterBuilder()
                        .with_hit_points(15)
                        .with_max_hp(15)
                        .build())

        effect = (DamageBuilder()
                    .with_duration(0)
                    .with_frequency(0)
                    .with_tick(0)
                    .with_damage(10)
                    .with_target(character)
                    .build())

        effect.trigger(mock())

        assert_that(character.hit_points, is_(equal_to(5)))

    def test_healing_effect(self):
        """
        Test that a healing effect can be applied on a character
        """
        character = (CharacterBuilder()
                        .with_hit_points(1)
                        .with_max_hp(15)
                        .build())

        effect = (HealBuilder()
                    .with_duration(0)
                    .with_frequency(0)
                    .with_tick(0)
                    .with_healing(10)
                    .with_target(character)
                    .build())

        effect.trigger(mock())

        assert_that(character.hit_points, is_(equal_to(11)))

    def test_healing_does_not_heal_over_max_hp(self):
        """
        Test that character does not get healed over his maximum hp when getting healing effect
        """
        character = (CharacterBuilder()
                        .with_hit_points(1)
                        .with_max_hp(5)
                        .build())

        effect = (HealBuilder()
                    .with_duration(0)
                    .with_frequency(0)
                    .with_tick(0)
                    .with_healing(10)
                    .with_target(character)
                    .build())

        effect.trigger(mock())

        assert_that(character.hit_points, is_(equal_to(5)))

class TestSpellCasting:
    """
    Test spell casting
    """
    def __init__(self):
        """
        Default constructor
        """
        pass

    def test_spell_casting_executes_action(self):
        """
        Casting a spell should activate the action
        """
        magic_factory = SpellCastingFactoryBuilder().build()
        action = mock()
        when(action).is_legal().thenReturn(True)

        when(magic_factory).get_action(any()).thenReturn(action) #pylint: disable-msg=E1103

        action_factory = (ActionFactoryBuilder()
                                    .with_spellcasting_factory(magic_factory)
                                    .build())

        caster = (CharacterBuilder()
                        .build())

        cast(caster,
             direction = 1,
             spell_name = 'healing wind',
             action_factory = action_factory)

        verify(action).execute()

class TestDomains():
    """
    Tests for gaining domains
    """
    def __init__(self):
        """
        Default constructor
        """
        super().__init__()

    def test_add_spell_level(self):
        """
        Test that a spell level can be added
        """
        caster = (CharacterBuilder()
                        .with_domain('fire', 1)
                        .build())

        caster.add_spell_level('fire')

        assert_that(caster.get_spell_level('fire'), is_(equal_to(2)))

    def test_add_multiple_levels(self):
        """
        Adding more than one level should be possible with a single call
        """
        caster = (CharacterBuilder()
                        .with_domain('fire', 1)
                        .build())

        caster.add_spell_level('fire', 5)

        assert_that(caster.get_spell_level('fire'), is_(equal_to(6)))
{'fraction_non_alphanumeric': 0.09191402251791198, 'fraction_numerical': 0.011361310133060389, 'mean_word_length': 1.7111542730299667, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5697007', 'n_tokens_mistral': 2695, 'n_tokens_neox': 2522, 'n_words': 670}