From a0abb99d8851e620b6b652132319daa35ed7df72 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 12 Sep 2019 16:53:57 +0300 Subject: [PATCH] A test for complex task logic --- .../workspace/SimpleWorkspaceTest.kt | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/SimpleWorkspaceTest.kt b/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/SimpleWorkspaceTest.kt index b64ee467..95233251 100644 --- a/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/SimpleWorkspaceTest.kt +++ b/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/SimpleWorkspaceTest.kt @@ -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 { 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 { data -> + val squareNode = data["square"].withType().node!! + val linearNode = data["linear"].withType().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 {env-> + joinByGroup { 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()) + } } \ No newline at end of file