Download presentation
Presentation is loading. Please wait.
Published byしおり こいたばし Modified over 6 years ago
1
CS3369 Realtime Control Computer Software/DENG Xiaotie
Lecture 11. Design, Testing and Documentation 11.1 Designing Issues 11.2 Debugging 11.3 Testing 11.4 Checking 11.5 Documentation 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
2
CS3369 Realtime Control Computer Software/DENG Xiaotie
Designing Top-down Design in OOP Data abstraction classes and objects member functions hide data as private Polymorphism allow commonly used member functions to have the same name but perform according to class of an object 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
3
CS3369 Realtime Control Computer Software/DENG Xiaotie
OO Programming with C++ Top-down Design: break tasks down into subtasks and write a function for each make it easy for a team to work on large software projects Functional abstraction: function as a black box so users only need to look at the function prototype and comments to use the function. Function prototype tells programmers pre-conditions and post conditions for arguments(parameters) to function. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
4
CS3369 Realtime Control Computer Software/DENG Xiaotie
Design of the Elevator Functions to use showelevator() //show elevator include the door . //pre-conditions: there is no input. The inputs are the member variables of the class. door --decides the wide of the gap. Door=25 if the door is closed. Door =3 if the door is open. The process of opening a door is the process of changing the value of door. Other required variables, k-- the vertical position of the elevator. Position--the h-position of the elevator. ///post-conditions: the elevator is drawn. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
5
CS3369 Realtime Control Computer Software/DENG Xiaotie
Design of the Elevator Functions to use erease() // erease the elevator. Draw black lines just for the door and the elevator, not for the skeleton. //pre-conditions are the same as selevator(). //post-conditions: door is ereased. Stop() //stop will control the door to stop step by step. //pre-conditions: k--the vertical position and s--stands for if the door is really stopped. (both k and s are member variables.) //post-condition: k and s may be changed. Stop() will be called many times. A door will be closed automatically once s==1. To this this, is simple, door=door-1. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
6
CS3369 Realtime Control Computer Software/DENG Xiaotie
Design of the Elevator Functions to use close()// to change the value of door to close the door step by step. //pre-conditions: the value of door in used, a member variable close is used. Close ==0 if the door is not completely closed. Close ==1 if the door is completely closed. //post-conditions: the value of door is changed if the door is not completely closed. The value of door is not changed if the door is completely closed and close is set to be 1. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
7
CS3369 Realtime Control Computer Software/DENG Xiaotie
Design of the Elevator The main function test if the elevator need to be stopped if yes, call stop() test if the elevator need to move if yes, (a) call close(), and then change the position oof the elevator, i.e., k=k-1 or k=k-1. Selevator(); delay(300); erease(); repeat 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
8
CS3369 Realtime Control Computer Software/DENG Xiaotie
OO Programming with C++ ADT: abstract data types: programmer using the data type does not have access to details of how the values and operations are implemented. interface:how to use ADT (for user) implementation: how the interface is is realized as C++ code. tips: hide member variables as private access functions to access necessary data. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
9
CS3369 Realtime Control Computer Software/DENG Xiaotie
Programming Practice Art ? Science? Programming languages change all the time, focusing on different aspects of programming techniques. Even Experts do not agree on details of programming style. E.g., How to pair up parenthesis {}? Do we line them up on the same column? Do we indent every pair which encloses an inner loop. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
10
CS3369 Realtime Control Computer Software/DENG Xiaotie
Programming Practice Criteria: reliable maintainable user friendly re-usability Good programming techniques are language independent. However, OO Languages provide useful tools to make it easier. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
11
CS3369 Realtime Control Computer Software/DENG Xiaotie
Readability and comprehensibility Naming named entities in programs: constants, variables, classes, objects, functions, files use meaningful names: names of objects should be closely related to the corresponding real world entities use more than one word, upper and lower case, delimiter characters avoid: ambiguities, cryptic abbreviations, unrelated names, single-letter identifies 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
12
CS3369 Realtime Control Computer Software/DENG Xiaotie
Readability and comprehensibility Divide Program into logically meaningful groups: class/object: for logically related entities functions: important/related pieces of program files: related functions and classes. Write pre-conditions and post-conditions in comments for function prototypes/function bodies. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
13
CS3369 Realtime Control Computer Software/DENG Xiaotie
Readability and comprehensibility Use indentations (consistently and correctly) to indicate program structures Use header file to define classes and prototype member functions store constants and global variables Use Makefile to compile programs in different files and organize team project. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
14
CS3369 Realtime Control Computer Software/DENG Xiaotie
Debugging/Testing/Checking Debugging: Try to locate errors: Grammar Errors: Run Time Errors: Testing: Searching for errors. developer tests (gently) for delivery of good product. expert tester tries to break product for quality guarantee. Checking: Make sure the output for an input is OK an extra function accompanying a function which checks for correctness of the output for every run of the function. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
15
CS3369 Realtime Control Computer Software/DENG Xiaotie
Debugging Grammar Errors: Usually a good programming language comes with compiler tools which locate (usually the first occurrence of) errors. Run Time Errors. Tools in Turbo C: trace: statements are executed line by line break point: execution stops at the line a break point is set Print-out statements: print out values of certain variables to see if execution goes as expected 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
16
CS3369 Realtime Control Computer Software/DENG Xiaotie
Debugging: An Example original function: int summation(int x, int y) { int z; z=x-y; return z} printout statements added to DEBUG: int z; cout<<“x=“ <<x<< “y=“ <<y<<endl; z=x-y; cout << “z=“ << z; 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
17
CS3369 Realtime Control Computer Software/DENG Xiaotie
Testing Testing process: top-down testing bottom-up testing real-time thread testing White Box Testing: knowing all codes and apply path testing exhaustive testing: make sure all paths are executed at least once selective testing: chooses some paths to test Black Box Testing: compare the output of the program with the expected output for many inputs. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
18
CS3369 Realtime Control Computer Software/DENG Xiaotie
Testing Process Top-down testing: usually for functionality Test in order of top level system, sub-system, module... Bottom-up testing test functions at the lowest level and work up hierarchy Real-time thread testing real time systems consist of co-operating processes and maybe interrupt driven external events may cause control transfers. thread testing identifies and executes each possible thread (of control flow of processes.) 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
19
CS3369 Realtime Control Computer Software/DENG Xiaotie
Input Data for Testing Choose input data according to the empirical distribution Choose degenerated patterns of data For the example of sorting function: all data are the same value input of size 0/1/2 Choose simple patterns of data input already sorted input are reversals of a sorted list 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
20
CS3369 Realtime Control Computer Software/DENG Xiaotie
Checking Make sure the output for an input is OK Write a checker function accompanying a function which checks for correctness of the output Invoke the checker function for every run of the original function. For the sorting function as an example: write an function to check the output of the sorting function is indeed sorted and check if the output data are the same as the input data 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
21
CS3369 Realtime Control Computer Software/DENG Xiaotie
An Example for Checking sort(A,n) {old_sort(A,n); //input is an array A of size n and output //is in the same array A but sorted. if (!check(A,n)) report-error();} int check(A,n) { int I; if (n==1) return TRUE; for (I=0; I<n-1; I++) { if A[I]>A[I+1] return FALSE;} return TRUE; } //here we only check A is sorted. In reality //we need also check the output array contains the same //set of elements as the input. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
22
CS3369 Realtime Control Computer Software/DENG Xiaotie
An Example for Checking max(A,n) {int tmp; tmp=old_max(A,n); if (!checkmax(tmp,A,n)) report-error();} int check(int a, int A[], int n) { int I; if (n==1) return TRUE; for (I=0; I<n-1; I++) { if A[I]>a return FALSE;} return TRUE; } 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
23
CS3369 Realtime Control Computer Software/DENG Xiaotie
Another Example for Global Variables The roots of a quadric equation ax2+bx+c=0 are x1= (-b+( b2-4ac))/2ac x2=x1= (-b- ( b2-4ac))/2ac include<iostream.h> float x1, x2; int flag=0; void roots(float a, float b, float c) void main(void) { roots(1.0,2.0, 1.0); if(flag == 0) cout<<“The roots are”<<x1<<x2; else cout<<“No real root”; } void roots(float a, float b, float c) { if (b*b-4*a*c>=0) x1=(-b+sqrt(b*b-4*a*c))/(2*a*c); x2 =(-b-sqrt(b*b-4*a*c))/(2*a*c); } else flag=1; x1, x2 and flag are used as global variables. Otherwise, roots must return two values that we do not know how to do it. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
24
CS3369 Realtime Control Computer Software/DENG Xiaotie
More about Equation Write a function that returns two roots of an equation ax2 +bx +c =0. Write a function that checks if the roots a correct. 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
25
CS3369 Realtime Control Computer Software/DENG Xiaotie
Documentation: Description of control software system functional specification design specification system manuel: for system maintenance people detailed description of system structure/component user manuel how system is to be operated written at the level of expertise of the operator system integration tests and test results: 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
26
Does it kill some stones?
Flow Chart Beginning of game: display the board Player 2’s next move Display the new board yes no Player 1’s next move Does it kill some stones? resign End of the Game Display the new move Choose a move yes no Note: only flow chart of player 1 is displayed and that of player 2 is similar. Is it legal 4/16/2019 CS3369 Realtime Control Computer Software/DENG Xiaotie
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.