• 张萍萍 计科高职13-1 201303014010 实践二个人项目


    实践二个人实践

     

    学号: 201303014010   姓名:张萍萍    班级:计科(高职)13-1

    一、题目简介

    这次实践是创建一个加减乘除的简单的小程序,主要利用加减乘除四种方法来实现简单的数字计算。

    二、源码的github链接:

    https://github.com/elinesping/project2/blob/master/张萍萍-201303014010-计科高职13-1-实践二个人项目代码

    三、所设计的模块测试用例、测试结果截图

    模块测试用例代码:

    import static org.junit.Assert.*;

    import org.junit.Before;

    import org.junit.Test;

    public class CalculatorTest {

           private static Calculator calculator = new Calculator(); 

           @Before

           public void setUp() throws Exception {

                  calculator.clear();

           }

    /*我们想测试一下“加法”功能是否正确,就在测试方法中调用几次add函数,初始值为0,先加2,在加3,

     * 我们期待的结果应该是5,实际结果也是5,说明add方法是正确的,反之说明他是错的*/

           @Test

           public void testAdd() {

                  calculator.add(2);

                  calculator.add(3); 

            assertEquals(5, calculator.getResult());

           }

           /*assertEquals(5, calculator.getResult());

            * 就是来判断期待结果和实际结果是否相等,第一个参数填写期待,第二个参数填写实际结果,

            * 也就是通过计算得到的结果。*/

     

           @Test

           public void testSubstract() {

                  calculator.add(10); 

                   calculator.substract(2); 

                   assertEquals(8, calculator.getResult());

           }

     

           @Test

           public void testMultiply() {

                  calculator.add(10); 

                  calculator.multiply(2);

                  assertEquals(20, calculator.getResult());

           }

           public void testDivide() {

                  calculator.add(10); 

                  calculator.divide(2);

                  assertEquals(5, calculator.getResult());

           }

    }

    测试结果截图:

     

    测试用例结构图:

     

          

    四、问题及解决方案、心得体会

    在本次实践中,我在使用据junit4来检查程序的时候发现了不少的错误,在建立测试文件之后,还需要进一步添加测试代码,而起我也明白了要保证程序的准确性,要多进行几次测试。

     

    要解决这个问题,要对测试代码进行编辑,将fail("Not yet implemented");改为calculator.add(10);  calculator.substract(2);   assertEquals(8, calculator.getResult());这样问题就解决了

     

    通过本次试验我了解了junit4,并且更好的复习了以前的java知识,并且学会了怎么用模块测试用例,也学会了怎么使用博客和github来更好的学习现在的知识。通过这次实践我发现其实我的Java还不是太熟练,有待加强。

  • 相关阅读:
    vue自定义指令
    ZOJ Problem Set–2104 Let the Balloon Rise
    ZOJ Problem Set 3202 Secondprice Auction
    ZOJ Problem Set–1879 Jolly Jumpers
    ZOJ Problem Set–2405 Specialized FourDigit Numbers
    ZOJ Problem Set–1874 Primary Arithmetic
    ZOJ Problem Set–1970 All in All
    ZOJ Problem Set–1828 Fibonacci Numbers
    要怎么样调整状态呢
    ZOJ Problem Set–1951 Goldbach's Conjecture
  • 原文地址:https://www.cnblogs.com/elinesping/p/4455802.html
Copyright © 2020-2023  润新知