Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Property-based testing: The lazy programmer's guide to writing thousands of tests

Property-based testing: The lazy programmer's guide to writing thousands of tests

Cc95ef8bf38403916f40854c4ede4853?s=128

Pierre GOUDJO

January 20, 2022
Tweet

More Decks by Pierre GOUDJO

Other Decks in Programming

Transcript

  1. Pierre Goudjo Property-based testing The lazy programmer's guide to writing

    thousands of tests
  2. “Real-life” Scenario

  3. None
  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  10. None
  11. None
  12. None
  13. None
  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. None
  22. None
  23. None
  24. None
  25. None
  26. Solution

  27. What’s an addition?

  28. None
  29. None
  30. Properties Addition • Associativity: x+(y+z) = (x+y)+z • Commutativity: x

    + y = y + x • Identity Element: x+0 = x
  31. This is property-based testing

  32. for any (x, y, …) such as precondition(x, y, …)

    holds property(x, y, …) is true
  33. Let’s implement this!!!!

  34. Is it useful?

  35. Avg • for any number (a and b ) •

    such a <= b • a <= avg(a, b) and avg(a, b) <= b • for any number (a and b ) • such a <= b • avg(a, b) == avg(a, b)
  36. Zip/Unzip • for any string (x) • such as x

    not “” • unzip(zip(x)) == x is true