A test for complex task logic

This commit is contained in:
Alexander Nozik 2019-09-12 16:53:57 +03:00
parent 74b5a1ac50
commit a0abb99d88

View File

@ -1,11 +1,11 @@
package hep.dataforge.workspace
import hep.dataforge.context.PluginTag
import hep.dataforge.data.first
import hep.dataforge.data.get
import hep.dataforge.data.*
import hep.dataforge.meta.boolean
import hep.dataforge.meta.get
import org.junit.Test
import hep.dataforge.names.asName
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@ -33,7 +33,7 @@ class SimpleWorkspaceTest {
}
task("square") {
val square = task("square") {
model {
allData()
}
@ -46,6 +46,37 @@ class SimpleWorkspaceTest {
}
}
val linear = task("linear") {
model {
allData()
}
pipe<Int, Int> { data ->
context.logger.info { "Starting linear on $data" }
data * 2 + 1
}
}
val fullSquare = task("fullsquare") {
model {
dependsOn("square", placement = "square".asName())
dependsOn("linear", placement = "linear".asName())
}
transform<Any> { data ->
val squareNode = data["square"].withType<Int>().node!!
val linearNode = data["linear"].withType<Int>().node!!
return@transform DataNode.build(Int::class) {
squareNode.dataSequence().forEach { (name, _) ->
val newData = Data{
val squareValue = squareNode[name].data!!.get()
val linearValue = linearNode[name].data!!.get()
squareValue+linearValue
}
set(name,newData)
}
}
}
}
task("sum") {
model {
dependsOn("square")
@ -60,7 +91,7 @@ class SimpleWorkspaceTest {
model {
allData()
}
joinByGroup<Int, Double> {env->
joinByGroup<Int, Double> { env ->
group("even", filter = { name, _ -> name.toString().toInt() % 2 == 0 }) {
result { data ->
env.context.logger.info { "Starting even" }
@ -107,4 +138,10 @@ class SimpleWorkspaceTest {
assertTrue { tasks["test.test"] != null }
//val node = workspace.run("test.test", "empty")
}
@Test
fun testFullSquare(){
val node = workspace.run("fullsquare")
println(node.toMeta())
}
}