<commit_before>import unittest

import numpy as np
from numpy.testing import assert_array_equal
import sympy

from means.approximation.ode_problem import ODEProblem, Moment, VarianceTerm


class TestODEProblem(unittest.TestCase):

    def test_ode_rhs_as_function(self):
        """
        Given an ODEProblem with well specified LHS, RHS expressions as well as list of constants,
        the value of rhs_as_function given the appropriate params should be the same as the value of
        rhs evaluated for these params.
        :return:
        """
        lhs = [Moment(np.ones(3),i) for i in sympy.Matrix(['y_1', 'y_2', 'y_3'])]
        rhs = sympy.Matrix(['y_1+y_2+c_2', 'y_2+y_3+c_3', 'y_3+c_1'])

        p = ODEProblem('MEA', lhs, rhs, constants=sympy.symbols(['c_1', 'c_2', 'c_3']))

        rhs_as_function = p.right_hand_side_as_function([1, 2, 3])

        params = [4, 5, 6]  # y_1, y_2, y_3 in that order
        expected_ans = np.array([[11], [14], [7]])
        actual_ans = np.array(rhs_as_function(params))
        assert_array_equal(actual_ans, expected_ans)

    def test_ode_moment_no_description_from_variance_terms(self):<commit_msg>added test showing the problem<commit_after>import unittest

import numpy as np
from numpy.testing import assert_array_equal
import sympy

from means.approximation.ode_problem import ODEProblem, Moment, VarianceTerm


class TestODEProblem(unittest.TestCase):

    def test_ode_rhs_as_function(self):
        """
        Given an ODEProblem with well specified LHS, RHS expressions as well as list of constants,
        the value of rhs_as_function given the appropriate params should be the same as the value of
        rhs evaluated for these params.
        :return:
        """
        lhs = [Moment(np.ones(3),i) for i in sympy.Matrix(['y_1', 'y_2', 'y_3'])]
        rhs = sympy.Matrix(['y_1+y_2+c_2', 'y_2+y_3+c_3', 'y_3+c_1'])

        p = ODEProblem('MEA', lhs, rhs, constants=sympy.symbols(['c_1', 'c_2', 'c_3']))

        rhs_as_function = p.right_hand_side_as_function([1, 2, 3])

        params = [4, 5, 6]  # y_1, y_2, y_3 in that order
        expected_ans = np.array([[11], [14], [7]])
        actual_ans = np.array(rhs_as_function(params))
        assert_array_equal(actual_ans, expected_ans)

    def test_ode_rhs_as_function_cache_does_not_persist_between_instances(self):
        """
        Given two ODEProblems, the cache should not persist between these objects.
        :return:
        """
        p1_lhs = [Moment(np.ones(3), i) for i in sympy.Matrix(['y_1', 'y_2', 'y_3'])]
        p1_rhs = sympy.Matrix(['y_1+y_2+c_2', 'y_2+y_3+c_3', 'y_3+c_1'])

        p2_lhs = [Moment(np.ones(3), i) for i in sympy.Matrix(['y_1', 'y_2', 'y_3'])]
        p2_rhs = sympy.Matrix(['y_1', 'c_1', 'y_2+y_3'])

        p1 = ODEProblem('MEA', p1_lhs, p1_rhs, constants=sympy.symbols(['c_1', 'c_2', 'c_3']))
        p1_rhs_as_function = p1.right_hand_side_as_function([1, 2, 3])

        params = [4, 5, 6]  # y_1, y_2, y_3 in that order

        p2 = ODEProblem('MEA', p2_lhs, p2_rhs, constants=sympy.symbols(['c_1', 'c_2', 'c_3']))
        p2_rhs_as_function = p2.right_hand_side_as_function([1, 2, 3])

        p1_expected_ans = np.array([[11], [14], [7]])
        p2_expected_ans = np.array([[4], [1], [6+5]])
        p1_actual_ans = np.array(p1_rhs_as_function(params))
        p2_actual_ans = np.array(p1_rhs_as_function(params))

        assert_array_equal(p1_actual_ans, p1_expected_ans)
        assert_array_equal(p2_actual_ans, p2_expected_ans)



    def test_ode_moment_no_description_from_variance_terms(self):
{'fraction_non_alphanumeric': 0.1305439330543933, 'fraction_numerical': 0.03598326359832636, 'mean_word_length': 3.5050251256281406, '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': '4920797', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1352, 'n_words': 295}