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

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

Course: "Program Design and Data Structure"
Class: 1723
Name: Wang Wenbin
Student ID: 20172329
Experiment Teacher: Wang Zhiqiang
Experiment Date: April 21, 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. completed experiment.

2. Experimental process and results

1. Understanding the content
First of all, I have a general understanding of what is TDD test and what is SOLID principle based on several blogs given by the teacher, and based on the textbook, I will learn more about encapsulation, inheritance, and polymorphism. The example given by the teacher and the relevant steps of the blog start the experiment.

2. The content and process of the first submission point of the experiment

Refer to Experiment 2 to complete the study of unit testing
Submit the screenshots of the last three JUnit test cases (normal, error, and boundary conditions) passing. The screenshots must be drawn and watermarked. Enter your student ID
to check whether JUnit will be submitted. Will use, test cases should include at least normal case, error case, edge case test

In the first experiment, because it was the first time I came into contact with the TDD test, everything seemed so unfamiliar, and I felt that there were a lot of things to download;
1. Preparation stage : First, use IDEA to create a test test file in its own root directory folder, and define it as the source directory,

This directory is the test folder corresponding to the further testing of the programs that you have compiled.
After that, I downloaded a plug-in called JUnit. If you want to complete the test, this plug-in is essential, master the core technology! !
This is the end of our preparatory work, and then we will start our experiment;
2. The experiment begins:
first write the class you want to test, and around the position of the first line, a shape similar to the following will appear. The "little light bulb" of the diagram and the words: Create test will appear .

After clicking on the "create test", a test program will appear in the test directory, and then we can start our test road. First of all, a test program that I have written before is on standby, just for now , the test program needs to inherit the tested class and write the test object. Here we need another very key method called assertEquals, whose function is to compare whether the value we expect is the same as the expected value (ps: here the The same should not only have the same content, but also the same attributes ), the same will display a green line, indicating pass, as shown in the following figure:

After the test is passed, plus the watermark of your student number, even the first experiment is over.

3. The content and process of the second submission point of the experiment

Reference Actively
type code, use JUnit to learn Java to study and learn StringBuffer in the way of TDD
Submit your unit test cases and screenshots of test passing, the screenshots should be watermarked with the student number
Test whether you can write JUnit test cases yourself

On the basis of the first experiment, it is not very difficult to start my second experiment;
first, continue to read the blog given in the requirements, and start writing the tested code according to the requirements:

After that, continue with the steps of Experiment 1, click "Create Test", and start writing the test class:

Note: When writing a test class, remember to write clearly what the test code is, that is, the code behind "@test" in the figure, and @test cannot be lost.

Fourth, the content and process of the third submission point of the experiment

Refer to Experiment 2 Java Object-Oriented Programming
Expand the design pattern example, experience the application of the OCP principle and the DIP principle, and have a preliminary understanding of the design pattern
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 test code to the MyDoc class to indicate that the addition is correct, submit a screenshot of the test code and the running result, and add the student number watermark
1: Let the system support the Short class, and add the test code to the MyDoc class to indicate that the addition is correct, submit Screenshots of test code and running results, plus student number watermark
2: Let the system support Boolean classes, and add test code to MyDoc class to indicate that the addition is correct, submit screenshots of test code and running results, plus student number watermark
3: Let the system support Long 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, add 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 Screenshots of the code and running results, plus student number watermark
5: Let the system support the Double class, and add test code in the MyDoc class to indicate that the addition is correct, submit screenshots of the test code and running results, plus the student number watermark

This question should be the earliest introduction to the SOLID principle, so when I saw this question for the first time, I was a little confused and felt a lot better. The first thought was that the first two were not difficult, so this must start The difficulty has increased. Sure enough, although the typing of the code imitates the teacher's example, the task can actually be completed, but it needs to be understood after all, so it is better to understand it first, so I began to carefully study the teacher's blog; teacher Two major changes have been made in the blog of . The teacher gave an example of "customers need to support Floatclasses, because based on the SOLID principle, Documentclasses cannot be changed, so they need to use design patterns , and the concept of "design factory" is introduced.Use the teacher's picture to explain

I feel that this picture is still very detailed;
ps: The teacher's screenshot is clearly an implementation intclass, misleading us children...

DoubleThis is the experimental diagram of my implementation class

5. The content and process of the fourth submission point of the experiment

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:

 // 定义属性并生成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)

When I got this experimental requirement, I actually found that some routines were needed, and I wrote the four arithmetic operations of complex numbers;
first, I wrote the above centralized method and defined variables according to the requirements, performed related calculations, and then started the test:

6. The content and process of the fifth submission point of the experiment

Use StarUML to model the code in the second experiment, send a screenshot of the class diagram, plus the student number watermark
. There are only two classes in the class diagram.
Class, inheritance, interface implementation, and combination are expressed in UML.
Through software

Make UML diagrams;

3. Problems encountered during the experiment and the solution process

- Question 1: When writing a plural class and testing it, although the content is the same, it always shows that it fails?

  • Problem 1 Solution:
    The first one, in the blue ink cloud, the senior said that it is enough to add .toString at the back, because the two return types are different, it can be done after trying it; the
    second one, I read it myself After a blog of someone else, about comparing several types of blogs of String, I found that it String.valueOfis also possible to use it;

Other (perception, thinking, etc.)

I feel that the time is getting less and less. Sometimes when I am typing the code, I am at a loss. I don't know why I am typing and what the purpose is. It really presents a false sense of prosperity in the class now.

References

Blue ink cloud class
actively typing code, using JUnit to learn Java
Experiment 2 Java Object-Oriented Programming
String, String.valueOf, toString The difference between them summarizes
a little explanation of Experiment 2 "Java Object-Oriented Programming"

Guess you like

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