Skip to content

Commit 60482b3

Browse files
committed
add ut
1 parent e407e88 commit 60482b3

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

graphx/src/test/scala/org/apache/spark/graphx/lib/PageRankSuite.scala

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,37 @@ class PageRankSuite extends SparkFunSuite with LocalSparkContext {
233233
assert(totalIters == 19)
234234
assert(iterAfterHalfCheckPoint == 18)
235235
}
236-
} // end of Grid PageRank
236+
} // end of Grid PageRank with checkpoint
237+
238+
test("Grid PageRank with checkpoint without intermediate normalization") {
239+
withSpark { sc =>
240+
// Check that 6 iterations in a row are equivalent
241+
// to 3 times 2 iterations without intermediate normalization
242+
val rows = 10
243+
val cols = 10
244+
val resetProb = 0.15
245+
val gridGraph = GraphGenerators.gridGraph(sc, rows, cols).cache()
246+
247+
val ranksA: Array[(VertexId, Double)] = PageRank.runWithOptions(
248+
gridGraph, numIter = 6, resetProb, srcId = None, normalized = true
249+
).vertices.collect()
250+
251+
val preRankGraph1 = PageRank.runWithOptions(
252+
gridGraph, numIter = 2, resetProb, srcId = None, normalized = false
253+
)
254+
255+
val preRankGraph2 = PageRank.runWithOptionsWithPreviousPageRank(
256+
gridGraph, numIter = 2, resetProb, srcId = None, normalized = false, preRankGraph1
257+
)
258+
259+
val ranksB: Array[(VertexId, Double)] = PageRank.runWithOptionsWithPreviousPageRank(
260+
gridGraph, numIter = 2, resetProb, srcId = None, normalized = true, preRankGraph2
261+
).vertices.collect()
262+
263+
// assert that all scores are equal
264+
assert(ranksA.zip(ranksB).forall{ case(rankA, rankB) => rankA == rankB })
265+
}
266+
} // end of Grid PageRank with checkpoint without intermediate normalization
237267

238268
test("Chain PageRank") {
239269
withSpark { sc =>

0 commit comments

Comments
 (0)