Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test files. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/G1.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/G2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3
2
0 1 3
1 2 2
8 changes: 8 additions & 0 deletions test/G3.txt
Original file line number Diff line number Diff line change
@@ -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
132 changes: 132 additions & 0 deletions test/TEST.java
Original file line number Diff line number Diff line change
@@ -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");
}
}

}
5 changes: 5 additions & 0 deletions test/oupput_test1.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/oupput_test2.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
4
4,5,1,0
2,3,0
2,3,1,4
3,5,2,0,1
5 changes: 5 additions & 0 deletions test/test1_excpected.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/test2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
4
0,1,0
0,2,0
1,2,0
2,0,0
5 changes: 5 additions & 0 deletions test/test2_excpected.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/test3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
1,2,0
2 changes: 2 additions & 0 deletions test/test3_excpected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 2 0 5.1
Graph: |V|=6 |E|=6 !TIE Diameter=3 Radius=2