# 结对编程之单元测试 201421123108 王坤彬

coding地址：https://coding.net/u/linzhao/p/UnitTest/git

1.整数加减乘除的测试；

2.分数加减乘除的测试；

3.最大公约数测试；

4.判断真分数测试；

public int gcd(int a, int b)//公约数

        {
            if (a == 0)
            {
                return b;
            }
           else if (b == 0)
            {
                return a;
            }
            else
            {
                return gcd(b % a, a);
            }
        }
        public int Calculate(int type, int op1, int op2)//整数四则运算
        {
            int result = 0;
            if (type == 1)
            {
                result = op1 + op2;
            }
            if (type == 2)
            {
                result = op1 - op2;
            }
            if (type == 3)
            {
                result = op1 * op2;
            }
            if (type == 4)
            {
                result = op1 / op2;
            }
            return result;
        }
        public string CalculateFengsu(int up1, int down1, int up2, int down2, int type)//分数四则运算
        {
            string result = "";
            if (type == 1)
            {
                up1 = (up1 * down2 + up2 * down1);
                down1 = down1 * down2;
                up2 = gcd(up1, down1);
                up1 = up1 / up2;
                down1 = down1 / up2;
                result = up1.ToString() + "/" + down1.ToString();
                return result;
            }
            if (type == 2)
            {
                up1 = (up1 * down2 - up2 * down1);
                down1 = down1 * down2;
                up2 = gcd(up1, down1);
                up1 = up1 / up2;
                down1 = down1 / up2;
                result = up1.ToString() + "/" + down1.ToString();
                return result;
            }
            if (type == 3)
            {
                up1 = up1 * up2;
                down1 = down1 * down2;
                up2 = gcd(up1, down1);
                up1 = up1 / up2;
                down1 = down1 / up2;
                result = up1.ToString() + "/" + down1.ToString();
                return result;
            }
            if (type == 4)
            {
                up1 = up1 * down2;
                down1 = down1 * up2;
                up2 = gcd(up1, down1);
                up1 = up1 / up2;
                down1 = down1 / up2;
                result = up1.ToString() + "/" + down1.ToString();
                return result;

            }

            return result;
        }
        public string CalculateZfengsu(int up1,int down1)//判断及生成真分数
        {
            string result = "true";
            int mid = 0;

                if (up1 > down1)
                {
                    mid = down1;
                    down1 = up1;
                    up1 = mid;
                    result = up1.ToString() + "/" + down1.ToString();
                    return result;
                }
                    if (up1 == down1)
                    {
                        down1 += 3;
                        result = up1.ToString() + "/" + down1.ToString();
                        return result;
                    }
    return result;
}

gcd(int a, int b)

Calculate(int type, int op1, int op2) //其中type为运算类型，op1，op2为整数。

CalculateFengsu(int up1, int down1, int up2, int down2, int type) //其中up1，up2为分子，down1，down2为分母，type为运算类型。

CalculateZfengsu(int up1,int down1) //up1，down1分别为分子分母。

六、小结：

这是结对编程的第二次作业，难度会大一些，万事开头难，不知道从何下手，摸索了一段时间后才开始做的，一些代码也不够熟练，总得好好的去找其他同学请教请教才行。还有就是要看以前的书籍。

 PSP2.1 Personal Software Process Stages Time Senior Student Time Planning 计划 0.5h 0.5h · Estimate 估计这个任务需要多少时间 2h 2.5h Development 开发 1.5h 1h · Analysis 需求分析 (包括学习新技术) 20min 10min · Design Spec 生成设计文档 10min 6min · Design Review 设计复审 10min 16min · Coding Standard 代码规范 5min 3min · Design 具体设计 20min 12min · Coding 具体编码 40min 21min · Code Review 代码复审 15min 9min · Test 测试（自我测试，修改代码，提交修改） 15min 21min Reporting 报告 5min 6min · 测试报告 5min 2min · 计算工作量 5min 1min · 提出过程改进计划 10min 3min
posted on 2017-03-29 15:40  执笔写下，狂  阅读(162)  评论(1编辑  收藏  举报