summaryrefslogtreecommitdiff
path: root/src/test/scala/forge/TestUtil.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/forge/TestUtil.scala')
-rw-r--r--src/test/scala/forge/TestUtil.scala78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/test/scala/forge/TestUtil.scala b/src/test/scala/forge/TestUtil.scala
new file mode 100644
index 00000000..5a328d87
--- /dev/null
+++ b/src/test/scala/forge/TestUtil.scala
@@ -0,0 +1,78 @@
+package forge
+
+import forge.Target.test
+import utest.assert
+
+import scala.collection.mutable
+
+object TestUtil {
+
+ def checkTopological(targets: Seq[Target[_]]) = {
+ val seen = mutable.Set.empty[Target[_]]
+ for(t <- targets.reverseIterator){
+ seen.add(t)
+ for(upstream <- t.inputs){
+ assert(!seen(upstream))
+ }
+ }
+ }
+
+ def makeGraphs() = {
+ object singleton {
+ val single = T{ test() }
+ }
+ object pair {
+ val up = T{ test() }
+ val down = T{ test(up) }
+ }
+
+ object anonTriple{
+ val up = T{ test() }
+ val down = T{ test(test(up)) }
+ }
+ object diamond{
+ val up = T{ test() }
+ val left = T{ test(up) }
+ val right = T{ test(up) }
+ val down = T{ test(left, right) }
+ }
+ object anonDiamond{
+ val up = T{ test() }
+ val down = T{ test(test(up), test(up)) }
+ }
+
+ // x g-----o
+ // \ \ \
+ // x o h-----I---o
+ // \ / \ / \ / \ \
+ // A---c--o E o-o \ \
+ // / \ / \ / \ o---J
+ // x d o--o o / /
+ // \ / \ / /
+ // o o---F---o
+ // / /
+ // x--B x
+ object bigSingleTerminal{
+ val a = T{ test(test(), test()) }
+ val b = T{ test(test()) }
+ val e = T{
+ val c = test(a)
+ val d = test(a)
+ test(test(test(), test(c)), test(test(c, test(d, b))))
+ }
+ val f = T{
+ test(test(test(), test(e)))
+ }
+ val i = T{
+ val g = test()
+ val h = test(g, e)
+ test(test(g), test(test(h)))
+ }
+ val j = T{
+ test(test(i), test(i, f), test(f))
+ }
+ }
+
+ (singleton, pair, anonTriple, diamond, anonDiamond, bigSingleTerminal)
+ }
+}