<commit_before>import itertools
import unittest

from chainlet.chainlink import FlatChain, Bundle

from chainlet_unittests.utility import NamedChainlet


class LinkerGrammar(unittest.TestCase):
    def test_pair(self):
        """Single link as `parent >> child`"""
        chainlet1 = NamedChainlet('1')
        chainlet2 = NamedChainlet('2')
        for parent, child in itertools.product((chainlet1, chainlet2), repeat=2):
            with self.subTest(parent=parent, child=child):
                chain_a = parent >> child
                self.assertSequenceEqual(chain_a.elements, (parent, child))
                chain_a_inv = child << parent
                self.assertSequenceEqual(chain_a.elements, chain_a_inv.elements)

    def test_tripple(self):
        """Chained link as `source >> link >> consumer`"""
        chainlet1 = NamedChainlet('1')
        chainlet2 = NamedChainlet('2')
        chainlet3 = NamedChainlet('3')
        for a, b, c in itertools.product((chainlet1, chainlet2, chainlet3), repeat=3):
            with self.subTest(a=a, b=b, c=c):
                chain_a = a >> b >> c
                self.assertSequenceEqual(chain_a.elements, (a, b, c))
                chain_a_inv = c << b << a
                self.assertSequenceEqual(chain_a.elements, chain_a_inv.elements)
                chain_a_child_sub = a >> b
                chain_a_child_full = chain_a_child_sub >> c
                chain_a_parent_sub = b >> c
                chain_a_parent_full = a >> chain_a_parent_sub
                self.assertSequenceEqual(chain_a.elements, chain_a_child_full.elements)
                self.assertSequenceEqual(chain_a.elements, chain_a_parent_full.elements)
                # do not allow mutating existing chain
                self.assertNotEqual(chain_a_child_sub, chain_a_child_full)
                self.assertNotEqual(chain_a_parent_sub, chain_a_parent_full)

    def test_single(self):
        """Empty link as () >> child_a"""
        chainlets = [NamedChainlet(idx) for idx in range(3)]
        for singlet in chainlets:
            for empty in (FlatChain(()), Bundle(()), (), set(), [], set()):
                with self.subTest(singlet=singlet, empty=empty):
                    single_out = singlet >> empty
                    self.assertIs(single_out, singlet)
                    single_in = empty >> singlet
                    self.assertIs(single_in, singlet)

    def test_parallel(self):
        """Parallel link as `parent >> (child_a, child_b, ...)` and `(parent_a, parent_b, ...) >> child`"""
        chainlet1 = NamedChainlet('1')
        chainlet2 = NamedChainlet('2')
        chainlet3 = NamedChainlet('3')
        for a, b, c in itertools.product((chainlet1, chainlet2, chainlet3), repeat=3):
            with self.subTest(a=a, b=b, c=c):
                chain_a = a >> (b, c)
                self.assertIs(chain_a.elements[0], a)
                self.assertSequenceEqual(chain_a.elements[1].elements, (b, c))
                chain_a_inv = (b, c) << a
                self.assertSequenceEqual(chain_a.elements, chain_a_inv.elements)
                chain_b = (a, b) >> c
                self.assertIs(chain_b.elements[1], c)
                self.assertSequenceEqual(chain_b.elements[0].elements, (a, b))
                chain_b_inv = c << (a, b)<commit_msg>unittest formatting<commit_after>import itertools
import unittest

from chainlet.chainlink import FlatChain, Bundle

from chainlet_unittests.utility import NamedChainlet


class LinkerGrammar(unittest.TestCase):
    def test_pair(self):
        """Single link as `parent >> child`"""
        chainlet1 = NamedChainlet('1')
        chainlet2 = NamedChainlet('2')
        for parent, child in itertools.product((chainlet1, chainlet2), repeat=2):
            with self.subTest(parent=parent, child=child):
                chain_a = parent >> child
                self.assertSequenceEqual(chain_a.elements, (parent, child))
                chain_a_inv = child << parent
                self.assertSequenceEqual(chain_a.elements, chain_a_inv.elements)

    def test_tripple(self):
        """Chained link as `source >> link >> consumer`"""
        chainlet1 = NamedChainlet('1')
        chainlet2 = NamedChainlet('2')
        chainlet3 = NamedChainlet('3')
        for a, b, c in itertools.product((chainlet1, chainlet2, chainlet3), repeat=3):
            with self.subTest(a=a, b=b, c=c):
                chain_a = a >> b >> c
                self.assertSequenceEqual(chain_a.elements, (a, b, c))
                chain_a_inv = c << b << a
                self.assertSequenceEqual(chain_a.elements, chain_a_inv.elements)
                chain_a_child_sub = a >> b
                chain_a_child_full = chain_a_child_sub >> c
                chain_a_parent_sub = b >> c
                chain_a_parent_full = a >> chain_a_parent_sub
                self.assertSequenceEqual(chain_a.elements, chain_a_child_full.elements)
                self.assertSequenceEqual(chain_a.elements, chain_a_parent_full.elements)
                # do not allow mutating existing chain
                self.assertNotEqual(chain_a_child_sub, chain_a_child_full)
                self.assertNotEqual(chain_a_parent_sub, chain_a_parent_full)

    def test_single(self):
        """Empty link as `() >> child_a`"""
        chainlets = [NamedChainlet(idx) for idx in range(3)]
        for singlet in chainlets:
            for empty in (FlatChain(()), Bundle(()), (), set(), [], set()):
                with self.subTest(singlet=singlet, empty=empty):
                    single_out = singlet >> empty
                    self.assertIs(single_out, singlet)
                    single_in = empty >> singlet
                    self.assertIs(single_in, singlet)

    def test_parallel(self):
        """Parallel link as `parent >> (child_a, child_b, ...)` and `(parent_a, parent_b, ...) >> child`"""
        chainlet1 = NamedChainlet('1')
        chainlet2 = NamedChainlet('2')
        chainlet3 = NamedChainlet('3')
        for a, b, c in itertools.product((chainlet1, chainlet2, chainlet3), repeat=3):
            with self.subTest(a=a, b=b, c=c):
                chain_a = a >> (b, c)
                self.assertIs(chain_a.elements[0], a)
                self.assertSequenceEqual(chain_a.elements[1].elements, (b, c))
                chain_a_inv = (b, c) << a
                self.assertSequenceEqual(chain_a.elements, chain_a_inv.elements)
                chain_b = (a, b) >> c
                self.assertIs(chain_b.elements[1], c)
                self.assertSequenceEqual(chain_b.elements[0].elements, (a, b))
                chain_b_inv = c << (a, b)
{'fraction_non_alphanumeric': 0.11429433051869722, 'fraction_numerical': 0.009650180940892641, 'mean_word_length': 2.2261673151750974, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 71, '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': '125583', 'n_tokens_mistral': 2062, 'n_tokens_neox': 1977, 'n_words': 418}