<commit_before>import unittest
from expressions.core import (BaseType, argument_sender, CallableObject,
    ExpressionString)


class TestBaseTypeType(unittest.TestCase):
    def test_BaseType_vector(self):
        v = BaseType([0, 0, 0])
        self.assertEqual(v._array, [0, 0, 0])

    def test_BaseType_vector_interface(self):
        """Should define a 3-vector of numbers"""
        u = BaseType**3;
        self.assertEqual(u._array, BaseType([0, 0, 0])._array)

    def test_BaseType_matrix(self):
        A = BaseType([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
        array = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        self.assertEqual(A._array, array)

    def test_BaseType_matrix_interface(self):
        A = BaseType**3*3
        array = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        self.assertEqual(A._array, array)

    def test_BaseType_matrix_getitem(self):
        A = BaseType([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        item = A[1][2]
        self.assertEqual(item, 6)

    def test_three_dimensions_BaseType_matrix_interface(self):
        A = BaseType**3*3*2
        array = [
            [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
            [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        ]
        self.assertEqual(A._array, array)


class FunctionTest(unittest.TestCase):
    def test_argument_sender(self):
        """The coroutine object created with argument_sender should
        yield the value sended and return the value again in the next
        iteration."""
        sender = argument_sender()
        next(sender)
        a = sender.send(2)
        b = next(sender)
        self.assertEqual(a, 2)
        self.assertEqual(b, 2)

    def test_CallableObject(self):
        double = CallableObject(x*2 for x in BaseType)
        self.assertEqual(8, next(double(4)))


class ExpressionTest(unittest.TestCase):
    def test_bynary_left_operators(self):
        add = BaseType(x+2 for x in BaseType)
        and_ = BaseType(x&2 for x in BaseType)
        div = BaseType(x/2 for x in BaseType)
        eq = BaseType(x==2 for x in BaseType)
        floordiv = BaseType(x//2 for x in BaseType)
        ge = BaseType(x>=2 for x in BaseType)
        gt = BaseType(x>2 for x in BaseType)
        le = BaseType(x<=2 for x in BaseType)
        lshift = BaseType(x<<2 for x in BaseType)
        lt = BaseType(x<2 for x in BaseType)
        # matmul = BaseType(x@2 for x in BaseType)
        mod = BaseType(x%2 for x in BaseType)
        mul = BaseType(x*2 for x in BaseType)
        ne = BaseType(x!=2 for x in BaseType)
        # or_ = BaseType(x|2 for x in BaseType)
        pow = BaseType(x**2 for x in BaseType)
        rshift = BaseType(x>>2 for x in BaseType)
        sub = BaseType(x-2 for x in BaseType)
        truediv = BaseType(x/2 for x in BaseType)
        xor = BaseType(x^2 for x in BaseType)

        self.assertEqual(add._expression, 'x+(2)')
        self.assertEqual(and_._expression, 'x&(2)')
        self.assertEqual(div._expression, 'x/(2)')
        self.assertEqual(eq._expression, 'x==(2)')
        self.assertEqual(floordiv._expression, 'x//(2)')<commit_msg>add test for many arguments<commit_after>import unittest
from expressions.core import (BaseType, argument_sender, CallableObject,
    ExpressionString)


class TestBaseTypeType(unittest.TestCase):
    def test_BaseType_vector(self):
        v = BaseType([0, 0, 0])
        self.assertEqual(v._array, [0, 0, 0])

    def test_BaseType_vector_interface(self):
        """Should define a 3-vector of numbers"""
        u = BaseType**3;
        self.assertEqual(u._array, BaseType([0, 0, 0])._array)

    def test_BaseType_matrix(self):
        A = BaseType([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
        array = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        self.assertEqual(A._array, array)

    def test_BaseType_matrix_interface(self):
        A = BaseType**3*3
        array = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        self.assertEqual(A._array, array)

    def test_BaseType_matrix_getitem(self):
        A = BaseType([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        item = A[1][2]
        self.assertEqual(item, 6)

    def test_three_dimensions_BaseType_matrix_interface(self):
        A = BaseType**3*3*2
        array = [
            [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
            [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        ]
        self.assertEqual(A._array, array)


class FunctionTest(unittest.TestCase):
    def test_argument_sender(self):
        """The coroutine object created with argument_sender should
        yield the value sended and return the value again in the next
        iteration."""
        sender = argument_sender()
        next(sender)
        a = sender.send(2)
        b = next(sender)
        self.assertEqual(a, 2)
        self.assertEqual(b, 2)

    def test_CallableObject(self):
        double = CallableObject(x*2 for x in BaseType)
        self.assertEqual(8, next(double(4)))

    def test_many_variables(self):
        add = BaseType(x + y for x, y in BaseType)
        added = add(3, 4)
        self.assertEqual(7, next(added))


class ExpressionTest(unittest.TestCase):
    def test_bynary_left_operators(self):
        add = BaseType(x+2 for x in BaseType)
        and_ = BaseType(x&2 for x in BaseType)
        div = BaseType(x/2 for x in BaseType)
        eq = BaseType(x==2 for x in BaseType)
        floordiv = BaseType(x//2 for x in BaseType)
        ge = BaseType(x>=2 for x in BaseType)
        gt = BaseType(x>2 for x in BaseType)
        le = BaseType(x<=2 for x in BaseType)
        lshift = BaseType(x<<2 for x in BaseType)
        lt = BaseType(x<2 for x in BaseType)
        # matmul = BaseType(x@2 for x in BaseType)
        mod = BaseType(x%2 for x in BaseType)
        mul = BaseType(x*2 for x in BaseType)
        ne = BaseType(x!=2 for x in BaseType)
        # or_ = BaseType(x|2 for x in BaseType)
        pow = BaseType(x**2 for x in BaseType)
        rshift = BaseType(x>>2 for x in BaseType)
        sub = BaseType(x-2 for x in BaseType)
        truediv = BaseType(x/2 for x in BaseType)
        xor = BaseType(x^2 for x in BaseType)

        self.assertEqual(add._expression, 'x+(2)')
        self.assertEqual(and_._expression, 'x&(2)')
        self.assertEqual(div._expression, 'x/(2)')
        self.assertEqual(eq._expression, 'x==(2)')
        self.assertEqual(floordiv._expression, 'x//(2)')
{'fraction_non_alphanumeric': 0.13211125158027812, 'fraction_numerical': 0.033343868520859674, 'mean_word_length': 2.487052341597796, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4182875', 'n_tokens_mistral': 2250, 'n_tokens_neox': 2137, 'n_words': 608}