Ai
1 Star 0 Fork 0

20175211/java_work

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
MyCPTest.java 2.62 KB
Copy Edit Raw Blame History
20175211 authored 2019-04-29 01:58 +08:00 . 完成MyCP及测试
import org.junit.Before;
import org.junit.Test;
import java.io.*;
import java.util.Scanner;
import static org.junit.Assert.*;
public class MyCPTest {
private boolean testSameFile(String[] args) throws Exception {
FileInputStream File1 = new FileInputStream(args[0]);
FileInputStream File2 = new FileInputStream(args[1]);
boolean flag;
if (File1.available() != File2.available()) {
//长度不同内容肯定不同
flag = false;
} else {
while (File1.read() != -1 && File2.read() != -1) {
if (File1.read() != File2.read()) {
flag = false;
}
}
flag = true;
}
File1.close();
File2.close();
return flag;
}
@Before
public void init(){
File file = new File("1.txt");
File numFile = new File("number.txt");
File binaryFile = new File("binary.bin");
try{
file.createNewFile();
numFile.createNewFile();
binaryFile.createNewFile();
FileOutputStream output = new FileOutputStream(file);
output.write("MyCP works perfectly!!".getBytes());
output = new FileOutputStream(numFile);
output.write("10 a 9".getBytes());
output = new FileOutputStream(binaryFile);
output.write("1111 10 1001".getBytes());
}catch (Exception e){
System.out.println(e.getMessage());
}
}
@Test
public void testNoOpt() {
String[] args1 = {"1.txt", "2.txt"};
String[] args2 = {"1.txt", "src"};
MyCP.main(args1);
MyCP.main(args2);
try{
assertTrue(testSameFile(args1));
args2[1]="src/1.txt";
assertTrue(testSameFile(args2));
}catch (Exception e){
System.out.println(e.getMessage());
fail();
}
}
@Test
public void testTX(){
String[] args = {"-tx","number.txt","2.bin"};
MyCP.main(args);
try{
FileInputStream bin = new FileInputStream("2.bin");
Scanner sc = new Scanner(bin);
assertEquals(sc.nextLine(),"1010 1001 ");
}catch (Exception e){
fail();
}
}
@Test
public void testXT(){
String[] args = {"-xt","binary.bin","decimal.txt"};
MyCP.main(args);
try{
FileInputStream bin = new FileInputStream("decimal.txt");
Scanner sc = new Scanner(bin);
assertEquals(sc.nextLine(),"15 2 9 ");
}catch (Exception e){
fail();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/imjoking/java_work.git
git@gitee.com:imjoking/java_work.git
imjoking
java_work
java_work
master

Search