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
3cfa07da
Commit
3cfa07da
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added unit tests for earliers added logarithmic rules.
parent
68ce57a9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/rules/logarithmic.py
+4
-2
4 additions, 2 deletions
src/rules/logarithmic.py
tests/test_rules_logarithmic.py
+30
-2
30 additions, 2 deletions
tests/test_rules_logarithmic.py
with
34 additions
and
4 deletions
src/rules/logarithmic.py
+
4
−
2
View file @
3cfa07da
...
@@ -34,9 +34,11 @@ def match_constant_logarithm(node):
...
@@ -34,9 +34,11 @@ def match_constant_logarithm(node):
p
=
[]
p
=
[]
if
raised
==
1
:
if
raised
==
1
:
# log(1) -> 0
p
.
append
(
P
(
node
,
logarithm_of_one
))
p
.
append
(
P
(
node
,
logarithm_of_one
))
if
raised
==
base
:
if
raised
==
base
:
# log(a, a) -> log(a) / log(a) # -> 1
p
.
append
(
P
(
node
,
divide_same_base
))
p
.
append
(
P
(
node
,
divide_same_base
))
return
p
return
p
...
@@ -48,7 +50,7 @@ def logarithm_of_one(root, args):
...
@@ -48,7 +50,7 @@ def logarithm_of_one(root, args):
"""
"""
raised
,
base
=
root
raised
,
base
=
root
return
log
(
raised
)
/
log
(
base
)
return
L
(
0
)
MESSAGES
[
logarithm_of_one
]
=
_
(
'
Logarithm of one reduces to zero.
'
)
MESSAGES
[
logarithm_of_one
]
=
_
(
'
Logarithm of one reduces to zero.
'
)
...
@@ -63,7 +65,7 @@ def divide_same_base(root, args):
...
@@ -63,7 +65,7 @@ def divide_same_base(root, args):
return
log
(
raised
)
/
log
(
base
)
return
log
(
raised
)
/
log
(
base
)
MESSAGES
[
divide_same_base
]
=
_
(
'
Apply log_b(a) -> log(a) / log(b).
'
)
MESSAGES
[
divide_same_base
]
=
_
(
'
Apply log_b(a) -> log(a) / log(b)
on {0}
.
'
)
def
match_add_logarithms
(
node
):
def
match_add_logarithms
(
node
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_rules_logarithmic.py
+
30
−
2
View file @
3cfa07da
...
@@ -23,7 +23,18 @@ class TestRulesLogarithmic(RulesTestCase):
...
@@ -23,7 +23,18 @@ class TestRulesLogarithmic(RulesTestCase):
self
.
assertEqualPos
(
match_constant_logarithm
(
root
),
self
.
assertEqualPos
(
match_constant_logarithm
(
root
),
[
P
(
root
,
divide_same_base
)])
[
P
(
root
,
divide_same_base
)])
def
test_logarithm_of_one
(
self
):
root
=
tree
(
'
log 1
'
)
self
.
assertEqual
(
logarithm_of_one
(
root
,
()),
0
)
def
test_divide_same_base
(
self
):
root
,
l5
,
l6
=
tree
(
'
log(5, 6), 5, 6
'
)
self
.
assertEqual
(
divide_same_base
(
root
,
()),
log
(
l5
)
/
log
(
l6
))
def
test_match_add_logarithms
(
self
):
def
test_match_add_logarithms
(
self
):
root
=
tree
(
'
log a + ln b
'
)
self
.
assertEqualPos
(
match_add_logarithms
(
root
),
[])
log_a
,
log_b
=
root
=
tree
(
'
log a + log b
'
)
log_a
,
log_b
=
root
=
tree
(
'
log a + log b
'
)
self
.
assertEqualPos
(
match_add_logarithms
(
root
),
self
.
assertEqualPos
(
match_add_logarithms
(
root
),
[
P
(
root
,
add_logarithms
,
(
Scope
(
root
),
log_a
,
log_b
))])
[
P
(
root
,
add_logarithms
,
(
Scope
(
root
),
log_a
,
log_b
))])
...
@@ -41,7 +52,24 @@ class TestRulesLogarithmic(RulesTestCase):
...
@@ -41,7 +52,24 @@ class TestRulesLogarithmic(RulesTestCase):
[
P
(
root
,
subtract_logarithms
,
(
Scope
(
root
),
log_b
,
log_a
))])
[
P
(
root
,
subtract_logarithms
,
(
Scope
(
root
),
log_b
,
log_a
))])
def
test_add_logarithms
(
self
):
def
test_add_logarithms
(
self
):
root
,
a
,
b
=
tree
(
'
log a + log b,
a, b
'
)
root
,
expect
=
tree
(
'
log a + log b,
log(ab)
'
)
log_a
,
log_b
=
root
log_a
,
log_b
=
root
self
.
assertEqual
(
add_logarithms
(
root
,
(
Scope
(
root
),
log_a
,
log_b
)),
self
.
assertEqual
(
add_logarithms
(
root
,
(
Scope
(
root
),
log_a
,
log_b
)),
log
(
a
*
b
))
expect
)
def
test_expand_negations
(
self
):
root
,
expect
=
tree
(
'
-log(a) - log(b), -(log(a) + log(b))
'
)
log_a
,
log_b
=
root
self
.
assertEqual
(
expand_negations
(
root
,
(
Scope
(
root
),
log_a
,
log_b
)),
expect
)
def
test_subtract_logarithms
(
self
):
root
,
expect
=
tree
(
'
log(a) - log(b), log(a / b)
'
)
loga
,
logb
=
root
self
.
assertEqual
(
subtract_logarithms
(
root
,
(
Scope
(
root
),
loga
,
logb
)),
expect
)
root
,
expect
=
tree
(
'
-log(a) + log(b), log(b / a)
'
)
loga
,
logb
=
root
self
.
assertEqual
(
subtract_logarithms
(
root
,
(
Scope
(
root
),
logb
,
loga
)),
expect
)
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