diff options
Diffstat (limited to 'src/test/scala')
-rw-r--r-- | src/test/scala/forge/EvaluationTests.scala | 6 | ||||
-rw-r--r-- | src/test/scala/forge/GraphTests.scala | 6 | ||||
-rw-r--r-- | src/test/scala/forge/TestGraphs.scala | 2 | ||||
-rw-r--r-- | src/test/scala/forge/TestUtil.scala | 20 |
4 files changed, 25 insertions, 9 deletions
diff --git a/src/test/scala/forge/EvaluationTests.scala b/src/test/scala/forge/EvaluationTests.scala index 313ceaaa..fe5d0b09 100644 --- a/src/test/scala/forge/EvaluationTests.scala +++ b/src/test/scala/forge/EvaluationTests.scala @@ -78,7 +78,7 @@ object EvaluationTests extends TestSuite{ up.counter += 1 check(down, expValue = 2, expEvaled = OSet(up, middle, down)) - middle.asInstanceOf[Target.Test].counter += 1 + middle.asInstanceOf[TestUtil.Test].counter += 1 check(down, expValue = 3, expEvaled = OSet(middle, down)) } @@ -103,8 +103,8 @@ object EvaluationTests extends TestSuite{ 'anonDiamond - { import anonDiamond._ val check = new Checker(anonDiamond) - val left = down.inputs(0).asInstanceOf[Target.Test] - val right = down.inputs(1).asInstanceOf[Target.Test] + val left = down.inputs(0).asInstanceOf[TestUtil.Test] + val right = down.inputs(1).asInstanceOf[TestUtil.Test] check(down, expValue = 0, expEvaled = OSet(up, left, right, down)) down.counter += 1 diff --git a/src/test/scala/forge/GraphTests.scala b/src/test/scala/forge/GraphTests.scala index d197fb5f..ec84218f 100644 --- a/src/test/scala/forge/GraphTests.scala +++ b/src/test/scala/forge/GraphTests.scala @@ -1,7 +1,7 @@ package forge import utest._ -import Target.test +import TestUtil.test import forge.util.OSet object GraphTests extends TestSuite{ @@ -79,8 +79,8 @@ object GraphTests extends TestSuite{ 'groupAroundNamedTargets - { def check[T: Discovered](base: T, - target: Target.Test, - expected: OSet[(OSet[Target.Test], Int)]) = { + target: TestUtil.Test, + expected: OSet[(OSet[TestUtil.Test], Int)]) = { val mapping = Discovered.mapping(base) val topoSortedTransitive = Evaluator.topoSortedTransitiveTargets(OSet(target)) diff --git a/src/test/scala/forge/TestGraphs.scala b/src/test/scala/forge/TestGraphs.scala index 8dac142c..0ee48a18 100644 --- a/src/test/scala/forge/TestGraphs.scala +++ b/src/test/scala/forge/TestGraphs.scala @@ -1,6 +1,6 @@ package forge -import forge.Target.test +import forge.TestUtil.test class TestGraphs(){ // single diff --git a/src/test/scala/forge/TestUtil.scala b/src/test/scala/forge/TestUtil.scala index 8405c87c..9337fbe0 100644 --- a/src/test/scala/forge/TestUtil.scala +++ b/src/test/scala/forge/TestUtil.scala @@ -1,12 +1,28 @@ package forge -import forge.util.OSet +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){ |