Last active
August 29, 2015 14:19
-
-
Save goatandsheep/d5e1959fffe0452210c2 to your computer and use it in GitHub Desktop.
Compare 3 different input files with 3 different output files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
import org.junit.*; | |
import static org.junit.Assert.*; | |
import java.io.*; | |
/** | |
* | |
* @author user | |
*/ | |
public class ShortestPathTest { | |
InputStream stdin; | |
PrintStream stdout; | |
PrintStream stderr; | |
public ShortestPathTest() { | |
} | |
@BeforeClass | |
public static void setUpClass() { | |
} | |
@AfterClass | |
public static void tearDownClass() { | |
} | |
@Before | |
public void setUp() { | |
stdin = System.in; //temporarily saving these so that I can revert back to these at the end of each file | |
stdout = System.out; | |
} | |
@After | |
public void tearDown() { | |
System.setIn(stdin); | |
System.setOut(stdout); | |
} | |
/** | |
* Test of main method, of class ShortestPath. | |
*/ | |
@Test | |
public void testMain1() throws IOException | |
{ | |
System.out.println("main1"); | |
System.setIn(new FileInputStream("input1.txt")); | |
File newout = new File("output.txt"); | |
FileOutputStream outnew = new FileOutputStream(newout); | |
PrintStream outcontent = new PrintStream(outnew); | |
System.setOut(outcontent); | |
File oldout = new File("output1.txt"); | |
//FileInputStream outread = new FileInputStream(oldout); | |
BufferedReader outread = new BufferedReader(new FileReader(oldout)); | |
String[] args = null; | |
ShortestPath.main(args); | |
outnew.close(); | |
BufferedReader newread = new BufferedReader(new FileReader(newout)); | |
String temp1; | |
String temp2; | |
do{ | |
temp1 = newread.readLine(); | |
temp2 = outread.readLine(); | |
assertEquals(temp1, temp2); | |
}while((temp1 != null) && (temp2 != null)); | |
newread.close(); | |
// TODO review the generated test code and remove the default call to fail. | |
//fail("The test case is a prototype."); | |
} | |
/** | |
* Test of main method, of class ShortestPath. | |
*/ | |
@Test | |
public void testMain2() throws IOException | |
{ | |
System.out.println("main2"); | |
System.setIn(new FileInputStream("input2.txt")); | |
File newout = new File("output.txt"); | |
FileOutputStream outnew = new FileOutputStream(newout); | |
PrintStream outcontent = new PrintStream(outnew); | |
System.setOut(outcontent); | |
File oldout = new File("output2.txt"); | |
//FileInputStream outread = new FileInputStream(oldout); | |
BufferedReader outread = new BufferedReader(new FileReader(oldout)); | |
String[] args = null; | |
ShortestPath.main(args); | |
outnew.close(); | |
BufferedReader newread = new BufferedReader(new FileReader(newout)); | |
String temp1; | |
String temp2; | |
do{ | |
temp1 = newread.readLine(); | |
temp2 = outread.readLine(); | |
assertEquals(temp1, temp2); | |
}while((temp1 != null) && (temp2 != null)); | |
newread.close(); | |
// TODO review the generated test code and remove the default call to fail. | |
//fail("The test case is a prototype."); | |
} | |
/** | |
* Test of main method, of class ShortestPath. | |
*/ | |
@Test | |
public void testMain3() throws IOException | |
{ | |
System.out.println("main3"); | |
System.setIn(new FileInputStream("input3.txt")); | |
File newout = new File("output.txt"); | |
FileOutputStream outnew = new FileOutputStream(newout); | |
PrintStream outcontent = new PrintStream(outnew); | |
System.setOut(outcontent); | |
File oldout = new File("output3.txt"); | |
//FileInputStream outread = new FileInputStream(oldout); | |
BufferedReader outread = new BufferedReader(new FileReader(oldout)); | |
String[] args = null; | |
ShortestPath.main(args); | |
outnew.close(); | |
BufferedReader newread = new BufferedReader(new FileReader(newout)); | |
String temp1; | |
String temp2; | |
do{ | |
temp1 = newread.readLine(); | |
temp2 = outread.readLine(); | |
assertEquals(temp1, temp2); | |
}while((temp1 != null) && (temp2 != null)); | |
newread.close(); | |
// TODO review the generated test code and remove the default call to fail. | |
//fail("The test case is a prototype."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment