Last active
March 5, 2018 10:49
-
-
Save mcallisto/59319680f74598b2a420f7c3ef1a4259 to your computer and use it in GitHub Desktop.
ScalaTest case for findCycleContaining
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Mario._ | |
import org.scalatest.FlatSpec | |
import scalax.collection.Graph | |
import scalax.collection.GraphEdge.UnDiEdge // shortcuts | |
import scalax.collection.GraphPredef._ | |
class findContainingTest extends FlatSpec { | |
def checkLength[T](found: Option[Traversable[T]], sizes: List[Int]): Boolean = found match { | |
case Some(vector) if sizes.contains(vector.size) ⇒ true | |
case _ ⇒ false | |
} | |
val g: Graph[Int,UnDiEdge] = Graph(4~5, 5~6, 6~7, 7~5, 7~8, 8~4) | |
"The proposed undirected graph" must "have some cycle containing node 4" in { | |
assert(checkLength(g.findCycleContaining(4), List(5, 6)) === true) | |
} | |
it must "have some cycle containing node 5" in { | |
assert(checkLength(g.findCycleContaining(5), List(4, 5, 6)) === true) | |
} | |
it must "have some cycle containing node 6" in { | |
assert(checkLength(g.findCycleContaining(6), List(4, 6)) === true) | |
} | |
"The proposed undirected graph without edge 5~7" must "have just one cycle containing each node" in { | |
assert(checkLength((g - 5~7).findCycleContaining(4), List(6)) === true) | |
assert(checkLength((g - 5~7).findCycleContaining(5), List(6)) === true) | |
assert(checkLength((g - 5~7).findCycleContaining(6), List(6)) === true) | |
} | |
"The proposed undirected graph without edge 6~7" must "have just one cycle containing node 4 and 5" in { | |
assert(checkLength((g - 6~7).findCycleContaining(4), List(5)) === true) | |
assert(checkLength((g - 6~7).findCycleContaining(5), List(5)) === true) | |
} | |
it must "NOT have a cycle containing node 6" in { | |
assert((g - 6~7).findCycleContaining(6).isEmpty === true) | |
} | |
"The proposed undirected graph without edge 4~8" must "NOT have a cycle containing node 4" in { | |
assert((g - 4~8).findCycleContaining(4).isEmpty === true) | |
} | |
it must "have just one cycle containing node 5 and 6" in { | |
assert(checkLength((g - 4~8).findCycleContaining(5), List(4)) === true) | |
assert(checkLength((g - 4~8).findCycleContaining(6), List(4)) === true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment