Last active
March 19, 2018 08:11
-
-
Save mcallisto/39633f64a0d8615b52fa34a73148632f to your computer and use it in GitHub Desktop.
Testing 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
object `given some undirected graphs` { | |
val unDiAcyclic_1: CC[Int, UnDiEdge] = factory(1 ~ 2, 2 ~ 3) | |
val unDiCyclic_1: CC[Int, UnDiEdge] = unDiAcyclic_1 + 1 ~ 3 | |
val unDiAcyclic_2: Graph[Int, UnDiEdge] = Graph(1 ~ 2, 1 ~ 3, 2 ~ 4, 2 ~ 5) | |
val unDiCyclic_21: Graph[Int, UnDiEdge] = unDiAcyclic_2 + 3 ~ 5 | |
val unDiCyclic_22: Graph[Int, UnDiEdge] = unDiAcyclic_2 ++ List(3 ~ 6, 6 ~ 7, 7 ~ 4) | |
val unDiCyclic_3: CC[Int, UnDiEdge] = factory() ++ Data.elementsOfUnDi_1 | |
def ua_1 (outer: Int): unDiAcyclic_1.NodeT = unDiAcyclic_1 get outer | |
def ua_2 (outer: Int): unDiAcyclic_2.NodeT = unDiAcyclic_2 get outer | |
def uc_1 (outer: Int): unDiCyclic_1.NodeT = unDiCyclic_1 get outer | |
def uc_21 (outer: Int): unDiCyclic_21.NodeT = unDiCyclic_21 get outer | |
def uc_22 (outer: Int): unDiCyclic_22.NodeT = unDiCyclic_22 get outer | |
def uc_3 (outer: Int): unDiCyclic_3.NodeT = unDiCyclic_3 get outer | |
def `the cycle returned by 'findCycle' contains the expected nodes` { | |
(unDiAcyclic_1 get 1 findCycle) should be (None) | |
uc_1(2).findCycle.get.nodes.toList should ( | |
be (List(2, 3, 1, 2) map uc_1) or | |
be (List(2, 1, 3, 2) map uc_1)) | |
(unDiAcyclic_2 get 1 findCycle) should be (None) | |
uc_21(1).findCycle.get.nodes.toList should ( | |
be (List(1, 3, 5, 2, 1) map uc_21) or | |
be (List(1, 2, 5, 3, 1) map uc_21)) | |
uc_22(3).findCycle.get.nodes.toList should ( | |
be (List(3, 1, 2, 4, 7, 6, 3) map uc_22) or | |
be (List(3, 6, 7, 4, 2, 1, 3) map uc_22)) | |
} | |
def `the cycle returned by 'findCycleContaining' contains the expected nodes` { | |
(ua_1(1) findCycleContaining(ua_1(1))) should be (None) | |
(ua_1(1) findCycleContaining(ua_1(2))) should be (None) | |
(ua_1(1) findCycleContaining(ua_1(3))) should be (None) | |
uc_1(2).findCycleContaining(uc_1(3)).get.nodes.toList should ( | |
be (List(2, 3, 1, 2) map uc_1) or | |
be (List(2, 1, 3, 2) map uc_1)) | |
(ua_2(1) findCycleContaining(ua_2(3))) should be (None) | |
uc_21(1).findCycleContaining(uc_21(3)).get.nodes.toList should ( | |
be (List(1, 3, 5, 2, 1) map uc_21) or | |
be (List(1, 2, 5, 3, 1) map uc_21)) | |
uc_21(1).findCycleContaining(uc_21(4)).get.nodes.toList should be (None) | |
uc_22(3).findCycleContaining(uc_22(4)).get.nodes.toList should ( | |
be (List(3, 1, 2, 4, 7, 6, 3) map uc_22) or | |
be (List(3, 6, 7, 4, 2, 1, 3) map uc_22)) | |
uc_22(3).findCycleContaining(uc_22(5)).get.nodes.toList should be (None) | |
uc_3(3).findCycleContaining(uc_3(2)).get.nodes.toList should ( | |
be (List(3, 2, 1, 3) map uc_3)) | |
uc_3(3).findCycleContaining(uc_3(1)).get.nodes.toList should ( | |
be (List(3, 2, 1, 3) map uc_3) or | |
be (List(3, 5, 1, 3) map uc_3)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment