hw3 unit test v1.1 - ntut.edu.tw

7
1/7 National Taipei University of Technology Object-Oriented Programming (Fall, 2007) Homework # 3 (Due: Wed. , Nov. 7, 24:00) 1. Introduction In homework #3, we will assemble several tasks as a group called Task Group. Second, we will practice two design patterns: Singleton and Composite. You have to apply these patterns in your program. Finally, you have to do some unit testing for your homework. In addition, a skeleton program is also offered to implement homework#3. Therefore, you can choose either the skeleton program or your own program. In general, you are encouraged to implementing homework#3 based on your own program. 2. Applying Singleton Pattern “Ensure a class only has one instance, and provide a global point of access to it.” The TaskManager class plays the “Controller” role in our application. All the functions of Task Organizer will be completed by using the public methods of TaskManager. It’s important for the TaskManager class to have exactly one instance. The TaskManager class ensure that no other instance can be created, and it provide a way to access the instance. Figure 1 shows the related class of class diagram after applying the Singleton pattern. The TaskManager defines an instance operation that lets clients access its unique instance. You should notice that the _instance attribute and instance operation are in class scope. Figure 1: Applying Singleton to TaskManager class 3. Task Group & Applying Composite Pattern

Upload: others

Post on 12-Mar-2022

12 views

Category:

Documents


0 download

TRANSCRIPT

1/7

National Taipei University of Technology Object-Oriented Programming (Fall, 2007)

Homework # 3 (Due: Wed. , Nov. 7, 24:00)

1. Introduction In homework #3, we will assemble several tasks as a group called Task Group.

Second, we will practice two design patterns: Singleton and Composite. You have to apply these patterns in your program. Finally, you have to do some unit testing for your homework.

In addition, a skeleton program is also offered to implement homework#3. Therefore, you can choose either the skeleton program or your own program. In general, you are encouraged to implementing homework#3 based on your own program.

2. Applying Singleton Pattern

“Ensure a class only has one instance, and provide a global point of access to it.”

The TaskManager class plays the “Controller” role in our application. All the functions of Task Organizer will be completed by using the public methods of TaskManager. It’s important for the TaskManager class to have exactly one instance. The TaskManager class ensure that no other instance can be created, and it provide a way to access the instance.

Figure 1 shows the related class of class diagram after applying the Singleton pattern. The TaskManager defines an instance operation that lets clients access its unique instance. You should notice that the _instance attribute and instance operation are in class scope.

Figure 1: Applying Singleton to TaskManager class

3. Task Group & Applying Composite Pattern

2/7

3.1 Add a new tag: <taskGroup> In this homework, several related tasks can be assembled as a group, and we called

it a “Task Group.” Each task group can also assembled other task groups and tasks. Therefore, all the tasks can form as a hierarchical tree structure. By using this tree structure, we can manage our tasks: put the related tasks together, or breakdown a complicated task into several subtasks.

In order to support the task group in our current implementation, we add a new tag called “<taskGroup>” for describing the task group. You have to modify the loadFromFile method for the file format changes. The file format changes section will be described in the following section.

3.2 File Format Changes

The description file now has only one default task group which contains all the tasks and task groups. Each task group will be described as “<taskGroup id="value"> </taskGroup>” format, and it can contains other tasks and task groups. For example, in the Figure 2, the default task group has 2 tasks and 2 task groups, and each task group has one or more tasks. The task format is the same as previous homework.

Figure 2: Sample Input File

3/7

3.3 Composite Pattern

“Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.”

Figure 3 shows the class structure of our application after applying the composite pattern. The ITask class is an abstract base class. The ITask class declares the common interface and implements some default behaviors. Both the Task class and TaskGroup class extend the ITask class. The Task class represents leaf objects in the composition, it means a leaf has no children; the TaskGroup class stores several child components and implements child-related operations in the ITask interface.

Two specific operations: countTotalExpectedTime and countTotalActualTime, are useful behaviors for managing our tasks. Sometimes, we want to know the total time we spent on some related tasks, such as doing the homework in this semester. If we treat the Task and TaskGroup differently, so the program have to distinguish these objects makes the application more complex. The Composite pattern describes how to use recursive composition so that clients don’t have to make this distinction.

Figure 3: Applying the Composite pattern

4/7

