20172317 2017-2018-2 《程序设计与数据结构》实验二报告
课程:《程序设计与数据结构》
班级: 1723
姓名: 蒋子行
学号: 20172317
实验教师: 王志强
实验日期: 2018年4月22日
必修/选修: 必修
实验内容Experiment content
- Master the basic of unit testing and TDD(Test-driven development)
- Understand and master 3 vital elements of object-oriented programming:encapsulation, inheritence, polymorphism
- Learn the basis of UML modeling
- Acquainted with SOLID principles(SRP, OCP, LSP, ISP, DIP)
- Acknowlegde the design pattern
- Complete experiment 1-5 from mosoteach
Procedure and the results of the experiments
Experiment 1
- Refer to http://www.cnblogs.com/rocedu/p/6371315.html#SECUNITTEST , and complete the study of unit testing
- Submit the screenshot that of all three JUnit test case(Normal case, Error case, Boundary case) have passed
- Screenshot of the result:
实验2 Experiment 2
- Refer to "积极主动敲代码,使用JUnit学习Java (http://www.cnblogs.com/rocedu/p/4837092.html)" to further study
StringBuffer
with TDD method - Submit your unit test example and the test passed screenshot
- Screenshot of the result:
Experiment 3
- Refer to "实验二 Java面向对象程序设计" to expand the exmaples of "design pattern". Experience the application of OCP principle and DIP principle.Understand the "design pattern" preliminarily.
- Use your student ID to do a remainder calculation, expand the code according to different results:
- Screenshots of the result(there was some flaws in the original screenshot, the screenshots here are the original screenshot with error and the screenshot of correct output)
As you can see in the first screenshot, class Double is supposed to print a float, however an integer replaced it.This is because variable
value
is set to be anint
rather than adouble
Experiment 4
- Develop a complex number class Complex in TDD method
- Screenshot of the result:
Experiment 5
- Model the code of this whole experiment with StarUML
- There should be at least 2 classes in the illustration
- Screenshot of the result:
Problems encountered while experimenting and solutions
- Problem 1:JUnit? Unit testing? Test-driven development?
- Solutions of problem 1:Yep, this is it, another
bullshitexperiment, this is really crazy.This time there are thousands of new concepts and things like that, so I have to find informations about these new things.Now the first one is JUnit. At first I thought it might be some kind of third party plugin. Well, actually it is ok to say so, but it is a unit testing framework for Java. According to the internet, JUnit plays an important role in the development of test-driven development. By utilizing JUnit, we can write test code, which can greatly improve our coding efficiency.(Though I don‘t really think so)
Well.....so, unit testing? The heck is that?According to the internet: "in computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use." Lets explain this in a intuitive way: imagine a factory that assembles tv, each time before a tv is made, it‘s component would be tested, and that process of testing is the so-called "unit-testing".
Annnd, "test-driven development", which is also known as TDD, is our next object. Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements.
- Problem 2:SOLID?
- Solutions of problem 2:SOLID is an acronym for five design principles.The five principles are:SRP(single responsibility principle), OCP(open/closed principle), LSP(Liskov substitution principle), ISP(interface segregation principle), DIP(dependency inversion principle).
Other
As if life isn‘t suck already, we have to complete all these nonsense in IDEA? NO, it could be worse, that could be worse.
I don‘t think I learned anything from this experiment, I just do what they told me to do. What a waste of time....
Luckily, it is not a completely meaningless experience. It triggered my thinking on the nature of software development. Here is a question: What can you really do? Are you creating code, or you‘re just writing code. Although I just hate these stuff, they play a vital rule in the process of software design. I am not good at all of these, but my rusty brain can still learn a thing or two, it‘s won‘t cause any loss anyway.
References
原文地址:https://www.cnblogs.com/Chiang-B/p/8965622.html