个人第2次作业:熟悉使用工具

GIT地址 https://github.com/saodan
GIT用户名 saodan
学号后五位 32125
博客地址 个人博客
作业链接 作业链接

一、配置环境

1.VS2013安装与配置

2.GIT安装与配置

二、克隆项目

1.登录我的github主页

2.进入阿超仓库的网址,点击右上角的 Fork ,将阿超的四则运算库拷贝到自己的同名仓库中

3.将项目克隆到电脑文件夹(F:\软工作业)

三、设计随机数四则运算项目

1.设计思路:

随机数生成:
设计思路:利用random生成随机数,并用数字1、2、3、4代替运算符:+、-*、/。

    int seed = Guid.NewGuid().GetHashCode();//随机数种子
    Random random = new Random(seed);
    List<int> fh=new List<int>();
    List<int> list=new List<int>();
    for (int i = 0; i < len;)
        {
            int fh_len1 = random.Next(2,4);//fh_len1:题目的符号数量
            for (int j = 0; j < fh_len1; j++)
                {
                    int h = random.Next(1, 5);
                    fh.Insert(j, h);//随机生成运算符
                }
                for (int j = 0; j < fh_len1 + 1; j++)
                {
                    int h = random.Next(0, 101);
                    list.Insert(j, h);//生成随机数
                }
        }

除数是否为0的判断:
设计思路:利用字典索引,将数字还原成运算符,再判断除号下一位是否为0


public bool test_ce(List<int> fh, List<int> list)
    {
        int j = 0;
        Dictionary<int, string> hash = new Dictionary<int, string> { { 1, "+" }, { 2, "-" }, { 3, "*" }, { 4, "/" } };
        foreach (int i in fh)
        {
            if (hash[i] != "/")
            {
                j++;
                continue;
            }
            else
            {
                if (list[j + 1] != 0)
                    return true;
                    else
                    return false;
                }
            }
            return true;
        }

四则运算:

Dictionary<int, string> hash = new Dictionary<int, string> { { 1, "+" }, { 2, "-" }, { 3, "*" }, { 4, "/" } };
int len = fh.Count();
string ji=null;
/*组装运算式*/
for(int i=0,j=0;i<len;)
{
    if (j < fh.Count())
    {
        ji += list[i] + hash[fh[j]];
        j++;
    }
    else
    {
        ji += list[i];
        i++;
    }
    i++;
}
ji += list[len];
/*利用datatable().Compute进行四则运算*/
var r = new DataTable().Compute(ji, null);
int num;
if (int.TryParse(r.ToString(),out num))//判断计算结果是否为整数
{
    str = ji + "=" + r.ToString()+"\n";
    Console.Write(str);
    t = true;//判断成功生成一个运算式
}

运行结果写入txt

string path = @"F:/四则运算.txt";
File.WriteAllText(path, "");//清空文本
...
File.AppendAllText(path, str);

运行结果:

2.代码提交

操作指南:如何使用git把本地代码上传(更新)到github上

四、单元测试

随机数项目的编码是在VS2013中完成的,但在进行单元测试时发现,我安装的vs版本很难进行单元测试,所以就卸载了vs2013重新安装了vs2017进行单元测试。

  • 测试一:测试除数为0判断模块

  • 测试二:测试小数判断模块
  • 测试三: 计算值模块测试,测试前,我先将计算值结果变量"r”改为public类型。

五、回归测试

六、效能工具

运行效能工具前,修改Program类:

```c class Program { static void Main(string[] args) { //int len = int.Parse(Console.ReadLine()); Sui s = new Sui(/*len*/100000);//生成100000个运算式 } } ```

七、提交代码到Github

八、存在的问题及感想体会

  • 英语水平差,很难读懂github的英文资料;在项目编码时,很多的变量都采用的汉语拼音式的编码;同时还不能熟练运用单元测试。像github中很多的资料是英文资料,所以提高英语水平对使用github,vs等项目工具很有帮助。
posted @ 2019-09-17 13:00  廖志丹  阅读(952)  评论(1编辑  收藏  举报