kpiplus
Version:
KPI+
1 lines • 844 B
JavaScript
var should=require("should");require("../libs/array-funcs"),describe("Array",function(){describe("#csum",function(){it("Should return 0 on empty array",function(){[].csum("value").should.be.exactly(0)}),it("Should return a sum of all requested fields",function(){[{value:1},{value:2},{value:3}].csum("value").should.be.exactly(6)}),it("Should sum strings",function(){[{value:"1"},{value:"2"},{value:"3"}].csum("value").should.be.exactly(6)}),it("Should only sum rows matching condition",function(){[{value:"1",due:!0},{value:"2"},{value:"3"}].csum("value",{due:!0}).should.be.exactly(1)}),it("Should work with empty condition",function(){[{value:"1",due:!0},{value:"2"},{value:"3"}].csum("value",{}).should.be.exactly(6)}),it("Should skip missing values",function(){[{value:"1"},{nope:"2"},{value:"3"}].csum("value").should.be.exactly(4)})})});