4. Unit Test Begin with this homework, you have to do the unit testing for every following

homework. We will provide a unit test skeleton in this homework. Table 1 show all the test methods. The first unit testing has 2 test cases: TaskManagerTestCase and TaskGroupTestCase. Each test case has a test suite that contains a number of test methods. There are 11 test methods in totally. You are required to provide implementation of those 10 test methods at least, and the testMissingRequiredAttribute method is for bonus. Test Method Description TaskManagerTestCase testLoadFromFileCorrectly All the tasks are loaded into application exactly testMissingRequiredAttribute (Bonus) Test if a required attribute is missing testMissingOptionalAttributes Test if a optional attribute is missing testChangingAttributesOrdering Test 5 possible combinations at least testSaveToFileCorrectly Test that the saved file is the same as expected testImportFileCorrectly Test importing tasks correctly testIsTaskExistCorrectly Test if one task is exist or not TaskGroupTestCase testAddSubTaskCorrectly Test adding a new subtask correctly testRemoveSubTaskCorrectly Test removing a subtask correctly testGetSubTaskCorrectly Test get a subtask correctly testFindSubTaskCorrectly Test find a subtask correctly

Table 1: Test Methods Listing

Moreover, you should get used to the following items so that make your unit tests more effective. 1. When a unit test fails, fix the code right away. 2. All unit tests pass but the code crashed: write a unit test that demonstrates the

failure. 3. Maintain your unit tests! Keep them up to date with your architecture/specification

changes. 4. Write your code so that it's easy to write unit tests. 5. Refactor your code when necessary to make it more unit test friendly. This will

almost always lead to better code as well. 6. Do not copy and paste from your application code that is needed to do setup!

5/7

5. Draw the Class Diagram for your program You have to draw the class diagram for your implementation. The structure of your

class diagram may be alike the design class diagram, but the class diagram contains more details, including:

1. All the classes you implement. 2. All the attributes and operations of the class. 3. The pattern name and pattern roles that you apply in this homework. You can draw the class diagram by using any UML drawing tool, or using Microsoft

Visio as well. However, you have to export the class diagram to the PDF or JPEG file format, and provide the electronic and printed versions both with homework submission. Figure 4 shows how the pattern name and pattern roles are marked. The pattern name will use the Stereotype on each related class, and the pattern role will use the Note to indicate the role which the class plays.

Figure 4: the pattern name and pattern role of the class diagram

6/7

6. Grading After completing this homework, your program should provide the following

features: 1. Applying the Singleton pattern (10%) 2. Applying the Composite Pattern (50%)

(a). Modify the TaskManager class to support task group. (20%) (b). Complete the ITask, Task, and TaskGroup classes correctly. (20%) (c). Implement the countTotalExpectedTime and countTotalActualTime

methods correctly. (10%) 3. Doing the unit testing (35%)

(a). 10 test methods listing in Table 1. (30%) (b). Bonus: implement the testMissingRequiredAttribute method. (5%)

4. Draw the class diagram for your implementation. (10%) Please write a C/C++ program to perform these features described above. The efficiency of your program is not a concern in this homework.

7. Homework submission The homework needs to be submitted in both ways:

1. Electronic version All the related files in this homework have to compress in one ZIP file. The ZIP

should include the following items: (1). Source code (the entire eclipse project). (2). Report (PDF or WORD). (3). Class diagram (PDF or JPEG).

Please login the Open Cyber Classroom using your student ID from the following URL: http://mslin.ee.ntut.edu.tw/new/student/. You have to upload the electronic version to the web. 2. Printed version You have to write a brief summary for this homework that should include the following items: (1). The features that you finished in this homework. (2). Snapshots of program execution. (3). The implementation class diagram. (4). Source Code Listing as appendix. (5). Measure the time that you spent in this homework. Please record the time precisely

in the following table (Table 2).

7/7

OOP homework#1 (total: 11:03 hours)

Date Start Stop Interrupt Hour Comments

20070917 13:35 15:00 1:25 Run Skeleton program

20070917 16:00 17:00 1:00 Learning STL library

Table 2: Measurement Example

8. References Some free UML drawing tolls: (1). StartUML, http://www.staruml.com/ (2). Visual Paradigm for UML,

http://www.visual-paradigm.com/product/vpuml/