summaryrefslogtreecommitdiff
path: root/src/test/scala/forge/TestUtil.scala
blob: f06dc6b638d88b204d22fdf84817fce4bdc7fcc3 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package forge

import forge.Target.test
import utest.assert

import scala.collection.mutable

object TestUtil {

  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))
      }
    }
  }

  class TestGraphs(){
    object singleton {
      val single = test()
    }
    object pair {
      val up = test()
      val down = test(up)
    }

    object anonTriple{
      val up = test()
      val down = test(test(up))
    }
    object diamond{
      val up = test()
      val left = test(up)
      val right = test(up)
      val down = test(left, right)
    }
    object anonDiamond{
      val up = test()
      val down = test(test(up), test(up))
    }

    //          o   g-----o
    //           \   \     \
    // o          o   h-----I---o
    //  \        / \ / \   / \   \
    //   A---c--o   E   o-o   \   \
    //  / \ / \    / \         o---J
    // o   d   o--o   o       /   /
    //      \ /        \     /   /
    //       o          o---F---o
    //      /          /
    //  o--B          o
    object bigSingleTerminal{
      val a = test(test(), test())
      val b = test(test())
      val e = {
        val c = test(a)
        val d = test(a)
        test(test(test(), test(c)), test(test(c, test(d, b))))
      }
      val f = test(test(test(), test(e)))

      val i = {
        val g = test()
        val h = test(g, e)
        test(test(g), test(test(h)))
      }
      val j = test(test(i), test(i, f), test(f))
    }

    (singleton, pair, anonTriple, diamond, anonDiamond, bigSingleTerminal)
  }
}