1 / 26

11.1 Designing Issues 11.2 Debugging 11.3 Testing 11.4 Checking 11.5 Documentation

Lecture 11. Design, Testing and Documentation. 11.1 Designing Issues 11.2 Debugging 11.3 Testing 11.4 Checking 11.5 Documentation. Designing. Top-down Design in OOP Data abstraction classes and objects member functions hide data as private Polymorphism

doster
Download Presentation

11.1 Designing Issues 11.2 Debugging 11.3 Testing 11.4 Checking 11.5 Documentation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 11. Design, Testing and Documentation • 11.1 Designing Issues • 11.2 Debugging • 11.3 Testing • 11.4 Checking • 11.5 Documentation CS3369 Realtime Control Computer Software/DENG Xiaotie

  2. 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 CS3369 Realtime Control Computer Software/DENG Xiaotie

  3. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  4. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  5. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  6. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  7. 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 CS3369 Realtime Control Computer Software/DENG Xiaotie

  8. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  9. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  10. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  11. 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 CS3369 Realtime Control Computer Software/DENG Xiaotie

  12. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  13. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  14. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  15. 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 CS3369 Realtime Control Computer Software/DENG Xiaotie

  16. Debugging: An Example • original function: • int summation(int x, int y) { • int z; • z=x-y; • return z} • printout statements added to DEBUG: • int summation(int x, int y) { • int z; cout<<“x=“ <<x<< “y=“ <<y<<endl; • z=x-y; cout << “z=“ << z; • return z} CS3369 Realtime Control Computer Software/DENG Xiaotie

  17. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  18. 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.) CS3369 Realtime Control Computer Software/DENG Xiaotie

  19. 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 • For the example of sorting function: • input already sorted • input are reversals of a sorted list CS3369 Realtime Control Computer Software/DENG Xiaotie

  20. 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 CS3369 Realtime Control Computer Software/DENG Xiaotie

  21. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  22. 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; } CS3369 Realtime Control Computer Software/DENG Xiaotie

  23. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  24. 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. CS3369 Realtime Control Computer Software/DENG Xiaotie

  25. 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: CS3369 Realtime Control Computer Software/DENG Xiaotie

  26. 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 CS3369 Realtime Control Computer Software/DENG Xiaotie

More Related