第四周WordCount优化
一、GitHub地址
https://github.com/kawoyi/Advanced-WordCounter最终由组长整合的组长github
二、psp表格

三、个人模块及实现
我负责的是输入模块,由FileUnit类里的readFile函数进行文件读取输入
public class FileUnit
{
public static void fileWriter(String outputpath,Map<String,Integer> map)throws IOException
{ //结果写到输出文件中
File file=new File(outputpath);
FileWriter fw = new FileWriter(file,false);
BufferedWriter bw = new BufferedWriter(fw);
List<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(map.entrySet());//实现按Value排序
//然后通过比较器来实现排序
Collections.sort(list,new Comparator<Map.Entry<String,Integer>>()
{
//降序排序
public int compare(Entry<String, Integer> o1,
Entry<String, Integer> o2)
{
int p1=o1.getValue();
int p2=o2.getValue();
int p=p1-p2;
if(p>0)
{
return -1;
}
else if(p==0)
{
return 0;
}
else
return 1;
}
});
for (Map.Entry<String, Integer> mapping:list)
{ //向result.txt写结果
int temp=0;
if(temp<100)
{
bw.write( mapping.getKey() + " " + mapping.getValue());
bw.newLine();
}
temp++;
}
bw.close();
}
public static void readFile(String filepath,StringBuffer buffer) //读取文件
{
try {
FileReader fis = new FileReader(filepath);
BufferedReader br = new BufferedReader(fis);
int temp=-1;
while ((temp = br.read()) != -1) {
buffer.append((char)(temp));
}
} catch (FileNotFoundException e) {
System.out.println("源文件未找到!");
e.printStackTrace();
} catch (IOException e) {
System.out.println("读写文件出现异常!");
e.printStackTrace();
}
}
}
四、测试用例设计及测试结果
测试程序对文件内容的识别分割是否正确,对各种情况下的单词进行测试,
包括纯字母单词,大写字母单词,字母和连字符组成的单词,字母和数字组成的单词,由空格分隔的单词,由符号分割的单词等等情况。
运用白盒测试的方法测试该程序是否能按照需求来识别文件标题,而对于20个测试用例来讲10个不到也足以覆盖要求,后续的文件内容采用了黑盒测试的方式偏重于考虑各类输出会出现的结果,总共20个数量较多,这里就只放出截图。

五,测试用例运行截图

由于总数过多只放出了其中一个的截图
六、小组贡献
0.25

浙公网安备 33010602011771号