blob: 9337fbe0a4e760b9444848497023ce4265c78545 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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))
}
}
}
}
|