-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add d2:log and d2:exponent to program rule grammar
#101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3184ced
feat: add `d2:pow` and `d2:log`
superskip 8dbf102
chore: update snapshot version
superskip bb8e867
chore: update api
superskip 93ead44
fix: share implementation of `log` and `d2_log`
superskip 4cafe2f
fix: rename `pow` -> `exponent`
superskip 1d67dc4
fix: review comments
superskip 7fb1c95
fix: add error margin to test result
superskip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/commonTest/kotlin/org/hisp/dhis/lib/expression/function/ExponentTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package org.hisp.dhis.lib.expression.function | ||
|
|
||
| import org.hisp.dhis.lib.expression.Expression | ||
| import org.hisp.dhis.lib.expression.ExpressionMode | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
|
|
||
| /** | ||
| * Tests the `d2:exponent` function | ||
| * | ||
| * @author Tony Valle | ||
| */ | ||
| internal class ExponentTest { | ||
|
|
||
| @Test | ||
| fun testExponent() { | ||
| assertEquals(1.0, evaluate("d2:exponent(49, 0)")) | ||
| assertEquals(7.0, evaluate("d2:exponent(49, 0.5)")) | ||
| assertEquals(49.0, evaluate("d2:exponent(49, 1)")) | ||
|
superskip marked this conversation as resolved.
|
||
| assertEquals(64.0, evaluate("d2:exponent(32, 1.2)") as Double, errorMargin) | ||
| assertEquals(25.0, evaluate("d2:exponent(0.2, -2)") as Double, errorMargin) | ||
| } | ||
|
|
||
| @Test | ||
| fun testExponent_Whitespace() { | ||
| assertEquals(2.0, evaluate("d2:exponent(2,1)")) | ||
| assertEquals(2.0, evaluate("d2:exponent( 2, 1)")) | ||
| assertEquals(2.0, evaluate("d2:exponent(2 , 1 )")) | ||
| assertEquals(2.0, evaluate("d2:exponent( 2 , 1 )")) | ||
| } | ||
|
|
||
| private val errorMargin: Double = 0.00000001 | ||
|
|
||
| private fun evaluate(expression: String): Any? { | ||
| return Expression(expression, ExpressionMode.RULE_ENGINE_ACTION).evaluate() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to add
d2:logwhenlogalready exists?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that all other program rule functions use the d2:-prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this discussed to keep it consistent? Maybe @enricocolasante knows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say so.
At the moment rule-engine is only allowing
CommonD2FunctionsandRuleEngineD2Functionsand all of them have thed2prefix.There wasn't a real discussion about it. We already have some generic functions about numeric operations like
modulusorfloorusing thed2prefix and as always this argument is the one used to continue doing this way.I think at some point we should separate generic functions and custom DHIS2 functions, the question is: should we do it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not the best time to do another refactor of the language(s) on a more fundamental level so if enrico is happy with this PR I think we try to move it forward