Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
trs
Commits
bf1bfdad
Commit
bf1bfdad
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added tests for recently added numeric division rules.
parent
f39fc1f5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_rules_numerics.py
+19
-4
19 additions, 4 deletions
tests/test_rules_numerics.py
with
19 additions
and
4 deletions
tests/test_rules_numerics.py
+
19
−
4
View file @
bf1bfdad
from
src.rules.numerics
import
match_add_numerics
,
add_numerics
,
\
match_divide_numerics
,
divide_numerics
,
match_multiply_numeric
s
,
\
multiply_numerics
match_divide_numerics
,
divide_numerics
,
reduce_fraction_constant
s
,
\
fraction_to_int_fraction
,
match_multiply_numerics
,
multiply_numerics
from
src.node
import
ExpressionLeaf
as
L
,
Scope
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
...
...
@@ -37,7 +37,7 @@ class TestRulesNumerics(RulesTestCase):
self
.
assertEqual
(
add_numerics
(
r
,
(
Scope
(
r
),
l1
,
ml2
)),
-
1
)
def
test_match_divide_numerics
(
self
):
a
,
b
,
i2
,
i3
,
i6
,
f1
,
f2
,
f3
=
tree
(
'
a,b,2,3,6,1.0,2.0,3.0
'
)
a
,
b
,
i2
,
i3
,
i4
,
i6
,
f1
,
f2
,
f3
=
tree
(
'
a,b,2,3,
4,
6,1.0,2.0,3.0
'
)
root
=
i6
/
i2
possibilities
=
match_divide_numerics
(
root
)
...
...
@@ -46,7 +46,13 @@ class TestRulesNumerics(RulesTestCase):
root
=
i3
/
i2
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
possibilities
=
match_divide_numerics
(
root
)
...
...
@@ -80,6 +86,15 @@ class TestRulesNumerics(RulesTestCase):
self
.
assertEqual
(
divide_numerics
(
i3
/
f2
,
(
3
,
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
):
i2
,
i3
,
i6
,
f2
,
f3
,
f6
=
tree
(
'
2,3,6,2.0,3.0,6.0
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment