diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-03 23:44:39 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-03 23:44:39 -0700 |
commit | 13270145903b457c906a9fa77bd152afb6448ef5 (patch) | |
tree | e85b7ed530e0c8e3c3041cbf17641857c448b602 /core/src/test/scala/forge/TestUtil.scala | |
parent | 66f1c5c2438aeb8f2496575f52c25b09cf5793a6 (diff) | |
download | mill-13270145903b457c906a9fa77bd152afb6448ef5.tar.gz mill-13270145903b457c906a9fa77bd152afb6448ef5.tar.bz2 mill-13270145903b457c906a9fa77bd152afb6448ef5.zip |
Split up forge into `scalaplugin` an `core` subprojects, to allow us to use the `T#apply` macro in the implementation of `scalaplugin.Subproject`
Also needed to implement inter-`Subproject` dependencies so the `MetacircularTests` can continue to support the new layout
Diffstat (limited to 'core/src/test/scala/forge/TestUtil.scala')
-rw-r--r-- | core/src/test/scala/forge/TestUtil.scala | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/core/src/test/scala/forge/TestUtil.scala b/core/src/test/scala/forge/TestUtil.scala new file mode 100644 index 00000000..9337fbe0 --- /dev/null +++ b/core/src/test/scala/forge/TestUtil.scala @@ -0,0 +1,36 @@ +package forge + +import forge.util.{Args, OSet} +import utest.assert +import scala.collection.mutable + +object TestUtil { + def test(inputs: Target[Int]*) = { + new Test(inputs, pure = inputs.nonEmpty) + } + + /** + * A dummy target that takes any number of inputs, and whose output can be + * controlled externally, so you can construct arbitrary dataflow graphs and + * test how changes propagate. + */ + class Test(val inputs: Seq[Target[Int]], + val pure: Boolean) extends Target[Int]{ + var counter = 0 + def evaluate(args: Args) = { + counter + args.args.map(_.asInstanceOf[Int]).sum + } + + override def sideHash = counter + } + def checkTopological(targets: OSet[Target[_]]) = { + val seen = mutable.Set.empty[Target[_]] + for(t <- targets.items.reverseIterator){ + seen.add(t) + for(upstream <- t.inputs){ + assert(!seen(upstream)) + } + } + } + +} |