{"id":21073670,"url":"https://github.com/chouffe/quickcheck-demo","last_synced_at":"2025-03-14T03:21:04.073Z","repository":{"id":148674494,"uuid":"65952703","full_name":"Chouffe/quickcheck-demo","owner":"Chouffe","description":"Learning Lunch @Airbnb","archived":false,"fork":false,"pushed_at":"2016-08-18T00:59:30.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T22:22:44.561Z","etag":null,"topics":["haskell","property-based-testing","quickcheck","testing"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Chouffe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-18T00:51:49.000Z","updated_at":"2017-07-07T05:16:58.000Z","dependencies_parsed_at":"2023-05-28T15:30:14.976Z","dependency_job_id":null,"html_url":"https://github.com/Chouffe/quickcheck-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chouffe%2Fquickcheck-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chouffe%2Fquickcheck-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chouffe%2Fquickcheck-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chouffe%2Fquickcheck-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chouffe","download_url":"https://codeload.github.com/Chouffe/quickcheck-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243515511,"owners_count":20303258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haskell","property-based-testing","quickcheck","testing"],"created_at":"2024-11-19T19:01:35.397Z","updated_at":"2025-03-14T03:21:04.043Z","avatar_url":"https://github.com/Chouffe.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Haskell Quickcheck Demo: Learning Lunch\n\n## Introduction\n\nQuickCheck is a library for random testing of program properties.\nIt is one of the best and most popular libraries that the Haskell ecosystem provides. It takes testing to an other level.\n\nWriting unit tests is boring and does not give strong correctness confidence unless all edge cases have been thoroughly studied and specced out. It takes time and it is impossible to cover the whole input space for a given program... Quickcheck addresses this problem :-)\n\nHaskell already provides a beautiful and powerful type system that help catch type related bugs at compile time (unlike Java for instance).\nQuickcheck generates tests for testing correctness of a given program.\n\nThe programmer provides a specification of the program, in the form of properties which functions should satisfy, and QuickCheck then tests that the properties hold in a large number of randomly generated cases.\n\n## Properties\n\nThe first step to testing with Quickcheck is to work out some properties that are true of the function for ALL inputs.\nSome invariants need to be found (see examples below)\n\nExamples:\n```\n-- Commutativity of `+`\n∀ a, b, a + b = b + a\n```\n\n```\n-- Transitivity of `\u003c`\n∀ x, y, z st x \u003c y  and y \u003c z, x \u003c z\n```\n\n```\n-- reverse is its own inverse\nreverse . reverse == identity\n```\n\n```\n-- Idempotence\nsort . sort = sort\n```\n\n```\n-- Constraints on length\n∀ n, xs, length (take n xs) \u003c= length xs\n```\n\n```\n-- And so on... Be creative (and use math ^^)\n```\n\n## Tests Generation\n\nGiven a property and a number of test cases to generate, QuickCheck will test the property on randomely generated input elements.\nRunning the property against a large number of different input elements give very STRONG confidence that the program is correct.\n\nRegular Unit testing does only test one specific input element for the given program. What if you forgot an edge case in your Unit Tests? What is the confidence that your program is CORRECT? Almost none... :(\n\n## Quickcheck Steps\n\n1. Input generation\n2. Property Testing\n    + If failed: will shrink the input elements as much as possible until it cannot shrink further\n    + If succeeded go to 1\n\n## How practical is Quickcheck?\n\nWriting programs that satisfy invariants and properties lead to extremely clean, composable, reusable code. Mixing TDD with Quickcheck is a very good way of keeping high code quality.\nQuickcheck can find bugs that you'd never thought of.\n\nUnit tests are still needed in practice when some properties cannot be defined for a given program.\n\n## Conclusion\n\n`Do not write tests, generate them!`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchouffe%2Fquickcheck-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchouffe%2Fquickcheck-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchouffe%2Fquickcheck-demo/lists"}