From 2ecc4f29395e9244a04b1e084bbb639dbf699a99 Mon Sep 17 00:00:00 2001 From: LizHad Date: Tue, 22 Nov 2016 17:59:12 +0200 Subject: [PATCH] Add test files. --- test/G1.txt | 11 ++++ test/G2.txt | 4 ++ test/G3.txt | 8 +++ test/TEST.java | 132 +++++++++++++++++++++++++++++++++++++++ test/oupput_test1.txt | 5 ++ test/oupput_test2.txt | 5 ++ test/test1.txt | 5 ++ test/test1_excpected.txt | 5 ++ test/test2.txt | 5 ++ test/test2_excpected.txt | 5 ++ test/test3.txt | 2 + test/test3_excpected.txt | 2 + 12 files changed, 189 insertions(+) create mode 100644 test/G1.txt create mode 100644 test/G2.txt create mode 100644 test/G3.txt create mode 100644 test/TEST.java create mode 100644 test/oupput_test1.txt create mode 100644 test/oupput_test2.txt create mode 100644 test/test1.txt create mode 100644 test/test1_excpected.txt create mode 100644 test/test2.txt create mode 100644 test/test2_excpected.txt create mode 100644 test/test3.txt create mode 100644 test/test3_excpected.txt diff --git a/test/G1.txt b/test/G1.txt new file mode 100644 index 0000000..b09fe68 --- /dev/null +++ b/test/G1.txt @@ -0,0 +1,11 @@ +6 +9 +0 3 4.1 +0 4 1.1 +0 5 3 +1 2 3 +1 4 4.2 +2 3 5.16 +2 4 2.2 +3 5 0.3 +4 5 2.2 \ No newline at end of file diff --git a/test/G2.txt b/test/G2.txt new file mode 100644 index 0000000..087e0fd --- /dev/null +++ b/test/G2.txt @@ -0,0 +1,4 @@ +3 +2 +0 1 3 +1 2 2 \ No newline at end of file diff --git a/test/G3.txt b/test/G3.txt new file mode 100644 index 0000000..b089d5d --- /dev/null +++ b/test/G3.txt @@ -0,0 +1,8 @@ +6 +6 +1 2 8 +1 0 3 +2 0 2.1 +0 4 4 +0 3 5 +3 5 6 \ No newline at end of file diff --git a/test/TEST.java b/test/TEST.java new file mode 100644 index 0000000..a87e897 --- /dev/null +++ b/test/TEST.java @@ -0,0 +1,132 @@ + +import java.io.BufferedReader; +import static org.junit.Assert.*; + +import org.junit.Test; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Arrays; + +import org.junit.Test; + +public class TEST { + + @Test + public void test_1() { + String folder="C:\\Users\\Zafrir\\Documents\\NetBeansProjects\\Graph_algo\\test\\"; + String graph = folder+"G1.txt"; + String test = folder+"test1.txt"; + String expected = folder+"test1_excpected.txt"; + String happend = folder+"oupput_test1.txt"; + + makeOutPut(graph, test, happend); + + In exp=new In(expected); + In hap = new In(happend); + + while ((hap.hasNextLine()) && (exp.hasNextLine())) { + assertEquals(hap.readLine(), exp.readLine()); + } + } + + @Test + public void test_2() { + String folder="C:\\Users\\Zafrir\\Documents\\NetBeansProjects\\Graph_algo\\test\\"; + String graph = folder+"G2.txt"; + String test = folder+"test2.txt"; + String expected = folder+"test2_excpected.txt"; + String happend = folder+"oupput_test2.txt"; + + makeOutPut(graph, test, happend); + + In exp=new In(expected); + In hap = new In(happend); + + while ((hap.hasNextLine()) && (exp.hasNextLine())) { + assertEquals(hap.readLine(), exp.readLine()); + } + } + + public void test_3() { + String folder="C:\\Users\\Zafrir\\Documents\\NetBeansProjects\\Graph_algo\\test\\"; + String graph = folder+"G3.txt"; + String test = folder+"test3.txt"; + String expected = folder+"test3_excpected.txt"; + String happend = folder+"oupput_test3.txt"; + + makeOutPut(graph, test, happend); + + In exp=new In(expected); + In hap = new In(happend); + + while ((hap.hasNextLine()) && (exp.hasNextLine())) { + assertEquals(hap.readLine(), exp.readLine()); + } + } + + + public void makeOutPut(String graphName, String testName, String outPutFile) { + + try { + File outFile = new File(outPutFile); + outFile.createNewFile(); + FileReader graphFile = new FileReader(graphName); + FileReader inputFile = new FileReader(testName); + BufferedReader graphReader = new BufferedReader(graphFile); + BufferedReader inputReader = new BufferedReader(inputFile); + PrintWriter outputWriter = new PrintWriter(outFile); + int vertex = Integer.parseInt(graphReader.readLine()); + int edges = Integer.parseInt(graphReader.readLine()); + EdgeWeightedDigraph Graph = new EdgeWeightedDigraph(vertex); + String line; + while ((line = graphReader.readLine()) != null) { + //System.out.println(line); + String splitArr[] = line.split("\t"); + DirectedEdge e = new DirectedEdge(Integer.parseInt(splitArr[0]), Integer.parseInt(splitArr[1]), Double.parseDouble(splitArr[2])); + Graph.addEdge(e); + e = new DirectedEdge(Integer.parseInt(splitArr[1]), Integer.parseInt(splitArr[0]), Double.parseDouble(splitArr[2])); + Graph.addEdge(e); + } + int numOfQ = Integer.parseInt(inputReader.readLine()); + DijkstraSP DijGraph = null; + for (int i = 0; i < numOfQ; i++) { + line = inputReader.readLine(); + String splitArr[] = line.split(","); + int from = Integer.parseInt(splitArr[0]); + int to = Integer.parseInt(splitArr[1]); + int BListLen = Integer.parseInt(splitArr[2]); + int BList[] = new int[BListLen]; + for (int j = 0; j < BListLen; j++) { + BList[j] = Integer.parseInt(splitArr[3 + j]); + } + Graph.setBL(BList); + DijGraph = new DijkstraSP(Graph, from); + double dist = DijGraph.distTo(to); + String BlistPrint = ""; + for (int j = 0; j < BListLen; j++) { + BlistPrint = BlistPrint + BList[j] + " "; + } + outputWriter.print(from + " " + to + " " + BListLen + " " + BlistPrint + dist + "\n"); + Graph.RetBL(BList); + } + String tieFlag = ""; + if (!(DijGraph.check(Graph, 0))) { + tieFlag = "!"; + } + GraphProperties graphP = new GraphProperties(Graph); + outputWriter.print("Graph: |V|=" + vertex + " |E|=" + edges + " " + tieFlag + "TIE " + " Diameter=" + graphP.diameter() + " Radius=" + graphP.radius()); + outputWriter.close(); + inputReader.close(); + graphFile.close(); + + } catch (Exception e) { + System.out.println("The file does not exist"); + } + } + +} diff --git a/test/oupput_test1.txt b/test/oupput_test1.txt new file mode 100644 index 0000000..b529b31 --- /dev/null +++ b/test/oupput_test1.txt @@ -0,0 +1,5 @@ +4 5 1 0 2.2 +2 3 0 4.7 +2 3 1 4 5.16 +3 5 2 0 1 0.3 +Graph: |V|=6 |E|=9 !TIE Diameter=2 Radius=2 \ No newline at end of file diff --git a/test/oupput_test2.txt b/test/oupput_test2.txt new file mode 100644 index 0000000..f2252d8 --- /dev/null +++ b/test/oupput_test2.txt @@ -0,0 +1,5 @@ +0 1 0 3.0 +0 2 0 5.0 +1 2 0 2.0 +2 0 0 5.0 +Graph: |V|=3 |E|=2 !TIE Diameter=2 Radius=1 \ No newline at end of file diff --git a/test/test1.txt b/test/test1.txt new file mode 100644 index 0000000..ec7feb4 --- /dev/null +++ b/test/test1.txt @@ -0,0 +1,5 @@ +4 +4,5,1,0 +2,3,0 +2,3,1,4 +3,5,2,0,1 \ No newline at end of file diff --git a/test/test1_excpected.txt b/test/test1_excpected.txt new file mode 100644 index 0000000..b529b31 --- /dev/null +++ b/test/test1_excpected.txt @@ -0,0 +1,5 @@ +4 5 1 0 2.2 +2 3 0 4.7 +2 3 1 4 5.16 +3 5 2 0 1 0.3 +Graph: |V|=6 |E|=9 !TIE Diameter=2 Radius=2 \ No newline at end of file diff --git a/test/test2.txt b/test/test2.txt new file mode 100644 index 0000000..26408b7 --- /dev/null +++ b/test/test2.txt @@ -0,0 +1,5 @@ +4 +0,1,0 +0,2,0 +1,2,0 +2,0,0 \ No newline at end of file diff --git a/test/test2_excpected.txt b/test/test2_excpected.txt new file mode 100644 index 0000000..f2252d8 --- /dev/null +++ b/test/test2_excpected.txt @@ -0,0 +1,5 @@ +0 1 0 3.0 +0 2 0 5.0 +1 2 0 2.0 +2 0 0 5.0 +Graph: |V|=3 |E|=2 !TIE Diameter=2 Radius=1 \ No newline at end of file diff --git a/test/test3.txt b/test/test3.txt new file mode 100644 index 0000000..cb7b875 --- /dev/null +++ b/test/test3.txt @@ -0,0 +1,2 @@ +1 +1,2,0 diff --git a/test/test3_excpected.txt b/test/test3_excpected.txt new file mode 100644 index 0000000..fd318f4 --- /dev/null +++ b/test/test3_excpected.txt @@ -0,0 +1,2 @@ +1 2 0 5.1 +Graph: |V|=6 |E|=6 !TIE Diameter=3 Radius=2 \ No newline at end of file