Simulation and Example

Slides:



Advertisements
Similar presentations
Object Oriented Analysis And Design-IT0207 iiI Semester
Advertisements

Testing Relational Database
Software Testing. Quality is Hard to Pin Down Concise, clear definition is elusive Not easily quantifiable Many things to many people You'll know it when.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
Software Engineering-II Sir zubair sajid. What’s the difference? Verification – Are you building the product right? – Software must conform to its specification.
ISBN Chapter 3 Describing Syntax and Semantics.
ITEC200 Week02 Program Correctness and Efficiency.
Program Correctness and Efficiency Chapter 2. Chapter 2: Program Correctness and Efficiency2 Chapter Objectives To understand the differences between.
Program Correctness and Efficiency Chapter 2. Chapter Objectives  To understand the differences between the three categories of program errors  To understand.
Program Testing Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
16/27/2015 3:38 AM6/27/2015 3:38 AM6/27/2015 3:38 AMTesting and Debugging Testing The process of verifying the software performs to the specifications.
Testing an individual module
Describing Syntax and Semantics
Chapter 6 Control Statements Continued
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Program Correctness and Efficiency Chapter 2 Chapter 2: Program Correctness and Efficiency2 Chapter Objectives To understand the differences between.
Fall 2007CS 225 Program Correctness and Efficiency Chapter 2.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
1 Shawlands Academy Higher Computing Software Development Unit.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Software Testing.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
1 C++ Plus Data Structures Nell Dale Chapter 1 Software Engineering Principles Modified from the Slides made by Sylvia Sorkin, Community College of Baltimore.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
The Software Development Process
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Chapter 6 Control Statements Continued
Chapter 1 Software Engineering Principles. Problem analysis Requirements elicitation Software specification High- and low-level design Implementation.
Dynamic Testing.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
CIS 068 Welcome to CIS 068 ! Lesson 3: Algorithm Correctness And Efficiency.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Testing i. explain the importance of system testing and installation planning;
1 Sections 7.2 – 7.7 Nested Control Statements Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Principles of Programming & Software Engineering
Software Testing.
Testing Tutorial 7.
Software Testing.
C++ Plus Data Structures
Chapter 6: Modular Programming
Testing and Debugging.
Loop Structures.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Lecture 09:Software Testing
Verification and Validation Unit Testing
Testing and Test-Driven Development CSC 4700 Software Engineering
Algorithm Correctness
Chapter 15 Debugging.
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Program Correctness and Efficiency
CSE 1020:Software Development
CHAPTER 6 Testing and Debugging.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Presentation transcript:

Simulation and Example

Simulation Simulation is used to study the performance of a physical system by using a physical, mathematical, or computer model of the system Steps to take when you do simulation Algorithm Programming techniques and coding Testing

Simulation Simulation is used to study the performance of a physical system by using a physical, mathematical, or computer model of the system Steps to take when you do simulation Algorithm Programming techniques and coding Testing

Example Write a program that simulates the operation of a busy airport that only has one run way to handle takeoff and landings. You may assume that each takeoff or landing takes 15 minutes to complete. One runway request is made during each 5 minute time interval and the likelihood of a landing request is the same as for a takeoff request. Priority is given to planes requesting a landing. If a request can not be honored, it is added to a takeoff or landing queue. This program should simulate 120 minutes of activity at the airport. Each request for runway clearance should be time- stamped to the appropriate queue. The output from your program should include the final queue contents, the number of takeoffs completed, the number of landings completed and the average number of minutes spent in each queue

Part 1: Determine Main Algorithm Clock < Total time? Clock =0 Total time = 120 Time done=0 Start No stop Yes Toss a coin Head? No Check takeoff arrival Clock += 5 Yes Check landing arrival Yes Current serve done? Serve the next one No

Part 2: Determine main data structure Queue: Takeoff Landing That queue has every attribute/action that a normal queue has and the following special attributes/actions Number of takeoff or landing served Total time wait Check new arrival in landing or takeoff queues Update statistics

Part 2: Determine main data structure Request: processingTime arrivalTime (may be requestID)

Part 3: Make the main algorithm more specific Check takeoff or landing arrival Given an arrival time Create a new request Print status for each queue

Part 3: Make the algorithm more specific Serve the next one Landing queue is NOT empty Yes currentRequest = get the first element in the landing queue No Takeoff queue is NOT empty Current request = get the first request in the takeoff queue Timestamp = get arrival time of current request Yes Wait =current clock - timestamp No The run way is idle now TotalWait +=wait Number of landing/takeoff served ++

Implementation Classes: Queue (Using Lab3Queue with just a little bit change in Lab1LinkedList) Request RunawayQueue (extends from Queue) AirportSim that actually starts the simulation and contain the main algorithm.

Testing Discussion: How can we test this simulation program: Criteria: Robustness: not crashing Accuracy: correctly computed

Testing Unit test Integration test Make sure Queue is working, RunawayQueue is working and Request is working correctly Integration test Test if AirportSim is working correctly Leave a trace of execution by displaying the method name as you enter it Display values of all input parameters upon entry to a method

