<commit_before>from django.test import TestCase

from battle.models import Battle, BattleCharacter, BattleUnit, BattleContubernium, BattleSoldier
from organization.models import Organization
from world.initialization import initialize_unit
from world.models import Tile, WorldUnit


class TestBattleStart(TestCase):
    fixtures = ['simple_world']

    def test_battle_create_from_conflict(self):
        initialize_unit(WorldUnit.objects.get(id=1))
        initialize_unit(WorldUnit.objects.get(id=2))
        tile = Tile.objects.get(id=108)
        battle = Battle.objects.create(tile=tile)
        battle.initialize_from_conflict([Organization.objects.get(id=105), Organization.objects.get(id=112)], tile)

        self.assertTrue(battle.battleorganization_set.filter(organization=Organization.objects.get(id=105)).exists())
        self.assertTrue(battle.battleorganization_set.filter(organization=Organization.objects.get(id=112)).exists())
        self.assertEqual(battle.battleorganization_set.count(), 2)

        self.assertTrue(
            battle.battleorganization_set.get(organization_id=105).z !=
            battle.battleorganization_set.get(organization_id=112).z
        )

        self.assertTrue(BattleCharacter.objects.exists())
        self.assertTrue(BattleCharacter.objects.filter(
            battle_organization__organization=Organization.objects.get(id=105),
        ).exists())
        self.assertTrue(BattleCharacter.objects.filter(
            battle_organization__organization=Organization.objects.get(id=112),
        ).exists())
        self.assertEqual(BattleCharacter.objects.count(), 2)

        self.assertTrue(BattleUnit.objects.exists())
        self.assertTrue(BattleUnit.objects.filter(world_unit=WorldUnit.objects.get(id=1),).exists())
        self.assertTrue(BattleUnit.objects.filter(world_unit=WorldUnit.objects.get(id=2),).exists())
        self.assertEqual(BattleUnit.objects.count(), 2)

        self.assertTrue(BattleContubernium.objects.exists())
        self.assertEqual(BattleContubernium.objects.count(), 8)
        self.assertTrue(BattleSoldier.objects.exists())
        self.assertEqual(BattleSoldier.objects.count(), 60)<commit_msg>Improved test<commit_after>from django.test import TestCase

from battle.models import Battle, BattleCharacter, BattleUnit, BattleContubernium, BattleSoldier
from organization.models import Organization
from world.initialization import initialize_unit
from world.models import Tile, WorldUnit, NPC


class TestBattleStart(TestCase):
    fixtures = ['simple_world']

    def test_battle_create_from_conflict(self):
        initialize_unit(WorldUnit.objects.get(id=1))
        initialize_unit(WorldUnit.objects.get(id=2))
        tile = Tile.objects.get(id=108)
        battle = Battle.objects.create(tile=tile)
        battle.initialize_from_conflict([Organization.objects.get(id=105), Organization.objects.get(id=112)], tile)

        self.assertTrue(battle.battleorganization_set.filter(organization=Organization.objects.get(id=105)).exists())
        self.assertTrue(battle.battleorganization_set.filter(organization=Organization.objects.get(id=112)).exists())
        self.assertEqual(battle.battleorganization_set.count(), 2)

        self.assertTrue(
            battle.battleorganization_set.get(organization_id=105).z !=
            battle.battleorganization_set.get(organization_id=112).z
        )

        self.assertTrue(BattleCharacter.objects.exists())
        self.assertTrue(BattleCharacter.objects.filter(
            battle_organization__organization=Organization.objects.get(id=105),
        ).exists())
        self.assertTrue(BattleCharacter.objects.filter(
            battle_organization__organization=Organization.objects.get(id=112),
        ).exists())
        self.assertEqual(BattleCharacter.objects.count(), 2)

        self.assertTrue(BattleUnit.objects.exists())
        self.assertTrue(BattleUnit.objects.filter(world_unit=WorldUnit.objects.get(id=1),).exists())
        self.assertTrue(BattleUnit.objects.filter(world_unit=WorldUnit.objects.get(id=2),).exists())
        self.assertEqual(BattleUnit.objects.count(), 2)

        self.assertTrue(BattleContubernium.objects.exists())
        self.assertEqual(BattleContubernium.objects.count(), 8)
        self.assertTrue(BattleSoldier.objects.exists())
        self.assertEqual(BattleSoldier.objects.count(), 60)

        for npc in NPC.objects.all():
            self.assertTrue(BattleSoldier.objects.filter(world_npc=npc).exists())
{'fraction_non_alphanumeric': 0.11577777777777777, 'fraction_numerical': 0.016444444444444446, 'mean_word_length': 4.191464821222607, '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': '1724357', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1276, 'n_words': 140}