第一次个人编程作业
| 这个作业属于哪个课程 | 软工2班 |
|---|---|
| 这个作业要求在哪里 | 个人项目 |
| 这个作业的目标 | 设计一个算法,计算原文和抄袭版论文之间的重复率,并将结果输出到指定文件。 |
github链接:github
PSP表格
| PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
|---|---|---|---|
| Planning | 计划 | 30 | 30 |
| · Estimate | · 估计这个任务需要多少时间 | 890 | 915 |
| Development | 开发 | 300 | 300 |
| · Analysis | · 需求分析 (包括学习新技术) | 120 | 130 |
| · Design Spec | · 生成设计文档 | 30 | 30 |
| · Design Review | · 设计复审 | 30 | 30 |
| · Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 15 | 20 |
| · Design | · 具体设计 | 60 | 60 |
| · Coding | · 具体编码 | 150 | 155 |
| · Code Review | · 代码复审 | 20 | 30 |
| · Test | · 测试(自我测试,修改代码,提交修改) | 30 | 35 |
| Reporting | 报告 | 30 | 30 |
| · Test Repor | · 测试报告 | 30 | 25 |
| · Size Measurement | · 计算工作量 | 30 | 25 |
| · Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 15 | 15 |
| · 合计 | 890 | 915 |
经过Code Quality Analysis工具的分析并消除所有的警告

性能分析

单元测试
#include <gtest/gtest.h>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
// 假设这些函数已经在main.cpp中定义
int longestCommonSubsequence(const std::string& str1, const std::string& str2);
double calculateSimilarity(const std::string& original, const std::string& plagiarized);
std::string readFile(const std::string& filePath);
// 测试longestCommonSubsequence函数
TEST(TextAnalysisTest, LongestCommonSubsequence) {
std::string str1 = "abcde";
std::string str2 = "ace";
int result = longestCommonSubsequence(str1, str2);
EXPECT_EQ(result, 3);
}
// 测试calculateSimilarity函数
TEST(TextAnalysisTest, CalculateSimilarity) {
std::string original = "abcde";
std::string plagiarized = "ace";
double result = calculateSimilarity(original, plagiarized);
EXPECT_DOUBLE_EQ(result, 0.6);
}
// 测试readFile函数
TEST(TextAnalysisTest, ReadFile) {
std::string filePath = "test.txt";
std::ofstream file(filePath);
file << "Hello, World!";
file.close();
std::string content = readFile(filePath);
EXPECT_EQ(content, "Hello, World!");
}
// 更多测试用例...
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
异常处理
文件打开失败:当尝试打开文件时,如果文件不存在或没有权限访问,抛出std::runtime_error异常。
命令行参数错误:当命令行参数数量不正确时,输出错误信息并退出程序。
浙公网安备 33010602011771号