Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
bf1bfdad
Commit
bf1bfdad
authored
Feb 28, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for recently added numeric division rules.
parent
f39fc1f5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
tests/test_rules_numerics.py
tests/test_rules_numerics.py
+19
-4
No files found.
tests/test_rules_numerics.py
View file @
bf1bfdad
from
src.rules.numerics
import
match_add_numerics
,
add_numerics
,
\
from
src.rules.numerics
import
match_add_numerics
,
add_numerics
,
\
match_divide_numerics
,
divide_numerics
,
match_multiply_numeric
s
,
\
match_divide_numerics
,
divide_numerics
,
reduce_fraction_constant
s
,
\
multiply_numerics
fraction_to_int_fraction
,
match_multiply_numerics
,
multiply_numerics
from
src.node
import
ExpressionLeaf
as
L
,
Scope
from
src.node
import
ExpressionLeaf
as
L
,
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
...
@@ -37,7 +37,7 @@ class TestRulesNumerics(RulesTestCase):
...
@@ -37,7 +37,7 @@ class TestRulesNumerics(RulesTestCase):
self
.
assertEqual
(
add_numerics
(
r
,
(
Scope
(
r
),
l1
,
ml2
)),
-
1
)
self
.
assertEqual
(
add_numerics
(
r
,
(
Scope
(
r
),
l1
,
ml2
)),
-
1
)
def
test_match_divide_numerics
(
self
):
def
test_match_divide_numerics
(
self
):
a
,
b
,
i2
,
i3
,
i
6
,
f1
,
f2
,
f3
=
tree
(
'a,b,2,3
,6,1.0,2.0,3.0'
)
a
,
b
,
i2
,
i3
,
i
4
,
i6
,
f1
,
f2
,
f3
=
tree
(
'a,b,2,3,4
,6,1.0,2.0,3.0'
)
root
=
i6
/
i2
root
=
i6
/
i2
possibilities
=
match_divide_numerics
(
root
)
possibilities
=
match_divide_numerics
(
root
)
...
@@ -46,7 +46,13 @@ class TestRulesNumerics(RulesTestCase):
...
@@ -46,7 +46,13 @@ class TestRulesNumerics(RulesTestCase):
root
=
i3
/
i2
root
=
i3
/
i2
possibilities
=
match_divide_numerics
(
root
)
possibilities
=
match_divide_numerics
(
root
)
self
.
assertEqualPos
(
possibilities
,
[])
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
fraction_to_int_fraction
,
(
1
,
1
,
2
))])
root
=
i2
/
i4
possibilities
=
match_divide_numerics
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
reduce_fraction_constants
,
(
2
,))])
root
=
f3
/
i2
root
=
f3
/
i2
possibilities
=
match_divide_numerics
(
root
)
possibilities
=
match_divide_numerics
(
root
)
...
@@ -80,6 +86,15 @@ class TestRulesNumerics(RulesTestCase):
...
@@ -80,6 +86,15 @@ class TestRulesNumerics(RulesTestCase):
self
.
assertEqual
(
divide_numerics
(
i3
/
f2
,
(
3
,
2.0
)),
1.5
)
self
.
assertEqual
(
divide_numerics
(
i3
/
f2
,
(
3
,
2.0
)),
1.5
)
self
.
assertEqual
(
divide_numerics
(
f3
/
f2
,
(
3.0
,
2.0
)),
1.5
)
self
.
assertEqual
(
divide_numerics
(
f3
/
f2
,
(
3.0
,
2.0
)),
1.5
)
def
test_reduce_fraction_constants
(
self
):
l1
,
l2
=
tree
(
'1,2'
)
self
.
assertEqual
(
reduce_fraction_constants
(
l2
/
4
,
(
2
,)),
l1
/
l2
)
def
test_fraction_to_int_fraction
(
self
):
l1
,
l4
=
tree
(
'1,4'
)
self
.
assertEqual
(
fraction_to_int_fraction
(
l4
/
3
,
(
1
,
1
,
3
)),
l1
+
l1
/
3
)
def
test_match_multiply_numerics
(
self
):
def
test_match_multiply_numerics
(
self
):
i2
,
i3
,
i6
,
f2
,
f3
,
f6
=
tree
(
'2,3,6,2.0,3.0,6.0'
)
i2
,
i3
,
i6
,
f2
,
f3
,
f6
=
tree
(
'2,3,6,2.0,3.0,6.0'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment