<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from GestureAgents.AppRecognizer import AppRecognizer
from RecognizerDT_Test import build_and_register_DT
from RecognizerTT_Test import build_and_register_TT
from RecognizerT_Test import RecognizerT_Test
from recognizer_testing import run_apps
from recognizer_testing import test_events


events_3tap = [
    ('f', 1, (0.5, 0.5), (
     (0, 'in'),
     (0.1, 'out'))),
    ('f', 2, (0.5, 0.5), (
     (0.2, 'in'),
     (0.3, 'out'))),
    ('f', 3, (0.5, 0.5), (
     (0.4, 'in'),
     (0.5, 'out'))),
]


class AppTestGeneric(object):
    def __init__(self, recognizer, events):
        self.ar = AppRecognizer(recognizer)
        self.ar.newAgent.register(AppTestGeneric.newAgentTap, self)
        self.received = 0
        self.events = events

    def newAgentTap(self, agent):
        for event in self.events:
            getattr(agent, event).register(AppTestGeneric.cb, self)

    def cb(self, agent):
        self.received += 1

    def unregister(self):
        self.ar.newAgent.unregister(self)

# Test Composition sharing sub-gestures
#Test 1: 2 recognizers share a sub recognzer (Tap)


RecognizerDT1 = build_and_register_DT()
RecognizerTT1 = build_and_register_TT()
RecognizerDT2 = build_and_register_DT(RecognizerT_Test)
RecognizerTT2 = build_and_register_TT(RecognizerT_Test)


def AppTestTap():
    from GestureAgentsTUIO.Gestures2D.RecognizerTap import RecognizerTap
    return AppTestGeneric(RecognizerTap, ("newTap",))


def AppTestDT():
    return AppTestGeneric(RecognizerDT1, ("newDoubleTap",))


def AppTestTT():
    return AppTestGeneric(RecognizerTT1, ("newTripleTap",))


def AppTestTap2():
    return AppTestGeneric(RecognizerT_Test, ("newTap",))


def AppTestDT2():
    return AppTestGeneric(RecognizerDT2, ("newDoubleTap",))


def AppTestTT2():
    return AppTestGeneric(RecognizerTT2, ("newTripleTap",))


class TapTestCase(unittest.TestCase):
    def setUp(self):
        self.appt1 = AppTestTap()

    def runTest(self):
        run_apps(test_events(events_3tap))
        self.assertEqual(self.appt1.received, 3)

    def tearDown(self):
        self.appt1.unregister()


class DoubleTapTestCase(unittest.TestCase):
    def setUp(self):
        self.appt1 = AppTestDT()

    def runTest(self):
        run_apps(test_events(events_3tap))
        self.assertEqual(self.appt1.received, 1)

    def tearDown(self):
        self.appt1.unregister()


class TripleTapTestCase(unittest.TestCase):
    def setUp(self):
        self.appt1 = AppTestTT()
<commit_msg>refactoring testing code<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from GestureAgents.AppRecognizer import AppRecognizer
from RecognizerDT_Test import build_and_register_DT
from RecognizerTT_Test import build_and_register_TT
from RecognizerT_Test import RecognizerT_Test
from recognizer_testing import run_apps
from recognizer_testing import test_events
from GestureAgentsTUIO.Gestures2D.RecognizerTap import RecognizerTap


events_3tap = [
    ('f', 1, (0.5, 0.5), (
     (0, 'in'),
     (0.1, 'out'))),
    ('f', 2, (0.5, 0.5), (
     (0.2, 'in'),
     (0.3, 'out'))),
    ('f', 3, (0.5, 0.5), (
     (0.4, 'in'),
     (0.5, 'out'))),
]


class AppTestGeneric(object):
    def __init__(self, recognizer, events):
        self.ar = AppRecognizer(recognizer)
        self.ar.newAgent.register(AppTestGeneric.newAgentTap, self)
        self.received = 0
        self.events = events

    def newAgentTap(self, agent):
        for event in self.events:
            getattr(agent, event).register(AppTestGeneric.cb, self)

    def cb(self, agent):
        self.received += 1

    def unregister(self):
        self.ar.newAgent.unregister(self)

# Test Composition sharing sub-gestures
#Test 1: 2 recognizers share a sub recognzer (Tap)


RecognizerDT1 = build_and_register_DT()
RecognizerTT1 = build_and_register_TT()
RecognizerDT2 = build_and_register_DT(RecognizerT_Test)
RecognizerTT2 = build_and_register_TT(RecognizerT_Test)


def AppTestDT():
    return AppTestGeneric(RecognizerDT1, ("newDoubleTap",))


def AppTestTT():
    return AppTestGeneric(RecognizerTT1, ("newTripleTap",))


def AppTestTap2():
    return AppTestGeneric(RecognizerT_Test, ("newTap",))


def AppTestDT2():
    return AppTestGeneric(RecognizerDT2, ("newDoubleTap",))


def AppTestTT2():
    return AppTestGeneric(RecognizerTT2, ("newTripleTap",))


def test_regognizer(recognizer_class, events2listen, fake_events, events_expected):
    class GenericRecognizerTestCase(unittest.TestCase):
        def setUp(self):
            self.appt1 = AppTestGeneric(recognizer_class, events2listen)

        def runTest(self):
            run_apps(test_events(fake_events))
            self.assertEqual(self.appt1.received, events_expected)

        def tearDown(self):
            self.appt1.unregister()
    return GenericRecognizerTestCase

TapTestCase = test_regognizer(RecognizerTap, ("newTap",), events_3tap, 3)


class DoubleTapTestCase(unittest.TestCase):
    def setUp(self):
        self.appt1 = AppTestDT()

    def runTest(self):
        run_apps(test_events(events_3tap))
        self.assertEqual(self.appt1.received, 1)

    def tearDown(self):
        self.appt1.unregister()


class TripleTapTestCase(unittest.TestCase):
    def setUp(self):
        self.appt1 = AppTestTT()

{'fraction_non_alphanumeric': 0.11902092675635277, 'fraction_numerical': 0.02092675635276532, 'mean_word_length': 3.8181818181818183, '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': '2479508', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1811, 'n_words': 362}