You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by va...@apache.org on 2015/03/04 21:33:06 UTC
[4/7] flink git commit: [FLINK-1522][FLINK-1576][gelly] Added more
test cases for Label Propagation
[FLINK-1522][FLINK-1576][gelly] Added more test cases for Label Propagation
This closes #441
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/b529b62a
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/b529b62a
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/b529b62a
Branch: refs/heads/master
Commit: b529b62a4f2e4b7482564ad6c65996c8f5b0d824
Parents: e306c62
Author: balidani <ba...@gmail.com>
Authored: Tue Mar 3 18:58:59 2015 +0100
Committer: Vasia Kalavri <va...@apache.org>
Committed: Wed Mar 4 21:30:58 2015 +0100
----------------------------------------------------------------------
.../test/LabelPropagationExampleITCase.java | 145 ++++++++++++++-----
1 file changed, 112 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/b529b62a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/LabelPropagationExampleITCase.java
----------------------------------------------------------------------
diff --git a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/LabelPropagationExampleITCase.java b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/LabelPropagationExampleITCase.java
index d5b2239..dfb0f3f 100755
--- a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/LabelPropagationExampleITCase.java
+++ b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/LabelPropagationExampleITCase.java
@@ -42,56 +42,135 @@ public class LabelPropagationExampleITCase extends MultipleProgramsTestBase {
private String resultPath;
private String expectedResult;
- private String verticesPath;
- private String edgesPath;
-
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
@Before
public void before() throws Exception{
resultPath = tempFolder.newFile().toURI().toString();
+ }
- final String vertices = "1 1\n" +
- "2 2\n" +
- "3 3\n" +
- "4 4\n" +
- "5 5\n";
-
- final String edges = "1 2\n" +
- "1 3\n" +
- "2 3\n" +
- "3 4\n" +
- "3 5\n" +
- "4 5\n" +
- "5 1\n";
+ @After
+ public void after() throws Exception{
+ compareResultsByLinesInMemory(expectedResult, resultPath);
+ }
- File verticesFile = tempFolder.newFile();
- Files.write(vertices, verticesFile, Charsets.UTF_8);
+ @Test
+ public void testSingleIteration() throws Exception {
+ /*
+ * Test one iteration of label propagation example with a simple graph
+ */
- File edgesFile = tempFolder.newFile();
- Files.write(edges, edgesFile, Charsets.UTF_8);
+ final String vertices = "1 10\n" +
+ "2 10\n" +
+ "3 30\n" +
+ "4 40\n" +
+ "5 40\n" +
+ "6 40\n" +
+ "7 70\n";
- verticesPath = verticesFile.toURI().toString();
- edgesPath = edgesFile.toURI().toString();
+ final String edges = "1 3\n" +
+ "2 3\n" +
+ "4 7\n" +
+ "5 7\n" +
+ "6 7\n" +
+ "7 3\n";
+
+ String verticesPath = createTempFile(vertices);
+ String edgesPath = createTempFile(edges);
+
+ LabelPropagationExample.main(new String[] {verticesPath, edgesPath, resultPath, "7", "1"});
+
+ expectedResult = "1,10\n" +
+ "2,10\n" +
+ "3,10\n" +
+ "4,40\n" +
+ "5,40\n" +
+ "6,40\n" +
+ "7,40\n";
}
- @After
- public void after() throws Exception{
- compareResultsByLinesInMemory(expectedResult, resultPath);
+ @Test
+ public void testTieBreaker() throws Exception {
+ /*
+ * Test the label propagation example where a tie must be broken
+ */
+
+ final String vertices = "1 10\n" +
+ "2 10\n" +
+ "3 10\n" +
+ "4 10\n" +
+ "5 0\n" +
+ "6 20\n" +
+ "7 20\n" +
+ "8 20\n" +
+ "9 20\n";
+
+ final String edges = "1 5\n" +
+ "2 5\n" +
+ "3 5\n" +
+ "4 5\n" +
+ "6 5\n" +
+ "7 5\n" +
+ "8 5\n" +
+ "9 5\n";
+
+ String verticesPath = createTempFile(vertices);
+ String edgesPath = createTempFile(edges);
+
+ LabelPropagationExample.main(new String[] {verticesPath, edgesPath, resultPath, "9", "1"});
+
+ expectedResult = "1,10\n" +
+ "2,10\n" +
+ "3,10\n" +
+ "4,10\n" +
+ "5,20\n" +
+ "6,20\n" +
+ "7,20\n" +
+ "8,20\n" +
+ "9,20\n";
}
@Test
- public void testLabelPropagation() throws Exception {
+ public void testTermination() throws Exception {
/*
- * Test the label propagation example
+ * Test the label propagation example where the algorithm terminates on the first iteration
*/
- LabelPropagationExample.main(new String[] {verticesPath, edgesPath, resultPath, "5", "16"});
- expectedResult = "1,5\n" +
- "2,5\n" +
- "3,5\n" +
- "4,5\n" +
- "5,5\n";
+ final String vertices = "1 10\n" +
+ "2 10\n" +
+ "3 10\n" +
+ "4 40\n" +
+ "5 40\n" +
+ "6 40\n";
+
+ final String edges = "1 2\n" +
+ "2 3\n" +
+ "3 1\n" +
+ "4 5\n" +
+ "5 6\n" +
+ "6 4\n";
+
+ String verticesPath = createTempFile(vertices);
+ String edgesPath = createTempFile(edges);
+
+ LabelPropagationExample.main(new String[]{verticesPath, edgesPath, resultPath, "6", "2"});
+
+ expectedResult = "1,10\n" +
+ "2,10\n" +
+ "3,10\n" +
+ "4,40\n" +
+ "5,40\n" +
+ "6,40\n";
+ }
+
+ // -------------------------------------------------------------------------
+ // Util methods
+ // -------------------------------------------------------------------------
+
+ private String createTempFile(final String rows) throws Exception {
+ File tempFile = tempFolder.newFile();
+ Files.write(rows, tempFile, Charsets.UTF_8);
+ return tempFile.toURI().toString();
}
}