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/GraphTests.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/GraphTests.scala')
-rw-r--r-- | core/src/test/scala/forge/GraphTests.scala | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/core/src/test/scala/forge/GraphTests.scala b/core/src/test/scala/forge/GraphTests.scala new file mode 100644 index 00000000..572e459e --- /dev/null +++ b/core/src/test/scala/forge/GraphTests.scala @@ -0,0 +1,187 @@ +package forge + +import utest._ +import TestUtil.test +import forge.util.OSet + +object GraphTests extends TestSuite{ + + val tests = Tests{ + + + val graphs = new TestGraphs() + import graphs._ + + 'discovery{ + class CanNest{ + val single = test() + val invisible: Any = test() + } + object outer { + val single = test() + val invisible: Any = test() + object nested{ + val single = test() + val invisible: Any = test() + + } + val classInstance = new CanNest + + } + val discovered = Discovered[outer.type].apply(outer).map(x => (x._1, x._3)) + val expected = Seq( + (List("classInstance", "single"), outer.classInstance.single), + (List("nested", "single"), outer.nested.single), + (List("single"), outer.single) + ) + assert(discovered == expected) + } + + + 'topoSortedTransitiveTargets - { + def check(targets: OSet[Target[_]], expected: OSet[Target[_]]) = { + val result = Evaluator.topoSortedTransitiveTargets(targets).values + TestUtil.checkTopological(result) + assert(result == expected) + } + + 'singleton - check( + targets = OSet(singleton.single), + expected = OSet(singleton.single) + ) + 'pair - check( + targets = OSet(pair.down), + expected = OSet(pair.up, pair.down) + ) + 'anonTriple - check( + targets = OSet(anonTriple.down), + expected = OSet(anonTriple.up, anonTriple.down.inputs(0), anonTriple.down) + ) + 'diamond - check( + targets = OSet(diamond.down), + expected = OSet(diamond.up, diamond.left, diamond.right, diamond.down) + ) + 'anonDiamond - check( + targets = OSet(diamond.down), + expected = OSet( + diamond.up, + diamond.down.inputs(0), + diamond.down.inputs(1), + diamond.down + ) + ) + 'bigSingleTerminal - { + val result = Evaluator.topoSortedTransitiveTargets(OSet(bigSingleTerminal.j)).values + TestUtil.checkTopological(result) + assert(result.size == 28) + } + } + + 'groupAroundNamedTargets - { + def check[T: Discovered](base: T, + target: TestUtil.Test, + expected: OSet[(OSet[TestUtil.Test], Int)]) = { + + val mapping = Discovered.mapping(base) + val topoSortedTransitive = Evaluator.topoSortedTransitiveTargets(OSet(target)) + + val grouped = Evaluator.groupAroundNamedTargets(topoSortedTransitive, mapping) + val flattened = OSet.from(grouped.values().flatMap(_.items)) + + TestUtil.checkTopological(flattened) + for(((expectedPresent, expectedSize), i) <- expected.items.zipWithIndex){ + val grouping = grouped.lookupKey(i) + assert( + grouping.size == expectedSize, + grouping.filter(mapping.contains) == expectedPresent + ) + } + } + 'singleton - check( + singleton, + singleton.single, + OSet(OSet(singleton.single) -> 1) + ) + 'pair - check( + pair, + pair.down, + OSet(OSet(pair.up) -> 1, OSet(pair.down) -> 1) + ) + 'anonTriple - check( + anonTriple, + anonTriple.down, + OSet(OSet(anonTriple.up) -> 1, OSet(anonTriple.down) -> 2) + ) + 'diamond - check( + diamond, + diamond.down, + OSet( + OSet(diamond.up) -> 1, + OSet(diamond.left) -> 1, + OSet(diamond.right) -> 1, + OSet(diamond.down) -> 1 + ) + ) + 'anonDiamond - check( + anonDiamond, + anonDiamond.down, + OSet( + OSet(anonDiamond.up) -> 1, + OSet(anonDiamond.down) -> 3 + ) + ) + 'bigSingleTerminal - check( + bigSingleTerminal, + bigSingleTerminal.j, + OSet( + OSet(bigSingleTerminal.a) -> 3, + OSet(bigSingleTerminal.b) -> 2, + OSet(bigSingleTerminal.e) -> 9, + OSet(bigSingleTerminal.i) -> 6, + OSet(bigSingleTerminal.f) -> 4, + OSet(bigSingleTerminal.j) -> 4 + ) + ) + } + + 'labeling - { + + def check[T: Discovered](base: T, t: Target[_], relPath: Option[String]) = { + + + val names: Seq[(Target[_], Seq[String])] = Discovered.mapping(base).mapValues(_.segments).toSeq + val nameMap = names.toMap + + val targetLabel = nameMap.get(t).map(_.mkString(".")) + assert(targetLabel == relPath) + } + 'singleton - check(singleton, singleton.single, Some("single")) + 'pair - { + check(pair, pair.up, Some("up")) + check(pair, pair.down, Some("down")) + } + + 'anonTriple - { + check(anonTriple, anonTriple.up, Some("up")) + check(anonTriple, anonTriple.down.inputs(0), None) + check(anonTriple, anonTriple.down, Some("down")) + } + + 'diamond - { + check(diamond, diamond.up, Some("up")) + check(diamond, diamond.left, Some("left")) + check(diamond, diamond.right, Some("right")) + check(diamond, diamond.down, Some("down")) + } + + 'anonDiamond - { + check(anonDiamond, anonDiamond.up, Some("up")) + check(anonDiamond, anonDiamond.down.inputs(0), None) + check(anonDiamond, anonDiamond.down.inputs(1), None) + check(anonDiamond, anonDiamond.down, Some("down")) + } + + } + + } +} |