From 26f5114e48eea103a3c730e9cd3390f8d4dbd516 Mon Sep 17 00:00:00 2001 From: Mikhail Zelenyy Date: Mon, 21 Oct 2019 16:26:47 +0300 Subject: [PATCH 1/2] Simple test for selecting data --- .../workspace/DataPropagationTest.kt | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 dataforge-workspace/src/jvmTest/kotlin/hep/dataforge/workspace/DataPropagationTest.kt 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 -- 2.34.1 From 956c07e386dc6285697e5de4898365f96d3ed24d Mon Sep 17 00:00:00 2001 From: Mikhail Zelenyy Date: Tue, 22 Oct 2019 14:24:22 +0300 Subject: [PATCH 2/2] Fixed default regex in DataFilter --- .../src/commonMain/kotlin/hep/dataforge/data/DataFilter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/DataFilter.kt b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/DataFilter.kt index 987d8412..a55aac9d 100644 --- a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/DataFilter.kt +++ b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/DataFilter.kt @@ -16,7 +16,7 @@ class DataFilter(override val config: Config) : Specific { /** * A regular expression pattern for the filter */ - var pattern by string("*.") + var pattern by string(".*") // val prefix by string() // val suffix by string() -- 2.34.1