个人项目:论文查重
个人项目:论文查重
| 这个作业属于哪个课程 | https://edu.cnblogs.com/campus/gdgy/Networkengineering1834 |
|---|---|
| 这个作业要求在哪里 | https://edu.cnblogs.com/campus/gdgy/Networkengineering1834/homework/11146 |
| 这个作业的目标 | 练习使用PSP表格,实现论文查重算法,学习如何单元测试,学习使用性能分析工具 |
一、GitHub地址
https://github.com/huilinho/3118005324
二、PSP表格
| PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
|---|---|---|---|
| Planning | 计划 | 60 | 90 |
| · Estimate | · 估计这个任务需要多少时间 | 60 | 30 |
| Development | 开发 | 300 | 480 |
| · Analysis | · 需求分析 (包括学习新技术) | 60 | 90 |
| · Design Spec | · 生成设计文档 | 30 | 50 |
| · Design Review | · 设计复审 | 30 | 50 |
| · Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 60 | 60 |
| · Design | · 具体设计 | 60 | 60 |
| · Coding | · 具体编码 | 240 | 320 |
| · Code Review | · 代码复审 | 40 | 80 |
| · Test | · 测试(自我测试,修改代码,提交修改) | 60 | 90 |
| Reporting | 报告 | 60 | 60 |
| · Test Repor | · 测试报告 | 30 | 30 |
| · Size Measurement | · 计算工作量 | 20 | 30 |
| · Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 30 | 40 |
| · 合计 | 1140 | 1560 |
三、模块接口的设计与实现过程
1.算法原理
参考文章:https://blog.csdn.net/baodream/article/details/80417695
最小编辑距离指的是字符串A转化为字符串B的最小编辑次数,允许的操作有插入,删除,替换。
1.先来说一下插入删除操作,比如有hello,helo俩个字符串,前一个字符串减去一个l和后一个加上一个l,其实是没有区别的。那么把这个操作统称为对一个字符串的删除就好了。
2.再来说一下替换操作,helo和halo,将e替换成a或者将a替换成e,其实都是没区别的。
下面的图片就是具体的运算过程,最终结果就是最后一行最后一列元素对应的值

2.程序流程
程序流程图

程序结果

3.相关接口和类
代码结构如下

(1).文件写入写出接口

(2).文件预处理工具类

(3).最短距离编辑算法类ED

其中关键部分是动态规划来找出最小编辑距离,此处采用了滚动数组,能够减少程序内存开支。

四、测试
1.首先测试5个正常的测试文件
package com.test;
import com.code.ED;
import com.code.FileProcessor;
import com.exception.FileException;
import org.testng.annotations.Test;
import java.io.IOException;
/**
* @author huilin
* @version 1.0
* @date 2020/9/23 15:42
*/
public class testTexts {
String origFilePath = "src/resources/orig.txt";
String ansFilePath = "src/resources/ans.txt";
//测试全部文件
@Test
public void testAll() throws IOException, FileException {
String[] filePaths = new String[]{
"src/resources/orig_0.8_add.txt",
"src/resources/orig_0.8_del.txt",
"src/resources/orig_0.8_dis_1.txt",
"src/resources/orig_0.8_dis_10.txt",
"src/resources/orig_0.8_dis_15.txt",
};
for (String file : filePaths) {
double result = ED.getResult(origFilePath,file);
System.out.println(file +"与原文件重复率为"+result);
FileProcessor.stringToFile(result,ansFilePath);
}
}
//测试add文件
@Test
public void testAdd() throws IOException,FileException {
String fileName = "src/resources/orig_0.8_add.txt";
double result = ED.getResult(origFilePath,fileName);
System.out.println(fileName +"与原文件重复率为"+result);
FileProcessor.stringToFile(result,ansFilePath);
}
//测试del文件
@Test
public void testDelete() throws IOException,FileException {
String fileName = "src/resources/orig_0.8_del.txt";
double result = ED.getResult(origFilePath,fileName );
System.out.println(fileName +"与原文件重复率为"+result);
FileProcessor.stringToFile(result,ansFilePath);
}
//测试dis1文件
@Test
public void testDis1() throws IOException,FileException {
String fileName = "src/resources/orig_0.8_dis_1.txt";
double result = ED.getResult(origFilePath,fileName );
System.out.println(fileName +"与原文件重复率为"+result);
FileProcessor.stringToFile(result,ansFilePath);
}
//测试dis10文件
@Test
public void testDis10() throws IOException,FileException {
String fileName = "src/resources/orig_0.8_dis_10.txt";
double result = ED.getResult(origFilePath,fileName );
System.out.println(fileName +"与原文件重复率为"+result);
FileProcessor.stringToFile(result,ansFilePath);
}
//测试dis15文件
@Test
public void testDis15() throws IOException,FileException {
String fileName = "src/resources/orig_0.8_dis_15.txt";
double result = ED.getResult(origFilePath,fileName );
System.out.println(fileName +"与原文件重复率为"+result);
FileProcessor.stringToFile(result,ansFilePath);
}
}
测试结果如下

平均0.5秒以内就可以完成一个文件的测试,测试速度较快
2.接下来测试异常处理的结果
异常处理定义类
package com.exception;
/**
* @author huilin
* @version 1.0
* @date 2020/9/21 14:27
*/
public class FileException extends Exception {
public FileException(String message){
super(message);
}
}
测试异常情况的代码
package com.test;
import com.code.ED;
import com.exception.FileException;
import org.testng.annotations.Test;
import java.io.IOException;
/**
* @author huilin
* @version 1.0
* @date 2020/9/23 20:12
*/
//测试异常处理
public class testException {
String origFilePath = "";
@Test
public void TestNull() throws IOException, FileException {
double result = ED.getResult(" "," " ); //传入两个空文件名进去
System.out.println(result);
}
@Test
public void Test() throws IOException, FileException {
double result = ED.getResult("D:/tests/empty1.txt","D:/tests/empty2.txt" ); //传入空文件进去
System.out.println(result);
}
}
测试结果如下

可以看出无论是传入空的文件路径,或者传入没有内容的文件,都会有相应的异常提醒。
3.单元测试代码的覆盖率


五、JProfiler分析性能
内存、CPU、GC、类、线程情况

LiveMemory情况

主要是char[]数组和StringBuilder类占用内存较多,因为这两个都是用于处理文本每一行的数据。
浙公网安备 33010602011771号