Merge pull request #22 from mipt-npm/dev-zelenyy

Dev zelenyy
This commit is contained in:
Alexander Nozik 2019-10-29 21:20:39 +03:00 committed by GitHub
commit 2b1fbf15ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 1 deletions

View File

@ -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()

View File

@ -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<Int> { 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<Int> { 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<Int> { 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<DataPropagationTestPlugin> {
override val type: KClass<out DataPropagationTestPlugin> = 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())
}
}