Giter Club home page Giter Club logo

collection-check's Introduction

Clojure's default data structures are great, but sometimes the problems we're trying to solve call for something else. However, alternate data structures should still behave as much as possible like vectors, sets, or maps.

This library tests whether a given data structure is equivalent to whatever data structure it mimics, using test.check. This is both a validation that the data structure is correct and that it implements all necessary interfaces.

The methods exposed here are compatible with ClojureScript.

usage

Since this is only for testing, it should be added as a :dev dependency:

{:profiles {:dev {:dependencies [[collection-check "0.1.7"]]}}}

To validate a vector-like data structure, you can use (assert-vector-like empty-collection element-generator). For instance:

> (require '[collection-check :refer :all])
nil
> (assert-vector-like [] simple-check.generators/int)
true

We can also specify the number of tests we'd like to perform, which defaults to 1000:

> (assert-vector-like 1e5 [] simple-check.generators/int)
true

If the assertion fails, it will throw an exception describing the custom and reference collections, and the actions that were taken to reproduce this error:

 java.lang.Exception: Assert failed: (= a b)
  a = #{0 9 -10}
  b = #{0 9 -10}
  actions = (-> coll transient (conj! -10) persistent! transient (conj! 9) persistent! transient (disj! -10) persistent! (conj -10))

We can do the same for sets via assert-set-like. For maps, assert-map-like takes two generators, one for keys, and another for values.

license

Copyright © 2017 Zachary Tellman

Distributed under the MIT License.

collection-check's People

Contributors

ztellman avatar martinklepsch avatar michalmarczyk avatar michaelblume avatar joegallo avatar nberger avatar

Watchers

Samir Sekkat avatar

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.