<commit_before>from django.test import TestCase

# Create your tests here.<commit_msg>Basic analyzer unit test<commit_after>from django.test import TestCase
from breach.models import SampleSet, Victim, Target
from breach.analyzer import decide_next_world_state


class AnalyzerTestCase(TestCase):
    def setUp(self):
        target = Target.objects.create(
            endpoint="http://di.uoa.gr/",
            prefix="test",
            alphabet="0123456789"
        )
        victim = Victim.objects.create(
            target=target
        )
        self.samplesets = [
            SampleSet.objects.create(
                victim=victim,
                amount=1,
                knownsecret="testsecret",
                knownalphabet="01",
                candidatealphabet="0",
                data="bigbigbigbigbigbig"
            ),
            SampleSet.objects.create(
                victim=victim,
                amount=1,
                knownsecret="testsecret",
                knownalphabet="01",
                candidatealphabet="1",
                data="small"
            )
        ]

    def test_decide(self):
        state, confidence = decide_next_world_state(self.samplesets)

        self.assertEqual(state["knownsecret"], "testsecret1")
{'fraction_non_alphanumeric': 0.09227129337539432, 'fraction_numerical': 0.01498422712933754, 'mean_word_length': 1.789010989010989, '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': '776011', 'n_tokens_mistral': 347, 'n_tokens_neox': 321, 'n_words': 58}