20172314 2017-2018-2 "Program Design and Data Structure" Experimental Report II

20172314 2017-2018-2 "Program Design and Data Structure" Experimental Report II

Course: "Programming and Data Structures"

Class: 1723

Name: Fang Yiwen

Student ID: 20172314

Experimental teacher: Wang Zhiqiang

Experiment Date: April 18, 2018

Compulsory/Elective: Compulsory

1. Experiment content

  1. Getting started with unit testing and TDD

  2. Understand and master the three elements of object-oriented: encapsulation, inheritance, polymorphism

  3. Preliminary mastery of UML modeling

  4. Become familiar with SOLID principles

  5. Learn about design patterns

  6. Complete the experiments (1)-(5) on the blue ink cloud.

2. Experimental requirements

1. Students who do not have Linux foundation are recommended to study the courses of " Introduction to Linux Basics (New Edition) " and " Vim Editor " first.

2. Complete the experiment, write the experimental report, and publish the experimental report in the blog park in the form of a blog . Note that the experimental report focuses on the running results and the problems encountered (tool search, installation, use, program editing, debugging, running, etc.), solving Methods (empty methods such as "checking the Internet", "asking classmates", "reading books", etc., all get 0 points) and analysis (what enlightenment can be obtained from it, what are the gains, lessons, etc.). The report can refer to the guidance of Mr. Fan Feilong

3. Plagiarism is strictly prohibited, and the experimental results of those who have this behavior will be reset to zero, and other punishment measures will be added.

3. Experimental process and results

  • Prepare:
    • Download WhiteStarUML
    • Install the plugin using Junit in IDEA.

Experiment one and two

  • After completing the first two experiments in the class, I know the pseudo code, product code and test code; TDD. Pseudocode has nothing to do with a specific programming language and is used to express one's own programming ideas. The production code is written in the Java language, and the test code is used to prove that the code is correct. In addition, the programmer's testing of the class implementation is called unit testing. TDD means to write test code first, then write product code, test-driven development, and prevent the generation of useless code.
  • Screenshot of successful test:

Experiment 3

  • Expand the design pattern example, experience the application of the OCP principle and the DIP principle, and initially understand the design pattern.
    Use your own student number %6 to perform the remainder operation, and expand the code according to the result. My student number takes the remainder as 2, and Gu is Boolean type. The content of OCP is that class functions should be open for extension and closed for modification.
  • This experiment adds boolean to Integer; and adds BooleanFactory to IntFactory.
  • Screenshot of successful test:

Experiment 4

  • To develop a complex class Complex in the way of TDD, the requirements are as follows: define properties and generate getters and setters; double RealPart; double ImagePart; the requirements are:

    // 定义属性并生成getter,setter 
    double RealPart; 
    double ImagePart; 
    // 定义构造函数 
    public  Complex() 
    public  Complex(double R,double I)
    //Override Object public boolean equals(Object obj) public String toString()
    // 定义公有方法:加减乘除 
    Complex ComplexAdd(Complex a) 
    Complex ComplexSub(Complex a) 
    Complex ComplexMulti(Complex a) 
    Complex ComplexDiv(Complex a)
  • According to the given requirements, improve it, the test is successful screenshot:

Experiment 5

  • Use WhiteStarUML to model the code in Experiment 2.
  • The completed result is shown in the figure:

4. Problems encountered in the experiment and the solution process

  • Question 1: When doing experiment 1 in class, the code is obviously correct, but the result is always wrong, and a string of "unmappable characters" is displayed.
  • One solution to the problem: After asking Mr. Wang, he said that it was the problem of the Chinese package, and it was easy to make mistakes when there was Chinese. There was no solution, so I changed all the Chinese to English and it was solved. After that, Mr. Wang gave a solution, which is to change the place where UTF-8 is displayed in the lower right corner of IDEA to GBK.
  • Question 2: When installing the plugin Junit, according to the blog tutorial, but the error is displayed

  • Problem 2 Solution: Use another method, select Manage repositories in the picture, because most people made mistakes at that time, it was done according to Mr. Wang's explanation.
  • Question 3: In experiment 2, there is "assertequals" in the code in StringBufferDemo, I don't know what it means.
  • Problem 3 Solved: After searching for relevant information, I learned that he meant ''assertEquals([String message], expected, actual) if the expected value is equal to the actual value, then run success, otherwise fail. Prompt that the expected value is xxx, but the actual value is xxx. Easy to adjust. refer to

5. Others

I feel that this task has a lot to learn. It can be completed step by step according to the blog, but it does not mean that I have mastered it all. If I do it all by myself, it is a bit difficult to achieve within a limited time.

6. References

Guess you like

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