Giter Club home page Giter Club logo

crabcheck's Introduction

Crabcheck

A WIP property-based testing library in Rust, built with generalized targeted-property testing in mind.

What is property-based testing?

TODO

Example usage

use crabcheck::quickcheck::quickcheck;

fn correct_insertion_sort(arr: &mut [i32]) {
    for i in 1..arr.len() {
        let mut j = i;
        while j > 0 && arr[j - 1] > arr[j] {
            arr.swap(j - 1, j);
            j -= 1;
        }
    }
}

fn bugged_insertion_sort(arr: &mut [i32]) {
    for i in 1..arr.len() - 1 {
        let mut j = i;
        while j > 0 && arr[j - 1] > arr[j] {
            arr.swap(j - 1, j);
            j -= 1;
        }
    }
}

fn is_sorted(array: &[i32]) -> bool {
    array.windows(2).all(|window| window[0] <= window[1])
}

fn main() {
    let should_work = quickcheck(|input: &mut Vec<i32>| {
        correct_insertion_sort(input);
        is_sorted(input)
    });
    assert!(should_work.counterexample.is_none());

    let should_fail = quickcheck(|input: &mut Vec<i32>| {
        bugged_insertion_sort(input);
        is_sorted(input)
    });
    assert!(should_fail.counterexample.is_some());

    println!(
        "Counterexample that doesn't work on buggy implementation: {:?}",
        should_fail.counterexample.unwrap(),
    );
}

crabcheck's People

Contributors

alpaylan avatar umut-sahin avatar

Stargazers

Ali Anıl Hazar avatar Jiefeng Li avatar Hamza Erbay avatar Guray Gurkan avatar  avatar Hüseyin Okan Soykam avatar  avatar Ozan Sazak avatar Emre Güllü avatar

Watchers

 avatar  avatar

Forkers

umut-sahin

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.