Software Testing with QuickCheck Lecture 1 Properties and Generators.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Simplifications of Context-Free Grammars
1
Chapter 26 Testing Bjarne Stroustrup
Processes and Operating Systems
STATISTICS POINT ESTIMATION Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National Taiwan University.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Objectives: Generate and describe sequences. Vocabulary:
Document #07-2I RXQ Customer Enrollment Using a Registration Agent (RA) Process Flow Diagram (Move-In) (mod 7/25 & clean-up 8/20) Customer Supplier.
XP New Perspectives on Microsoft Office Word 2003 Tutorial 6 1 Microsoft Office Word 2003 Tutorial 6 – Creating Form Letters and Mailing Labels.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Local Customization Chapter 2. Local Customization 2-2 Objectives Customization Considerations Types of Data Elements Location for Locally Defined Data.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Wants.
Lecture 2 ANALYSIS OF VARIANCE: AN INTRODUCTION
Modelling & Datatypes John Hughes. Software Software = Programs + Data.
Chapter 7 Sampling and Sampling Distributions
The 5S numbers game..
Proud Members of the Consulting Group, LLC
Order of Operations Lesson
1 SESSION 5- RECORDING AND REPORTING IN GRADES R-12 Computer Applications Technology Information Technology.
Configuration management
1 Refactoring with Contracts Shmuel Tyszberowicz School of Computer Science The Academic College of Tel Aviv Yaffo Maayan Goldstein School of Computer.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
Red Tag Date 13/12/11 5S.
Software testing.
Statistics and Data Analysis Professor William Greene Stern School of Business IOMS Department Department of Economics.
PP Test Review Sections 6-1 to 6-6
Chapter 17 Linked Lists.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
DATA STRUCTURES AND ALGORITHMS Prepared by İnanç TAHRALI
Chapter 24 Lists, Stacks, and Queues
11 Data Structures Foundations of Computer Science ã Cengage Learning.
Multicore Programming Skip list Tutorial 10 CS Spring 2010.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Short seed extractors against quantum storage Amnon Ta-Shma Tel-Aviv University 1.
1 Designing Hash Tables Sections 5.3, 5.4, Designing a hash table 1.Hash function: establishing a key with an indexed location in a hash table.
Hash Tables.
1 Lecture 16: Tables and OOP. 2 Tables -- get and put.
INTRODUCTION Lesson 1 – Microsoft Word Word Basics
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
Lilian Blot PART III: ITERATIONS Core Elements Autumn 2012 TPOP 1.
Chapter 10 Software Testing
Slide R - 1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Prentice Hall Active Learning Lecture Slides For use with Classroom Response.
Subtraction: Adding UP
Lilian Blot CORE ELEMENTS SELECTION & FUNCTIONS Lecture 3 Autumn 2014 TPOP 1.
Converting a Fraction to %
An Interactive Tutorial by S. Mahaffey (Osborne High School)
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Exception Handling Outline 13.1 Introduction 13.2 Exception-Handling Overview 13.3 Other.
1 Atlas Copco Distribution Center DS Connect User’s Guide This document is uncontrolled if viewed or printed outside the IMS.
Median and Mode Lesson
User Defined Functions Lesson 1 CS1313 Fall User Defined Functions 1 Outline 1.User Defined Functions 1 Outline 2.Standard Library Not Enough #1.
Distributed Computing 5. Snapshot Shmuel Zaks ©
SAT Solver CS 680 Formal Methods Jeremy Johnson. 2 Disjunctive Normal Form  A Boolean expression is a Boolean function  Any Boolean function can be.
Software Testing and Quality Assurance
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Testing a Media Proxy with … QuickCheck Thomas Arts John Hughes Chalmers/ITU Joakim Johansson Ulf Wiger Ericsson.
Erlang/QuickCheck Thomas Arts, IT University John Hughes, Chalmers University Gothenburg.
(or what I learned from Neil about software testing) John Hughes Chalmers University/Quviq AB.
Testing in Erlang. Different testing tools EUnit (standard lightweight xUnit solution for Erlang) Common Test (OTP based distributed testing tool) Qucik.
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
Scientific Debugging. Errors in Software Errors are unexpected behaviors or outputs in programs As long as software is developed by humans, it will contain.
Function Definition by Cases and Recursion Lecture 2, Programmeringsteknik del A.
TESTING FUNDAMENTALS BY K.KARTHIKEYAN.
1 Logic Our ability to state invariants, record preconditions and post- conditions, and the ability to reason about a formal model depend on the logic.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
Introduction To Repetition The for loop
Test Data Generators.
Presentation transcript:

