diff --git a/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/DataPropagationTest.kt b/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/DataPropagationTest.kt new file mode 100644 index 00000000..c449ffc3 --- /dev/null +++ b/dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/DataPropagationTest.kt @@ -0,0 +1,95 @@ +package hep.dataforge.workspace + +import hep.dataforge.context.Context +import hep.dataforge.context.PluginFactory +import hep.dataforge.context.PluginTag +import hep.dataforge.data.* +import hep.dataforge.meta.Meta +import hep.dataforge.names.asName +import org.junit.Test +import kotlin.reflect.KClass +import kotlin.test.assertEquals + + +class DataPropagationTestPlugin : WorkspacePlugin() { + override val tag: PluginTag = Companion.tag + + val testAllData = task("allData", Int::class) { + model { + allData() + } + transform { data -> + return@transform DataNode { + val result = data.dataSequence().map { it.second.get() }.reduce { acc, pair -> acc + pair } + set("result".asName(), Data { result }) + } + } + } + + + val testSingleData = task("singleData", Int::class) { + model { + data("myData\\[12\\]") + } + transform { data -> + return@transform DataNode { + val result = data.dataSequence().map { it.second.get() }.reduce { acc, pair -> acc + pair } + set("result".asName(), Data { result }) + } + } + } + + val testAllRegexData = task("allRegexData", Int::class) { + model { + data(pattern = "myData.*") + } + transform { data -> + return@transform DataNode { + val result = data.dataSequence().map { it.second.get() }.reduce { acc, pair -> acc + pair } + set("result".asName(), Data { result }) + } + } + } + + + companion object : PluginFactory { + + override val type: KClass = DataPropagationTestPlugin::class + + override fun invoke(meta: Meta, context: Context): DataPropagationTestPlugin = + DataPropagationTestPlugin(meta) + + override val tag: PluginTag = PluginTag("Test") + } +} + +class DataPropagationTest { + val testWorkspace = Workspace { + context { + plugin(DataPropagationTestPlugin()) + } + data { + repeat(100) { + static("myData[$it]", it) + } + } + } + + @Test + fun testAllData() { + val node = testWorkspace.run("Test.allData") + assertEquals(4950, node.first()!!.get()) + } + + @Test + fun testAllRegexData() { + val node = testWorkspace.run("Test.allRegexData") + assertEquals(4950, node.first()!!.get()) + } + + @Test + fun testSingleData() { + val node = testWorkspace.run("Test.singleData") + assertEquals(12, node.first()!!.get()) + } +} \ No newline at end of file