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

GIT地址 个人地址
GIT用户名 qwe-qwe-369
学号后五位 24126
博客地址 个人博客地址
作业链接 作业链接

操作步骤

1.安装软件

安装成功效果图

2.克隆项目

克隆成功效果图
克隆项目

3.编写代码

首先,这次作业对我来说非常困难,它需要调用的知识很多,不过,等慢慢了解琢磨了这道题的需求之后,我的脑子里大概有了一条解决路径:解题思路
这样之后,只需要一步步解决小问题就可以了。

3.1代码展示

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace 个人作业2
{
    class Cal
    {
        public void Calculator(int n)
        {
            bool test = false;
            Random r = new Random();
            int op = r.Next(2, 4);//符号数
            List<int> l = new List<int>();
            List<int> f = new List<int>();
            for (int li = 0; li < n;)
            {
                for (int i = 0; i < op; i++)
                {
                    f.Add(r.Next(1, 5));//随机运算符

                }
                for (int i = 0; i <= op; i++)
                {
                    l.Add(r.Next(0, 100));//随机数范围
                }
                Dictionary<int, string> h = new Dictionary<int, string> { { 1, "+" }, { 2, "-" }, { 3, "*" }, { 4, "/" } };
                for (int i = 0; i < f.Count(); i++)//判断除数是否=0
                {
                    if (h[f[i]] == "/" && l[i] == 0)
                        test = false;
                    else
                        test = true;
                }
                string str = "";
                for (int i = 0; i < f.Count;)
                {
                    if (i == 0)
                    {
                        str = l[i].ToString() + h[f[i]].ToString() + l[i + 1].ToString();
                        i += 1;
                    }
                    else
                    {
                        str += h[f[i]].ToString() + l[i + 1].ToString();
                        i += 1;
                    }

                }//生成运算式
                if (test)
                {
                    test = false;
                    DataTable table = new DataTable();
                    var re = table.Compute(str, null);
                    int s;
                    if (int.TryParse(re.ToString(), out s))//判断结果是否为小数
                    {
                        Console.WriteLine(str + "=" + re.ToString());
                        test = true;
                    }
                }
                if (test == true)
                    li++;
                l.Clear();
                f.Clear();
            }

        }
        static void Main(string[] args)
        {
            Console.Write("请输入四则运算题目个数:");
            int n = Convert.ToInt32(Console.ReadLine());
            Cal c = new Cal();
            c.Calculator(n);
        }


    }
}

4.单元测试

4.1新建单元测试项目

新建单元测试项目

4.2添加引用

在这里插入图片描述

4.3通过单元测试

单元测试通过

5.运用断点检查错误

断点监视
查询中

6.回归测试

再次运行代码,是否出错
回归测试

7.效能工具

9个运算式时:
9运算式
3000运算式时:
3000运算式
详细报告

8.提交代码

提交文件
提交截图
提交成功

9.课后反思

这次作业耗时巨大,充分表示了自己的编程能力多么薄弱,很多代码都是查看他人的代码,思考他的思路,然后解决问题。虽然这次作业花费了不少时间,不过在此之中也摸索了如何把问题拆分变小,逐一攻破。

posted @ 2019-09-20 12:31  张微玖qwer  阅读(226)  评论(1编辑  收藏  举报