Giter Site home page Giter Site logo

qt-workshop's Introduction

qt-workshop

The purpose of this workshop is to introduce Property Based Testing with Quick Theories. The workshop is based off of the Kata on Chapter 6 of Property-Based Testing with PropEr, Erlang, and Elixir by Fred Hebert. I highly recommend this book.

The Kata

Given the following table:

Item Unit Price Special Price
A 50 3 for 130
B 30 2 for 45
C 20
D 15

Given a item price catalog, when given a list of items to purchase, then calculate the total. This project provides a sample skeleton, but feel free to adjust the code as needed.

Vague Requirements:

  • Item names are unique
  • List of items have no set length
  • List of items are unordered
  • Unit prices are whole numbers
  • All items have a unit price
  • Special prices can be applied multiple times
  • Special prices are optional

Step 1: Identify the properties (5 minutes, +10 minute discussion)

Property based testing frameworks check the truthfulness of properties. A property is a statement like: for all (x, y, ...) such as precondition(x, y, ...) holds property(x, y, ...) is true. - fast-check docs

As a group, let's identify the properties of this function:

Things to look for

Here are some patterns from the Quick Theories documentation.

  • Invariant Pattern "Some things never change"
  • The inverse function pattern "There and back again"
  • Idempotence "The more things change, the more they stay the same"
  • Analogous function pattern "Different paths same destination"

Step 2: Creating generators (15 minutes, +10 minute discussion)

Working with the quick theories basic generators, complete the generator CartDSL.purchaseList to generate a list of items to purchase.

Step 3: Test the property & implement (15 minutes, +10 minute discussion)

Test the property where the cart total is the sum of the purchase list given all the products have no special prices.

  • Try configuring quick theories to run through more or fewer examples.

Step 4: Refactor generator to include expectation (5 minutes, +10 minute discussion)

Refactor the carts generator to produce a random cart and the appropriate expectation.

Discussion: Adding in special prices (15 minutes)

Extra: Negative Testing (15 minutes, +10 minute discussion)

  • Identify very, very broad properties
  • Apply very, very broad inputs to verify that the system doesn't crash

qt-workshop's People

Contributors

mr-rampage avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

timeapen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.