|
@@ -1,11 +1,11 @@
|
|
|
from src.rules.integrals import indef, choose_constant, solve_integral, \
|
|
from src.rules.integrals import indef, choose_constant, solve_integral, \
|
|
|
match_solve_indef, solve_indef, match_integrate_variable_power, \
|
|
match_solve_indef, solve_indef, match_integrate_variable_power, \
|
|
|
integrate_variable_root, integrate_variable_exponent, \
|
|
integrate_variable_root, integrate_variable_exponent, \
|
|
|
- match_constant_integral, constant_integral, \
|
|
|
|
|
- match_factor_out_constant, factor_out_constant, \
|
|
|
|
|
- match_division_integral, division_integral, extend_division_integral, \
|
|
|
|
|
- match_function_integral, logarithm_integral, sinus_integral, \
|
|
|
|
|
- cosinus_integral
|
|
|
|
|
|
|
+ match_constant_integral, constant_integral, single_variable_integral, \
|
|
|
|
|
+ match_factor_out_constant, split_negation_to_constant, \
|
|
|
|
|
+ factor_out_constant, match_division_integral, division_integral, \
|
|
|
|
|
+ extend_division_integral, match_function_integral, \
|
|
|
|
|
+ logarithm_integral, sinus_integral, cosinus_integral
|
|
|
from src.node import Scope
|
|
from src.node import Scope
|
|
|
from src.possibilities import Possibility as P
|
|
from src.possibilities import Possibility as P
|
|
|
from tests.rulestestcase import RulesTestCase, tree
|
|
from tests.rulestestcase import RulesTestCase, tree
|
|
@@ -41,9 +41,16 @@ class TestRulesIntegrals(RulesTestCase):
|
|
|
self.assertEqual(solve_indef(root, ()), expect)
|
|
self.assertEqual(solve_indef(root, ()), expect)
|
|
|
|
|
|
|
|
def test_match_integrate_variable_power(self):
|
|
def test_match_integrate_variable_power(self):
|
|
|
- for root in tree('int x ^ n, int x ^ n'):
|
|
|
|
|
- self.assertEqualPos(match_integrate_variable_power(root),
|
|
|
|
|
- [P(root, integrate_variable_root)])
|
|
|
|
|
|
|
+ root = tree('int x ^ n')
|
|
|
|
|
+ self.assertEqualPos(match_integrate_variable_power(root),
|
|
|
|
|
+ [P(root, integrate_variable_root)])
|
|
|
|
|
+
|
|
|
|
|
+ root = tree('int x ^ n')
|
|
|
|
|
+ self.assertEqualPos(match_integrate_variable_power(root),
|
|
|
|
|
+ [P(root, integrate_variable_root)])
|
|
|
|
|
+
|
|
|
|
|
+ root = tree('int -x ^ n')
|
|
|
|
|
+ self.assertEqualPos(match_integrate_variable_power(root), [])
|
|
|
|
|
|
|
|
for root in tree('int g ^ x, int g ^ x'):
|
|
for root in tree('int g ^ x, int g ^ x'):
|
|
|
self.assertEqualPos(match_integrate_variable_power(root),
|
|
self.assertEqualPos(match_integrate_variable_power(root),
|
|
@@ -58,11 +65,21 @@ class TestRulesIntegrals(RulesTestCase):
|
|
|
self.assertEqual(integrate_variable_exponent(root, ()), expect)
|
|
self.assertEqual(integrate_variable_exponent(root, ()), expect)
|
|
|
|
|
|
|
|
def test_match_constant_integral(self):
|
|
def test_match_constant_integral(self):
|
|
|
- root0, root1 = tree('int 2, int c dx')
|
|
|
|
|
- self.assertEqualPos(match_constant_integral(root0),
|
|
|
|
|
- [P(root0, constant_integral)])
|
|
|
|
|
- self.assertEqualPos(match_constant_integral(root1),
|
|
|
|
|
- [P(root1, constant_integral)])
|
|
|
|
|
|
|
+ root = tree('int x dx')
|
|
|
|
|
+ self.assertEqualPos(match_constant_integral(root),
|
|
|
|
|
+ [P(root, single_variable_integral)])
|
|
|
|
|
+
|
|
|
|
|
+ root = tree('int 2')
|
|
|
|
|
+ self.assertEqualPos(match_constant_integral(root),
|
|
|
|
|
+ [P(root, constant_integral)])
|
|
|
|
|
+
|
|
|
|
|
+ root = tree('int c dx')
|
|
|
|
|
+ self.assertEqualPos(match_constant_integral(root),
|
|
|
|
|
+ [P(root, constant_integral)])
|
|
|
|
|
+
|
|
|
|
|
+ def test_single_variable_integral(self):
|
|
|
|
|
+ root, expect = tree('int x, int x ^ 1')
|
|
|
|
|
+ self.assertEqual(single_variable_integral(root, ()), expect)
|
|
|
|
|
|
|
|
def test_constant_integral(self):
|
|
def test_constant_integral(self):
|
|
|
root, expect = tree('int 2, 2x + c')
|
|
root, expect = tree('int 2, 2x + c')
|
|
@@ -76,6 +93,14 @@ class TestRulesIntegrals(RulesTestCase):
|
|
|
self.assertEqualPos(match_factor_out_constant(root),
|
|
self.assertEqualPos(match_factor_out_constant(root),
|
|
|
[P(root, factor_out_constant, (Scope(cx), c))])
|
|
[P(root, factor_out_constant, (Scope(cx), c))])
|
|
|
|
|
|
|
|
|
|
+ root = tree('int -x2 dx')
|
|
|
|
|
+ self.assertEqualPos(match_factor_out_constant(root),
|
|
|
|
|
+ [P(root, split_negation_to_constant)])
|
|
|
|
|
+
|
|
|
|
|
+ def test_split_negation_to_constant(self):
|
|
|
|
|
+ root, expect = tree('int -x2 dx, int -1x2 dx')
|
|
|
|
|
+ self.assertEqual(split_negation_to_constant(root, ()), expect)
|
|
|
|
|
+
|
|
|
def test_factor_out_constant(self):
|
|
def test_factor_out_constant(self):
|
|
|
root, expect = tree('int cx2 dx, c int x2 dx')
|
|
root, expect = tree('int cx2 dx, c int x2 dx')
|
|
|
c, x2 = cx2 = root[0]
|
|
c, x2 = cx2 = root[0]
|