• 20145313第二次实验


    20145313第二次实验

    单元测试

    代码实现

    测试用例



    找到BUG,进行修改

    TDD测试用例

    建立MyUtil类并测试

    模块化

    UML建模

    继承

    练习

    源代码

    package exp2;
    public class Complex {
    protected int a;
    protected int b;
    public Complex(int a, int b) {
    this.a = a;
    this.b = b;
    }
    
    public String toString() {
    return this.a + " + " + this.b + "i";
     }
    
    public static Complex addition(Complex complex1, Complex complex2) {
      int a = complex1.a + complex2.a;
    int b = complex1.b + complex2.b;
    return new Complex(a, b);
    }
    
    public static Complex subtract(Complex complex1, Complex complex2) {
    int a = complex1.a - complex2.a;
    int b = complex1.b - complex2.b;
    return new Complex(a, b);
    }
    
    public static Complex multiplication(Complex complex1, Complex complex2) {
    int a = complex1.a * complex2.a - complex1.b * complex2.b;
    int b = complex1.b * complex2.a + complex1.a * complex2.b;
    return new Complex(a, b);
    }
    
    public static Complex division(Complex complex1, Complex complex2) throws Exception {
    if (complex2.a == 0) {
    throw new Exception("complex2.a is 0");
    }
    if (complex2.b == 0) {
    throw new Exception("complex2.b is 0");
    }
    int a = (complex1.a * complex2.a + complex1.b * complex2.b) / (complex2.a * complex2.a + complex2.b * complex2.b);
    int b = (complex1.b * complex2.a - complex1.a * complex2.b) / (complex2.a * complex2.a + complex2.b * complex2.b);
    return new Complex(a, b);
     }
    }
    

    测试代码

    package exp2;
    public class Comtest {
     public static void main(String[] args) throws Exception{
     Complex complex1 = new Complex(1, 2);
    	Complex complex2 = new Complex(3, 4);
    System.out.println(complex1 + " + " + complex2 + " = " + Complex.addition(complex1, complex2));
    System.out.println(complex1 + " - " + complex2 + " = " + Complex.subtract(complex1, complex2));
    System.out.println(complex1 + " x " + complex2 + " = " + Complex.multiplication(complex1, complex2));
     System.out.println(complex1 + " / " + complex2 + " = " + Complex.division(complex1, complex2));
    }
    }
    

    测试截图

    步骤 耗时 百分比
    需求分析 20min 5
    设计 20min 20
    代码实现 50min 50
    测试 20min 15
    分析总结 20min 10
  • 相关阅读:
    C# post请求,Json转换实体类
    jq div 托拉拽
    json转换成实体类
    C# 队列、锁、异步
    关于C#调用protobuf 序列化和反序列化
    关于System.Data.Entity.Infrastructure.DbUpdateException 的问题
    C# 本地CSS和JS引用无问题,部署服务器之后出现500错误
    windows服务
    下拉加载更多DEMO(js实现)
    禁用iPhone手机浏览器上给电话号码自动加上的link样式
  • 原文地址:https://www.cnblogs.com/entropy/p/5392565.html
Copyright © 2020-2023  润新知