20172315 2017-2018-2 "Program Design and Data Structure" Experiment 2 Report

20172315 2017-2018-2 "Program Design and Data Structure" Experiment 2 Report

Course: "Program Design and Data Structure"
Class: 1723
Name: Hu Zhitao
Student ID: 20172315
Experiment Teacher: Wang Zhiqiang
Experiment Date: April 18, 2018
Compulsory/Elective: Compulsory

1. Experiment content

(1) Preliminary grasp of unit testing and TDD
(2). Understand and master the three elements of object-oriented: encapsulation, inheritance, polymorphism
(3). Preliminary grasp of UML modeling
(4) Familiar with SOLID principles
(5). Understand design model

Fill in the specific content of the experiment here;

2. Experimental process and results

Experiment (1)

Target:

  • Refer to http://www.cnblogs.com/rocedu/p/6371315.html#SECUNITTEST to complete unit testing learning
  • Submit the screenshots of the last three JUnit test cases (normal, error, and boundary conditions) that have passed. The screenshots must be drawn and watermarked, and enter your student ID.
  • This submission point examines whether JUnit will be used or not. The test cases should at least include tests for normal conditions, error conditions, and boundary conditions.
    Screenshot of code submission: Experiment (1) can be said to be based on the reference


    given by the teacher . In this experiment I learned how to use unit testing, and the use of Junit. Through Mr. Lou's blog, I also learned the importance of unit testing and benefited a lot!

    Experiment (2)

    Target:

  • Refer to actively typing code, using JUnit to learn Java ( http://www.cnblogs.com/rocedu/p/4837092.html )
  • Study and learn StringBuffer in the way of TDD
  • Submit a screenshot of your unit test case and test passing, and add the student number watermark to the screenshot
  • Test whether you can write JUnit test cases by yourself
    Code screenshot:

    This experiment is actually done in the same way as the previous one, a little bit according to Mr. An Zhao Lou's tutorial. Through this experiment, my understanding of unit testing and the use of Junit is more profound. .

    Experiment (3)

    Target:
  • Reference Experiment 2 Java Object-Oriented Programming
  • Expand the design pattern examples, realize the application of OCP principles and DIP principles, and have a preliminary understanding of design patterns
  • Use your own student number %6 to perform the remainder operation, and expand the code according to the result:
    0: Let the system support the Byte class, and add the test code to the MyDoc class to indicate that the addition is correct, submit the test code and the screenshot of the running result, plus the student number Watermark
    1: Let the system support the Short class, and add the test code in the MyDoc class to indicate that the addition is correct, submit the test code and the screenshot of the running result, and add the student number watermark
    2: Let the system support the Boolean class, and add the test code in the MyDoc class Indicate that the addition is correct, submit a screenshot of the test code and the running result, plus the student number watermark
    3: Let the system support the Long class, and add the test code in the MyDoc class to indicate that the addition is correct, submit the test code and the screenshot of the running result, plus the student number watermark
    4: Let the system support the Float class, and add the test code in the MyDoc class to indicate that the addition is correct, submit the test code and screenshots of the running result, and add the student number watermark
    5: Let the system support the Double class, and add the test code in the MyDoc class to indicate that Add the correct, submit the test code and screenshots of the running results, and add the student number
    watermark


    . experiment. I also greatly exercised my hands-on ability in this experiment. Although the experimental process was somewhat tortuous, I still completed the experiment.

    Experiment (4)

    Goal:
    Submit: unit test code and screenshots of successful running and code links on the code cloud. The screenshots should be watermarked with the student number.
    Task: Develop a complex class Complex in the way of TDD. The requirements are as follows:

    // Define properties and generate getters,setters
    double RealPart;
    double ImagePart;

    // Define the constructor
    public Complex()
    public Complex(double R,double I)

    //Override Object
    public boolean equals(Object obj)
    public String toString()

    // Define public methods: addition, subtraction, multiplication and division
    Complex ComplexAdd(Complex a)
    Complex ComplexSub(Complex a)
    Complex ComplexMulti(Complex a)
    Complex ComplexDiv(Complex a)

screenshot:

This experimental program is rather cumbersome in my opinion. First, we need to write a complex class and test it. It took a lot of work to write the algorithm, and this experiment was the one I spent the most time on.

Experiment (5)

Target:

  • Use StarUML to model the code in Experiment 2, send a screenshot of the class diagram, and add the student number watermark
  • There are only two classes missing in the class diagram
  • Class, inheritance, interface implementation, composition are expressed in UML
    Screenshot:

There was no tutorial for this experiment, and I didn't have a particularly clear idea of ​​the goal of the experiment. The software given by the teacher is also in English and cannot be used. Are there any good tutorials online. But in the case of my groping, I still completed a class diagram.

3. Problems encountered during the experiment and the solution process

  • Problem 1: I don't know how to install Junit at first.
  • Problem 1 Solution: Knowing to search for installation from settings after asking classmates

  • Question 2: I encountered a character set error when using Junit, that is, the problem of garbled characters.
  • Problem 2 Solution: Use the teacher's solution to solve it.
  • Question 3: I still don't understand the capacity of StringBuffer
  • Solution 3: After querying the data, we learned that when the initial capacity is exceeded by more than two, its capacity becomes 2*length+2.

References

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324904397&siteId=291194637