<commit_before>import unittest

from streamsx.topology.topology import *
from streamsx.topology.schema import CommonSchema
from streamsx.topology.tester import Tester

class Person(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def rough_birth_year(self):
        return time.localtime().tm_year - self.age;

class TestPythonWindowing(unittest.TestCase):
    def setUp(self):
        Tester.setup_standalone(self)

    def test_BasicCountCountWindow(self):
        topo = Topology()
        s = topo.source([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
        s = s.last(10).trigger(1).aggregate(lambda x: sum(x)/len(x))
        
        tester = Tester(topo)
        tester.contents(s, [1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5])
        tester.test(self.test_ctxtype, self.test_config)

    def test_JsonInputCountCountWindow(self):
        topo = Topology()
        s = topo.source([{'a':1},{'b':2,'c':3}, {'d': 4, 'e': 5}])
        
        # Check the averages of the values of the Json objects
        s = s.map(lambda x: x, schema = CommonSchema.Json)
        s = s.last(3).trigger(1).aggregate(lambda x: int(sum([sum([s[k] for k in s]) for s in x])/len(x)))
        
        tester = Tester(topo)
        tester.contents(s, [1,3,5])
        tester.test(self.test_ctxtype, self.test_config)

    def test_StringInputCountCountWindow(self):
        topo = Topology()
        s = topo.source(['1','3','5','7'])
        s = s.map(lambda x: x, schema = CommonSchema.String)
        s = s.last(3).trigger(1).aggregate(lambda x: int(sum([int(s) for s in x])/len(x)),
                                           schema = CommonSchema.Python)

        tester = Tester(topo)
        tester.contents(s, [1,2,3,5])<commit_msg>Change trigger of BasicCountCountWindow test to 2<commit_after>import unittest

from streamsx.topology.topology import *
from streamsx.topology.schema import CommonSchema
from streamsx.topology.tester import Tester

class Person(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def rough_birth_year(self):
        return time.localtime().tm_year - self.age;

class TestPythonWindowing(unittest.TestCase):
    def setUp(self):
        Tester.setup_standalone(self)

    def test_BasicCountCountWindow(self):
        topo = Topology()
        s = topo.source([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
        s = s.last(10).trigger(2).aggregate(lambda x: sum(x)/len(x))

        tester = Tester(topo)
        tester.contents(s, [1.5,2.5,3.5,4.5,5.5,7.5,9.5])
        tester.test(self.test_ctxtype, self.test_config)

    def test_JsonInputCountCountWindow(self):
        topo = Topology()
        s = topo.source([{'a':1},{'b':2,'c':3}, {'d': 4, 'e': 5}])
        
        # Check the averages of the values of the Json objects
        s = s.map(lambda x: x, schema = CommonSchema.Json)
        s = s.last(3).trigger(1).aggregate(lambda x: int(sum([sum([s[k] for k in s]) for s in x])/len(x)))
        
        tester = Tester(topo)
        tester.contents(s, [1,3,5])
        tester.test(self.test_ctxtype, self.test_config)

    def test_StringInputCountCountWindow(self):
        topo = Topology()
        s = topo.source(['1','3','5','7'])
        s = s.map(lambda x: x, schema = CommonSchema.String)
        s = s.last(3).trigger(1).aggregate(lambda x: int(sum([int(s) for s in x])/len(x)),
                                           schema = CommonSchema.Python)

        tester = Tester(topo)
        tester.contents(s, [1,2,3,5])
{'fraction_non_alphanumeric': 0.15479184129645152, 'fraction_numerical': 0.037440625873148926, 'mean_word_length': 2.6198179979777554, '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': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3943933', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1273, 'n_words': 257}