-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
752 additions
and
246 deletions.
There are no files selected for viewing
This file contains 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 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 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
60 changes: 0 additions & 60 deletions
60
src/commonTest/kotlin/org/hisp/dhis/lib/expression/AggregateFunctionsExpressionTest.kt
This file was deleted.
Oops, something went wrong.
169 changes: 0 additions & 169 deletions
169
src/commonTest/kotlin/org/hisp/dhis/lib/expression/FunctionsExpressionTest.kt
This file was deleted.
Oops, something went wrong.
This file contains 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
19 changes: 19 additions & 0 deletions
19
src/commonTest/kotlin/org/hisp/dhis/lib/expression/function/AggregateFunctionTest.kt
This file contains 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,19 @@ | ||
package org.hisp.dhis.lib.expression.function | ||
|
||
import org.hisp.dhis.lib.expression.Expression | ||
import org.hisp.dhis.lib.expression.spi.* | ||
|
||
abstract class AggregateFunctionTest { | ||
|
||
fun evaluate(expression: String, dataValues: Map<DataItem, Any>): Double { | ||
return Expression(expression).evaluate( | ||
{ _: String -> null }, | ||
ExpressionData().copy(dataItemValues = dataValues)) as Double | ||
} | ||
|
||
fun newDeDataItem(u1234567890: String): DataItem { | ||
return DataItem( | ||
DataItemType.DATA_ELEMENT, ID(ID.Type.DataElementUID, u1234567890), | ||
QueryModifiers().copy(periodAggregation = true)) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/commonTest/kotlin/org/hisp/dhis/lib/expression/function/AvgTest.kt
This file contains 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,27 @@ | ||
package org.hisp.dhis.lib.expression.function | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
/** | ||
* Tests the `avg` function | ||
* | ||
* @author Jan Bernitt | ||
*/ | ||
internal class AvgTest : AggregateFunctionTest() { | ||
|
||
@Test | ||
fun testAvg_Single() { | ||
val dataValues = mapOf( | ||
newDeDataItem("u1234567890") to doubleArrayOf(0.0, 10.0, 5.0, 3.0, 7.0)) | ||
assertEquals(5.0, evaluate("avg(#{u1234567890})", dataValues)) | ||
} | ||
|
||
@Test | ||
fun testAvg_Complex() { | ||
val dataValues = mapOf( | ||
newDeDataItem("u1234567890") to doubleArrayOf(0.0, 10.0, 5.0, 3.0, 7.0), | ||
newDeDataItem("v1234567890") to doubleArrayOf(0.0, 10.0, 5.0, 3.0, 7.0)) | ||
assertEquals(10.0, evaluate("avg(#{u1234567890} + #{v1234567890})", dataValues)) | ||
} | ||
} |
This file contains 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.