Testing Programs There is no guarantee that a program that is syntax and run-time error free will also be void of logic errors The “best” situation is a logic error that occurs in a part of the program that always executes; otherwise, it may be difficult to find the error The worst kind of logic error is one that occurs in an obscure part of the code (infrequently executed) Chapter 2: Program Correctness and Efficiency

Structured Walkthroughs Most logic errors arise during the design phase and are the result of an incorrect algorithm Logic errors may also result from typographical errors that do not cause syntax or run-time errors One form of testing is hand-tracing the algorithm before implementing Structured walkthrough: designer must explain the algorithm to other team members and simulate its execution with other team members looking on Chapter 2: Program Correctness and Efficiency

Levels and Types of Testing Testing: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects after all syntax errors have been removed and the program compiles No amount of testing can guarantee the absence of defects in sufficiently complex programs Unit testing: checking the smallest testable piece of the software (a method or class) Integration testing: testing the interactions among units Chapter 2: Program Correctness and Efficiency

Levels and Types of Testing (continued) System testing: testing the program in context Acceptance testing: system testing designed to show that the program meets its functional requirements Black-box testing: tests the item based on its interfaces and functional requirements White-box testing: tests the software with the knowledge of its internal structure Chapter 2: Program Correctness and Efficiency

Preparations for Testing A test plan should be developed early in the design phase Aspects of a test plan include deciding how the software will be tested, when the tests will occur, who will do the testing, and what test data will be used If the test plan is developed early, testing can take place concurrently with the design and coding A good programmer practices defensive programming and includes code to detect unexpected or invalid data Chapter 2: Program Correctness and Efficiency

Testing Tips for Program Systems Most of the time, you will test program systems that contain collections of classes, each with several methods If a method implements an interface, its specification should document input parameters and expected results Carefully document each method parameter and class attribute using comments as you write the code Leave a trace of execution by displaying the method name as you enter it Display values of all input parameters upon entry to a method Chapter 2: Program Correctness and Efficiency

Testing Tips for Program Systems (continued) Display the values of any class attributes that are accessed by this method Display the values of all method outputs after returning from a method Plan for testing as you write each module rather than after the fact Chapter 2: Program Correctness and Efficiency

Developing the Test Data Test data should be specified during the analysis and design phases for the different levels of testing: unit, integration, and system In black-box testing, we are concerned with the relationship between the unit inputs and outputs There should be test data to check for all expected inputs as well as unanticipated data In white-box testing, we are concerned with exercising alternative paths through the code Test data should ensure that all if statement conditions will evaluate to both true and false Chapter 2: Program Correctness and Efficiency

Testing Boundary Conditions When hand-tracing through an algorithm or performing white-box testing, you must exercise all paths Check special cases called boundary conditions Chapter 2: Program Correctness and Efficiency

Why do Testing? Normally testing is done by The programmer Other members of the software team who did not code the module being tested Final users of the software product Do not rely on programmers for testing as they are often blind to their own oversights Companies also have quality assurance organizations that verify that the testing process is performed correctly In extreme programming, programmers work in pairs where one writes the code and the other writes the tests Chapter 2: Program Correctness and Efficiency

Stubs It may be difficult to test a method or class that interacts with other methods or classes The replacement of a method that has not yet been implemented or tested is called a stub A stub has the same header as the method it replaces, but its body only displays a message indicating that the stub was called Chapter 2: Program Correctness and Efficiency

Drivers A driver program declares any necessary object instances and variables, assigns values to any of the method’s inputs, calls the method, and displays the values of any outputs returned by the method You can put a main method in a class to serve as the test driver for that class’s methods Chapter 2: Program Correctness and Efficiency

Using a Test Framework A test framework is a software product that facilitates writing test cases, organizing the test cases into test suites, running the test suites, and reporting the results A test framework often used for Java products is JUnit, an open-source product that can be used in a stand-alone mode and is available from junit.org Chapter 2: Program Correctness and Efficiency

Debugging a Program Debugging is the major activity performed by programmers during the testing phase Testing determines if there is an error, debugging determines the cause of it Debugging is like detective work Inspect carefully the information displayed by your program Insert additional diagnostic output statements in the method to determine more information Chapter 2: Program Correctness and Efficiency

Using a Debugger Debuggers often are included with IDEs A debugger can execute your program incrementally rather than all at once Single-step execution executes in increments as small as one program statement Breakpoints are used to traverse large portions of code before stopping The actual mechanics of using a debugger depend on the IDE that you are using Chapter 2: Program Correctness and Efficiency

Using a Debugger (continued) Chapter 2: Program Correctness and Efficiency

Reasoning about Programs: Assertions and Loop Invariants Assertions: logical statements about a program that are claimed to be true; generally written as a comment Preconditions and postconditions are assertions A loop invariant is an assertion Helps prove that a loop meets it specification True before loop begins, at the beginning of each repetition of the loop body, and just after loop exit Chapter 2: Program Correctness and Efficiency

Efficiency of Algorithms Difficult to get a precise measure of the performance of an algorithm or program Can characterize a program by how the execution time or memory requirements increase as a function of increasing input size Big-O notation A simple way to determine the big-O of an algorithm or program is to look at the loops and to see whether the loops are nested Chapter 2: Program Correctness and Efficiency

Efficiency of Algorithms (continued) Chapter 2: Program Correctness and Efficiency