chai-increasing

Chai matchers for increasing/decreasing sequences

A chai plugin for forming assertions on increasing/decreasing sequences.

Usage

Monotonic increasing/decreasing:

expect([1,2,2,3,3,4]).to.be.increasing;
expect([5,4,4,4,4,3]).to.be.decreasing;
expect([1,1,1,1,1,1]).to.be.increasing;
expect([1,1,1,1,1,1]).to.be.decreasing;

Strictly increasing/decreasing:

expect([1,2,3,4,5]).to.be.strictly.increasing;
expect([1,2,3,3,4,5]).not.to.be.strictly.increasing;
expect([10,9,8,7,6]).to.be.strictly.increasing;
expect([10,9,8,7,7]).not.to.be.strictly.decreasing;

Empty arrays are vacuously increasing/decreasing:

expect([]).to.be.increasing;
expect([]).to.be.decreasing;
expect([]).to.be.strictly.increasing;
expect([]).to.be.strictly.decreasing;

Extras:

// supports Strings, Floats and Immutable.js Lists
expect(['Apple','Banana','Coconut']).to.be.strictly.increasing;
expect([1.15, 1.75, 3.28, 4.96]).to.be.strictly.increasing;
expect(Immutable.List.of([1,2,3,4])).to.be.strictly.increasing;

Nondecreasing/Nonincreasing aliases:

// "nondecreasing" and "nonincreasing" may be used instead 
// of "increasing" and "decreasing" for clarity; the behaviour is the same.
expect([1,1,1]).to.be.increasing;
expect([1,1,1]).to.be.nondecreasing;

Installation

npm install chai-increasing --save-dev
var chai = require('chai');
chai.use(require('chai-increasing'));

License

MIT License.
Copyright © 2016 James Lawson