diff options
author | Akihiro Matsukawa <amatsukawa@twitter.com> | 2013-12-18 18:22:53 -0800 |
---|---|---|
committer | Akihiro Matsukawa <amatsukawa@twitter.com> | 2013-12-18 18:22:53 -0800 |
commit | 989f22b365c8f51fa9c262f29bb07ed608d967a1 (patch) | |
tree | 2cd9e617f6460e664e4b0ad0eaef00f192988806 /graph/src | |
parent | b1db1b6c84cfaa0c45cd99386c4500dc6ccf0bf6 (diff) | |
download | spark-989f22b365c8f51fa9c262f29bb07ed608d967a1.tar.gz spark-989f22b365c8f51fa9c262f29bb07ed608d967a1.tar.bz2 spark-989f22b365c8f51fa9c262f29bb07ed608d967a1.zip |
added scc tests
Diffstat (limited to 'graph/src')
-rw-r--r-- | graph/src/test/scala/org/apache/spark/graph/AnalyticsSuite.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/graph/src/test/scala/org/apache/spark/graph/AnalyticsSuite.scala b/graph/src/test/scala/org/apache/spark/graph/AnalyticsSuite.scala index 05ebe2b84d..d36339b65b 100644 --- a/graph/src/test/scala/org/apache/spark/graph/AnalyticsSuite.scala +++ b/graph/src/test/scala/org/apache/spark/graph/AnalyticsSuite.scala @@ -199,6 +199,49 @@ class AnalyticsSuite extends FunSuite with LocalSparkContext { } } // end of reverse chain connected components + test("Island Strongly Connected Components") { + withSpark(new SparkContext("local", "test")) { sc => + val vertices = sc.parallelize((1L to 5L).map(x => (x, -1))) + val edges = sc.parallelize(Seq.empty[Edge[Int]]) + val graph = Graph(vertices, edges) + val sccGraph = StronglyConnectedComponents.run(graph, 5) + for ((id, scc) <- sccGraph.vertices.collect) { + assert(id == scc) + } + } + } + + test("Cycle Strongly Connected Components") { + withSpark(new SparkContext("local", "test")) { sc => + val rawEdges = sc.parallelize((0L to 6L).map(x => (x, (x + 1) % 7))) + val graph = Graph.fromEdgeTuples(rawEdges, -1) + val sccGraph = StronglyConnectedComponents.run(graph, 20) + for ((id, scc) <- sccGraph.vertices.collect) { + assert(0L == scc) + } + } + } + + test("2 Cycle Strongly Connected Components") { + withSpark(new SparkContext("local", "test")) { sc => + val edges = + Array(0L -> 1L, 1L -> 2L, 2L -> 0L) ++ + Array(3L -> 4L, 4L -> 5L, 5L -> 3L) ++ + Array(6L -> 0L, 5L -> 7L) + val rawEdges = sc.parallelize(edges) + val graph = Graph.fromEdgeTuples(rawEdges, -1) + val sccGraph = StronglyConnectedComponents.run(graph, 20) + for ((id, scc) <- sccGraph.vertices.collect) { + if (id < 3) + assert(0L == scc) + else if (id < 6) + assert(3L == scc) + else + assert(id == scc) + } + } + } + test("Count a single triangle") { withSpark(new SparkContext("local", "test")) { sc => val rawEdges = sc.parallelize(Array( 0L->1L, 1L->2L, 2L->0L ), 2) |