一、配置环境
- VS2015配置
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190917182607629.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
- GIT安装与配置
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190917184641679.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
二、复制项目
- 登录git
- 进入阿超仓库,点击右上角的 Fork ,将阿超的四则运算库拷贝到自己的同名仓库中
![在这里插入图片描述](https://img-blog.csdnimg.cn/2019091718554920.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190917185736453.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
- 将项目复制到本地
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190917190402657.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
- 进入项目文件夹,新建一个文件夹
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190917190711274.png)
三、完成随机四则运算项目
public struct data//结构体
{
public int x, y, z;//分别代表3个运算数
public int a1, a2;//分别代表2个运算符
public int sum;//代表运算结果
}
public static char choice1(int a)//选择运算符号
{
if (a == 1)
return '+';
else if (a == 2)
return '-';
else if (a == 3)
return '*';
else
return '/';
}
public static int choice2(int x, int y, int z)//运算过程,这里x,z表示运算数字,y表示运算符号
{
if (y == 1)
return x + z;
else if (y == 2)
return x - z;
else if (y == 3)
return x * z;
else if (y == 4 && z > 0)
return x / z;
else
return x + z;
}
public static int Sum(int x,int y,int z,int a1,int a2 )//运算优先级选择
{
if (a1 <= 2 || a2 > 2)
return choice2(x, a1, choice2(y, a2, z));
else
return choice2(choice2(x, a1, y), a2, z);
}
public bool judge(List<data> data, data k)//判断算式是否符合要求
{
for (int i = 0; i < data.Count; i++)//判断是否重复
if (data[i].x == k.x && data[i].y == k.y && data[i].z == k.z && data[i].a1 == k.a1 && data[i].a2 == k.a2)
return false;
if ((Sum(k.x,k.y,k.z,k.a1,k.a2) % 1) != 0)//判断是否为小数
return false;
if (Sum(k.x, k.y, k.z, k.a1, k.a2) < 0)//判断是否为负数
return false;
return true;
}
public string run1(int n)//随机生成算式
{
string strList = "";
List<data> data = new List<data>();
for (int i = 0; i < n; i++)
{
Random r = new Random();
while (true)
{
data m = new data();
m.x = r.Next(1, 101);
m.a1 = r.Next(1, 5);
m.y = r.Next(1, 101);
m.a2 = r.Next(1, 5);
m.z = r.Next(1, 101);
if (judge(data, m))
{
m.sum = Sum(m.x, m.y, m.z, m.a1, m.a2);
data.Add(m);
break;
}
}
}
for (int i = 0; i < n; i++)
{
strList = strList + data[i].x + "" + choice1(data[i].a1) + "" + data[i].y + "" + choice1(data[i].a2) + "" + data[i].z + "=" + data[i].sum + "\n";
}
return strList;
}
public void run2(string msg)//打印到txt文件
{
string path = @"D:\随机四则运算.txt";
System.IO.StreamWriter sw = new System.IO.StreamWriter(path);
sw.WriteLine(msg);
sw.Flush();
sw.Close();
}
- 结果截图
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919150421939.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919150530735.png)
四、单元测试
- 新建测试项目
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919151304243.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919151419791.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
- 添加引用
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919151625853.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
- 单元测试代码及结果
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919165501334.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
五、效能工具
- 选择CPU使用率
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919171134732.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
- 完整的效能分析报告
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919171328835.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
![详细报告](https://img-blog.csdnimg.cn/2019091917152016.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
- 每行代码占用 CPU 的时间比例
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919171805540.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
六、提交代码
- 配置自己的个人邮箱与 Commit 时的用户名
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919172821841.png)
- 用 Git 记录下所有的改动
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919173854327.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
- 确保所有本地的改动都已经 add 并 commit 了
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919174551869.png)
- push
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919174800496.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919174915601.png)
- 在完成 push 后,向源仓库发起 Pull Request。打开你Fork 后的项目主页点击按钮 New pull request,成功提交代码。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190919175250568.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3plcm93Y2w=,size_16,color_FFFFFF,t_70)
## 七、存在的问题及感想体会
- 在进行代码设计时没有思路,只知道用随机数,最后去网上看了很多其他人的代码,然后才慢慢写出代码。在单元测试环节,我的测试怎么都不通过,后来我把原本的代码进行了很多修改才最终完成。后面也学习了一些github的基础操作,还有单元测试,对编码很有帮助。