Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Commit

Permalink
New tests and fixes for bugs related. Fixes issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
matnel committed Aug 6, 2012
1 parent ddc4083 commit d04a440
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/io/DataReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public static Graph readFile(File f) throws Exception {

double w = Double.parseDouble(split[2]);

start.linkTo(end, w);
if( start.linkTo(end, w) ) {
throw new Exception("Tie alrady exists");
}
}

Graph g = new Graph();
Expand Down
36 changes: 24 additions & 12 deletions src/test/DataReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;

import io.DataReader;

Expand Down Expand Up @@ -41,28 +42,39 @@ public void testReadEmpty() throws Exception {
assertArrayEquals("Empty file should return correct object", result, g.matrix() );
}

@Test(expected=Exception.class)
public void testReadNegativeValue() throws Exception {
String test = "a:b:-1";
Graph g = DataReader.readFile( createFile(test) );
}


@Test
public void testValidFile() throws Exception {

String test = "a:b:10" + br + "a:c:100" + br + "b:a:5";
String test = "b:a:5" + br + "a:b:10" + br + "a:c:100";

Graph g = DataReader.readFile( createFile(test) );

double[][] result = { {0,10,100}, {5,0,-1}, {-1,-1,0} };
assertArrayEquals("Matrix not generated correctly", result, g.matrix() );
assertEquals("Item has incorrect name", "b", g.edges().get(0).name() );
assertEquals("Item has incorrect name", "c", g.edges().get(1).name() );
assertEquals("Item has incorrect name", "a", g.edges().get(2).name() );

assertEquals("Item has incorrect name", "a", g.edges().get(0).name() );
assertEquals("Item has incorrect name", "b", g.edges().get(1).name() );
assertEquals("Item has incorrect name", "c", g.edges().get(2).name() );
double[][] result = { {0,-1,5}, {-1,0,-1}, {10,100,0} };
assertArrayEquals("Matrix not generated correctly", result, g.matrix() );
}

@Test(expected=Exception.class)
public void testInvalid1() throws Exception {
String test = "a:b:c";
Graph g = DataReader.readFile( createFile(test) );
}

@Test(expected=Exception.class)
public void testInvalid2() throws Exception {
String test = "a:b:-1";
Graph g = DataReader.readFile( createFile(test) );
}

@Test(expected=Exception.class)
public void testInvalid3() throws Exception {
String test = "a:b:1" + br + "a:b:2";
Graph g = DataReader.readFile( createFile(test) );
}


}

0 comments on commit d04a440

Please sign in to comment.