Software Testing with QuickCheck Lecture 1 Properties and Generators

Testing How do we know software works? – We test it! lists:delete removes an element from a list … seems to work! 4> lists:delete(2,[1,2,3]). [1,3] 5> lists:delete(4,[1,2,3]). [1,2,3]

Automated Testing Testing accounts for ~50% of software cost! Automate it… write once, run often delete_present_test() -> lists:delete(2,[1,2,3]) == [1,3]. delete_absent_test() -> lists:delete(4,[1,2,3]) == [1,2,3]. Lots of code (35%) Boring Easy to miss something

Property-based testing Generalise test cases prop_delete() -> ?FORALL({I,L}, {int(),list(int())}, not lists:member(I, lists:delete(I,L))). prop_delete() -> ?FORALL({I,L}, {int(),list(int())}, not lists:member(I, lists:delete(I,L))). prop_delete() -> ?FORALL({I,L}, {int(),list(int())}, not lists:member(I, lists:delete(I,L))). prop_delete() -> ?FORALL({I,L}, {int(),list(int())}, not lists:member(I, lists:delete(I,L))). prop_delete() -> ?FORALL({I,L}, {int(),list(int())}, not lists:member(I, lists:delete(I,L))). 21> eqc:quickcheck(examples:prop_delete()) OK, passed 100 tests

Properties We test directly against a formal specification ?FORALL(N, int(), N*N >= 0) Bound variable Test case generator Test oracle

More tests… 29> eqc:quickcheck( eqc:numtests(1000, examples:prop_delete() ) ) Failed! After 346 tests. {2,[-7,-13,-15,2,2]} Shrinking.(1 times) {2,[2,2]} false A failed test c.f. ?FORALL({I,L},…,…) A simplest failing test

The fault explained lists:delete(2,[2,2]) [2]lists:member(2,[2]) true not true false

Properties with preconditions The property holds provided L contains no duplicates prop_delete() -> ?FORALL({I,L}, {int(),list(int())}, ?IMPLIES(no_duplicates(L), not lists:member(I,lists:delete(I,L)))). no_duplicates(L) -> lists:usort(L) == lists:sort(L). 39> eqc:quickcheck(examples:prop_delete()) x x x.x......xx x....x....xx....x..x x. x x.. OK, passed 100 tests Skipped tests

Custom generators Why not generate lists without duplicates in the first place? Use as ?FORALL(L,ulist(int()),…) Generators are an abstract data type with ?LET for sequencing ulist(Elem) -> ?LET(L,list(Elem), lists:usort(L)). First: generate a list L Then: sort it and remove duplicates

Why was the error hard to find? I ε int() L ε list(int()) What is the probability that I occurs in Ltwice? prop_delete() -> ?FORALL({I,L}, {int(),list(int())}, collect(lists:member(I,L), not lists:member(I,lists:delete(I,L))). 34> eqc:quickcheck(examples:prop_delete()) OK, passed 100 tests 88% false 12% true true Usually I doesnt even occur once

Generate relevant tests Ensure that I is a member of L – Generate it from L prop_delete_2() -> ?FORALL(L,list(int()), ?IMPLIES(L /= [], ?FORALL(I,elements(L), not lists:member(I,lists:delete(I,L)) )). prop_delete_2() -> ?FORALL(L,list(int()), ?IMPLIES(L /= [], ?FORALL(I,elements(L), not lists:member(I,lists:delete(I,L)) )). 45> eqc:quickcheck(examples:prop_delete_2())..xx.x.x.xx...x.x...x....x xx.....Failed! After 28 tests. [-8,0,7,0] 0 Shrinking...(3 times) [0,0] 0

Documenting misconceptions Useful to record that an expected property is not true prop_delete_misconception() -> fails( ?FORALL(L,list(int()), ?IMPLIES(L /= [], ?FORALL(I,elements(L), not lists:member(I,lists:delete(I,L))))) ). 49> eqc:quickcheck(examples:prop_delete_misconception()). x...x.x....x OK, failed as expected. After 19 tests. Good distribution ensures we falsify the property quickly

Remember! We test against a formal specification! – Often it is the specification which is wrong! We dont see the test data! – 100 passing tests can give a false sense of security Collect statistics! – Ensure a good test case distribution

Exercises