chai-increasing

用於判斷遞增/遞減序列的 Chai 匹配器

一個 chai 外掛程式,用於對遞增/遞減序列進行斷言。

用法

單調遞增/遞減

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;

嚴格遞增/遞減

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;

空陣列在空洞的意義上是遞增/遞減的

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

額外功能

// 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" 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;

安裝

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

授權條款

MIT 授權條款。
版權 © 2016 James Lawson