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

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

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

1. Experimental content

  • Use the JUnit test tool to test whether there is a problem with the written class
  • Learn what TDD is and use JUnit to aid in TDD testing research StringBuffer
  • Code expansion, experience the application of OCP principles and DIP principles, and initially understand design patterns
  • Modeling with StarUML, expressing classes, inheritance, interface implementation, composition in UML
  • For Eclipse-related content, refer to Intellj IDEA simple tutorial and replace it with IDEA implementation

2. Experimental process and results

These experiments are not difficult, and you can follow the steps given by the teacher to complete them step by step, but the most important thing is to understand when you first come into contact with them. For example, in the first experiment, because I did not have a directory directory, I was stuck for a long time. What follows is also incomprehensible.

The first experiment is to use JUnit4 to test the level corresponding to a score. This experiment is not difficult, so I think about the difference between JUnit3 and JUnit4. For details, see the difference between JUnit3 and JUnit4 . Simply put, there are three differences, one is that JUnit4 uses the org.junit. package and JUnit3.8 uses the junit.Framework. The second is that in JUnit3, the test class needs to inherit the junit.framework.TestCase class, but not in JUniy4. The third is that JUnit3 recognizes test methods by analyzing the method name: the method name must be prefixed with "test", it must return void, and it must have no parameters (eg public void testDivide() ). In JUnit4, test methods do not have to be prefixed with 'test', but are annotated with @Test**** . Overall JUnit4 is simpler, richer, and easier to use.

In the second experiment, TDD tests whether the string corresponding to the index is correct, returns the current capacity (especially the difference between capacity and length, the former is the current maximum capacity, the latter is the length of the string), returns the first The index within this string of the next occurrence of the specified substring.

The third experiment uses my student number %6 to perform the remainder operation, and expands the code according to the result so that the system supports the Byte class (for my student number, it is ok to define the byte class). The senior pointed out the mismatch between my variable names and corrected it in the following question.

The fourth experiment develops a complex number class in the way of TDD and requires defining properties and generating getters, setters, defining constructors and adding, subtracting, multiplying and dividing methods. I didn't understand the question the first time. When I rewrote the toString method, I had no clue and thought that I could just output the value at will. Later, I found that when I entered (a+bi), the idea prompted me that I did not define i, and then I felt that I should find a way to rewrite the toString method. The fourth experiment encountered more problems, and I answered them one by one below.

The fifth experiment is to draw class diagrams, which is very interesting. There are two points to pay attention to. One is the meaning represented by +-~#, and the other is abstraction, which is marked with italics.

Third, the problems encountered during the experiment and the solution process

  • Problem 1: The first step is a problem... I only have the package package and no Directory directory, so I can't set the directory to Test Sources Root to test with JUnit.
  • Solution to problem 1: The reason why the directory cannot be created is because the level is not enough. The highest level is the directory, so finally a module is re-created, and the original content is copied to this module, and the directory can be re-created.
  • Question 2: In the third experiment, public class Dataan error public class Documentwill be prompted, and an error will also be prompted. Why?
  • Solution to problem 2: public class DataThe prompt error is because Data is an abstract class, and abstract needs to be used to indicate that it is an abstract type. If abstract is not used to indicate that it is an abstract method, the DisplayValue() method cannot be inherited later. public class DocumentYou need to declare it in a file named Document.
    Attached is a screenshot of the corrected code

  • Question 3: Why is there always a horizontal line on my assertEquals?

  • Solution to problem 3: The real and imaginary parts defined above are of double type. After I searched online, I found that assertEquals only supports int type, long type or boolean type. In short, (double, double) type is not supported at this time. , I was thinking about what to do... Then I found that it supports (string, string) type. Then add "" to the number to turn it into a string, add a toString method to the following method to convert it into a string, and the horizontal line on assertEquals disappears.
  • Question 4: As shown in the figure, the class file of bjaa$1 cannot be found, me? ? ?

  • Question 4 Solution: What file is this? I didn't find it out on the Internet, but the first half of the sentence was that the file package could not be found. Later, when I checked, I found that the import had imported this file for me inexplicably, so this error message appeared, and it disappeared after I deleted it.
  • Question 5 and its solution: In the getter and setter methods, I entered the same thing according to the submission standard given by the teacher, but I always reported an error, the prompt is that I need to rewrite it into a static method, but in this case, I cannot get to a different value. . There must be a problem. In fact, this problem has not been solved before I write this sentence. It wasn't until I just looked at Question 4 that I found the two functions that were originally constructed. I tried again and found that it was really set to be static.... I'm so angry....

4. Others (perception, thinking, etc.)

5. References

Guess you like

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