zoukankan      html  css  js  c++  java
  • 实验二报告

    20145339顿珠达杰 实验二"Java面向对象程序设计"

    程序设计过程

    实验内容

    使用TDD的方式设计实现复数类 Complex 自己请教张薇用这个东西 所以直接用了梓靖的代码 重新完成她的实验。

    编写代码:

    import org.junit.Test; public class ComplexNumberTest { @Test public void TestFunction1() { ComplexNumber complexnumber = new ComplexNumber(3, 5); ; assert complexnumber.mdRealPart == 3 : "ComplexNumber(double r,double I)构造函数有错误"; assert complexnumber.mdImaginPart == 5 : "ComplexNumber(double r,double I)构造函数有错误"; }

    @Test
    public void TestFunction2() {
        ComplexNumber complexnumber = new ComplexNumber();
    
        assert complexnumber.m_dImaginPart == 0 : "ComplexNumber()构造函数有错误";
        assert complexnumber.m_dRealPart == 0 : "ComplexNumber()构造函数有错误";
    }
    
    @Test
    public void TestSetWay() {
        ComplexNumber complexnumber = new ComplexNumber();
    
        complexnumber.SetRealPart(1);
        complexnumber.SetImaginaryPart(1);
        assert complexnumber.m_dRealPart == 1 : "SetRealPart方法有错误";
        assert complexnumber.m_dImaginPart == 1 : "SetImaginaryPart方法有错误";
    }
    
    @Test
    public void TestgetWay() {
        ComplexNumber complexnumber = new ComplexNumber();
    
        complexnumber.SetRealPart(3);
        complexnumber.SetImaginaryPart(5);
        assert complexnumber.GetRealPart() == 3 : "GetRealPart方法有错误";
        assert complexnumber.GetImaginaryPart() == 5 : "GetImaginaryPart方法有错误";
    }
    
    @Test
    public void TestStringWay() {
        ComplexNumber complexnumber = new ComplexNumber(3,5);
    
       assert complexnumber.toString()=="3.0+5.0i":"toString方法有错误";
    }
    
    @Test
    public void TestAddWay1() {
        ComplexNumber complexnumber1 = new ComplexNumber(1,1);
        ComplexNumber complexnumber2 = new ComplexNumber(2,2);
        ComplexNumber complexnumber3=complexnumber1.ComplexAdd1(complexnumber2);
    
        assert complexnumber3.m_dRealPart == 3 : "ComplexAdd方法有错误";
        assert complexnumber3.m_dImaginPart == 3 : "ComplexAdd方法有错误";
    }
    
    @Test
    public void TestAddWay2() {
        ComplexNumber complexnumber1 = new ComplexNumber(1,1);
        ComplexNumber complexnumber2=complexnumber1.ComplexAdd2(2);
    
        assert complexnumber2.m_dRealPart == 3 : "ComplexAdd方法有错误";
        assert complexnumber2.m_dImaginPart == 1 : "ComplexAdd方法有错误";
    }
    
    @Test
    public void TestMinusWay1() {
        ComplexNumber complexnumber1 = new ComplexNumber(1,1);
        ComplexNumber complexnumber2 = new ComplexNumber(2,2);
        ComplexNumber complexnumber3=complexnumber2.ComplexMinus1(complexnumber1);
    
        assert complexnumber3.m_dRealPart == 1 : "ComplexMinus方法有错误";
        assert complexnumber3.m_dImaginPart == 1 : "ComplexMinus方法有错误";
    }
    
    @Test
    public void TestMinusWay2() {
        ComplexNumber complexnumber1 = new ComplexNumber(5,1);
        ComplexNumber complexnumber2=complexnumber1.ComplexMinus2(1);
    
        assert complexnumber2.m_dRealPart == 4 : "ComplexMinus方法有错误";
        assert complexnumber2.m_dImaginPart == 1 : "ComplexMinus方法有错误";
    }
    
    @Test
    public void TestMultiWay1() {
        ComplexNumber complexnumber1 = new ComplexNumber(3,3);
        ComplexNumber complexnumber2 = new ComplexNumber(3,5);
        ComplexNumber complexnumber3=complexnumber1.ComplexMulti1(complexnumber2);
    
        assert complexnumber3.m_dRealPart == -6 : "ComplexMinus方法有错误";
        assert complexnumber3.m_dImaginPart == 24 : "ComplexMinus方法有错误";
    
    }
    
    @Test
    public void TestMultiWay2() {
        ComplexNumber complexnumber1 = new ComplexNumber(3,3);
        ComplexNumber complexnumber2=complexnumber1.ComplexMulti2(2);
    
        assert complexnumber2.m_dRealPart == 6 : "ComplexMinus方法有错误";
        assert complexnumber2.m_dImaginPart == 6 : "ComplexMinus方法有错误";
    
    }
    

    进行单元测试:

    建模:

    实验体会:

    自己还是没学到很多.得加油了。

  • 相关阅读:
    slf4j使用
    centos 安装 redis
    centos安装单机zookeeper
    activemq消息重发机制[转]
    maven 指定工程的 jdk 版本及编译级别
    Elasticsearch-索引新数据(创建索引、添加数据)
    Elasticsearch-数据的存储、搜索(干货)
    Yarn-本地获取任务日志
    Hive-Container killed by YARN for exceeding memory limits. 9.2 GB of 9 GB physical memory used. Consider boosting spark.yarn.executor.memoryOverhead.
    Elasticsearch-安装、日志解读
  • 原文地址:https://www.cnblogs.com/dj20145339/p/5402289.html
Copyright © 2011-2022 走看看