Sample Problems for Testing • For “Program” Level Testing: – Triangle – Next Date – Sales Commission • For “System” Level Testing: – – – – SATM system Currency conversion Windshield Wiper Garage Door Controller These 7 problems will be used throughout the remainder of the course as examples for different testing techniques 1. Triangle Problem • Problem (Requirements) Statement: – Write me a program that • will accept 3 numbers which represent the 3 sides of a triangle. Problem: • evaluate the inputs and determine if relating a) inputs to – – – – It is a triangle an isosceles triangle an equilateral triangle a scalene triangle b) outputs based on input validity & input relationship • Output the answer Look at this requirement statement and identify areas of potential problem if you were writing the program - - - anything more if you were testing this? (would you ensure that the outputs are tested via “partitioned” set?) Your textbook has an “improved” version of the requirement. 1. Triangle Problem • The triangle problem is the most widely used example in software testing literature. • Simple version: The triangle program accepts three integers, a, b, and c, as input. These are taken to be sides of a triangle. The output of the program is the type of triangle determined by the three sides: Equilateral, Isosceles, Scalene, or Not A Triangle. 1. Triangle Problem • Improved version: “Simple version” plus better definition of inputs: • The integers a, b, and c must satisfy the following conditions: • c1. 1 ≤ a ≤ 200 c4. a<b+c • c2. 1 ≤ b ≤ 200 c5. b<a+c • c3. 1 ≤ c ≤ 200 c6. c<a+b 1. Triangle Problem • If an input value fails any of conditions c1, c2, or c3, the program notes this with an output message, for example, “Value of b is not in the range of permitted values.” If values of a, b, and c satisfy conditions c1, c2, and c3, one of four mutually exclusive outputs is given: 1. If all three sides are equal, the program output is Equilateral. 2. If exactly one pair of sides is equal, the program output is Isosceles. 3. If no pair of sides is equal, the program output is Scalene. 4. If any of conditions c4, c5, and c6 is not met, the program output is NotATriangle 1. Triangle Problem Discussion • Problems persist! What output is expected for the input set (2, 2, 5)? • Isosceles because a = b? • NotATriangle because c > a+b? • Fix it (sometimes testers must also be specifiers!) • The Really Final Version: “Improved version” plus better definition of outputs. 2. Next Date Problem • Problem (Requirements) Statement: – Write me a program that • will accept 3 numbers which represent the day, month, and year of a calendar date • evaluate the inputs and determine – The next day of the date represented by the input • output the next day answer Problem: relating inputs to outputs based on input validity & input relationship & “complex” data relationships Look at this requirement statement and identify areas of potential problem if you were writing the program - - - anything more if you were testing this? 2. Next Date Problem • NextDate is a function of three variables: month, date, and year. It returns the date of the day after the input date. The month, date, and year variables have integer values subject to these conditions: • c1. 1 ≤ month ≤12 • c2. 1 ≤ day ≤ 31 • c3. 1812 ≤ year ≤ 2012 • If any of conditions c1, c2, or c3 fails, NextDate produces an output indicating the corresponding variable has an out-of-range value — for example, “Value of month not in the range 1..12”. Because numerous invalid day–month– year combinations exist, NextDate collapses these into one message: “Invalid Input Date.” 3. Monthly Sales Commission Problem • Problem (Requirements) Statement: – Write me a program that • will accept 3 numbers which represent the number of locks, number of stocks, and number of barrels of a riflesold at each town during the month • Will accept a number, -1, for locks to represent the “end” of monthly sales so sales commission can be computed • evaluate the inputs and determine the monthly sales commission as follows: – each lock price is $45; each stock price is $30; and each barrel price is $25 – sales person is paid 10% of total sales for the first $1000; 15% on the next $800; and 20% in excess of $1800 • output the sales commission • Some sales “limitations” exist Problem: Input – store - compute -output – Must sell one complete rifle – Monthly sales (production limit) must be: » # of locks <71 » # of stocks < 81 » # of barrels < 91 Look at this requirement statement and identify areas of potential problem if you were writing the program - - - anything more if you were testing this? 4. SATM System Problem • Problem (Requirements) Statement: – Develop part (a component) of an automatic teller system that: • • • • Displays a “welcome screen” with a simple instruction to insert ATM card Validates the ATM card. If invalid keeps it (with a message); otherwise goes on Asks for and validates a personal id number ( only up to 3 times) If valid, three “activity” options are presented: – Check the account balance – Withdraw from the account – Deposit into the account • Once the option is selected, the customer is presented with and asked to choose between a checking or a savings account • For each of these 3 optional activities the customer account file is also updated with – Date of ATM access and – Increment the number of times this account is accessed through ATM 4. SATM System Problem Welcome to Rock Solid Federal Credit Union Please insert your ATM card Printed Receipt 1 2 3 Card Slot 4 5 6 Enter 7 8 9 Clear 0 Cash Dispenser Cancel Deposit Slot 4. SATM System Problem (cont.) – Requirements (cont.) • If account balance is requested then a new balance is printed and the customer is given a choice for more activities. • For both withdrawal and deposit options, the customer is asked to key in the amount • For withdrawal, the minimum increment is $10. The customer account will be updated, and the customer will be asked to take the cash from the dispenser. In the event there is insufficient funds, the customer is asked to re-key an amount • For deposits, if the ATM terminal deposit is working (envelop exists and slot moves), then the customer is asked to place the deposit in an envelop and deposit through the ATM. Otherwise, the customer is told of the problem and given a choice of other options. • When customer activities are complete, a new balance is printed on the receipt and a choice for more activities is given. If the customer chooses more activity, he is returned to the 3 choices of activities again. • If the customer has no more activity then a message for customer to take both the receipt and the ATM card and the system ends. This testing would be closer to a component or system test, after each unit test is completed. How would divide the component into units for unit testing? 5. Currency Conversion Subsystem • Problem (Requirements) Statement: – Develop a GUI based sub-system that • will accept US currency and convert it to: – – – – Brazilian currency Canadian currency European community currency Japanese currency Note: more currencies than the textbook • use the exchange rate within the last 12 hours. • Also allow the “reverse currency” computation Look at this requirement statement and identify areas of potential problem if you were writing the program - - - anything more if you were testing this? 5. Currency Conversion Subsystem Currency Converter U.S. Dollar amount Equivalent in ... Brazil Compute Canada Clear European community Japan Quit 6. Saturn Windshield Wiper Controller • Problem (Requirements) Statement: – Write me an “embedded” program that • Controls the 4 speed settings of a windshield wiper: – – – – Off Intermittent Low High OFF -> Wiper does not move As a tester what needs to be considered? - if wiper is not moving, then ? • For “off”, the windshield wiper does not move • For Intermittent setting, there are 3 “dial” sub-settings: – 1 : wiper wipes 4 times per minute – 2: wiper wipes 6 times per minute – 3: wiper wipes 12 times per minute • For Low, the wiper wipes 30 times per minute • For High, the wiper wipes 60 times per minutes Look at this requirement statement and identify areas of potential problem if you were writing the program - - - anything more if you were testing this? 6. Saturn Windshield Wiper Controller c1. Lever OFF INT INT INT LOW HIGH c2. Dial n/a 1 2 3 n/a n/a 0 4 6 12 30 60 a1. Wiper speed is… 7. The Garage Door Controller (shown here as a SysML Context Diagram) Digit Keypad Portable Opener 48V DC Power Wall-mount button Light Beam Wireless Receiver Garage Door Controller Extreme Limit Sensor Drive Motor Lamp Obstacle (Resistance) Sensor 110V AC Power