Giter Club home page Giter Club logo

propcheck's Introduction

Exhaustive and Randomized Testing

A library for exhaustive and randomized testing of Dart properties, based on enumerators. It is inspired by Haskell's smallcheck and quickcheck. If you don't know these libraries, have a look at the small demo below to get an idea of what it can be useful for. I also wrote a post that goes into more details.

Documentation

The only documentation so far is this README and the API reference.

Quick Start

import 'dart:collection';
import 'package:propcheck/propcheck.dart';
import 'package:enumerators/combinators.dart' as c;
import 'package:unittest/unittest.dart';

// defines append and reverse
part 'demolib.dart';

/* --- the properties to test --- */

// this should always hold
bool good(List xs, List ys) =>
    equals(reverse(append(xs, ys)),
           append(reverse(ys), reverse(xs)));

// this should NOT always hold
bool bad(List xs, List ys) =>
    equals(reverse(append(xs, ys)),
           append(reverse(xs), reverse(ys)));

/* --- how we test them --- */

main() {
  // we define an enumeration of lists of integers
  final boolsLists = c.listsOf(c.bools);

  // 'good' and 'bad' take 2 arguments each so we use forall2
  Property goodProperty = forall2(boolsLists, boolsLists, good);
  Property badProperty = forall2(boolsLists, boolsLists, bad);

  // we test the properties against *every* pair of lists of bools whose
  // combined size is <= 10.
  group('smallcheck', () {
    final sc = new SmallCheck(depth: 10);
    test('good', () => sc.check(goodProperty));
    test('bad', () => sc.check(badProperty));
  });

  // we test the properties against random pairs of lists of bools of
  // combined size 0, 1, ..., 300.
  group('quickcheck', () {
    final qc = new QuickCheck(maxSize: 300, seed: 42);
    test('good', () => qc.check(goodProperty));
    test('bad', () => qc.check(badProperty));
  });
}

Output:

unittest-suite-wait-for-done
PASS: smallcheck good
FAIL: smallcheck bad
  Caught falsified after 11 tests
    argument 1: [true]
    argument 2: [false]
  
  [...]
  
PASS: quickcheck good
FAIL: quickcheck bad
  Caught falsified after 5 tests
    argument 1: [false]
    argument 2: [false, false, true]
  
  [...]

2 PASSED, 2 FAILED, 0 ERRORS

Try it!

git clone https://github.com/polux/propcheck
cd propcheck
pub get
dart example/demo.dart

Enjoy the progress indicator, probably the most elaborate part of this library :)

propcheck's People

Contributors

polux avatar stargator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

propcheck's Issues

Dart 2 compatibility

Hi and thanks for propcheck! I use it in the majority of the test suites in https://github.com/spebbe/dartz/ and also at work.

I'm currently in the process of developing a Dart 2-compatible version of dartz, fixing the things that can be fixed and removing the things that cannot be salvaged. It would be fantastic to be able to continue to use propcheck for the tests, but currently both propcheck and enumerators fail to run on the Dart 2 VM (as of 2.0.0-dev.66.0) with full runtime type checks enabled.

Do you have plans to release a Dart 2 compatible version? No pressure :-)

Thanks,

/Björn

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.