@buildingsblock/core
Advanced tools
Comparing version 0.1.0-alpha.2 to 0.1.0-alpha.3
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.calcAverageSalesTurnoverRate = exports.calcAverageContingencyReserveFundPerBudget = exports.calcAverageContingencyReserveFundPerSquareFoot = exports.calcAverageBudgetPerSquareFoot = exports.calcAverageRepairAndMaintenanceBudgetPerSquareFoot = void 0; | ||
exports.default = exports.calcAverageContingencyReserveFundPerBudget = exports.calcAverageSalesTurnoverRate = exports.calcContingencyReserveFundContributionsPerSquareFoot = exports.calcContingencyReserveFundPerSquareFoot = exports.calcBudgetPerSquareFoot = exports.calcRepairAndMaintenanceBudgetPerSquareFoot = void 0; | ||
@@ -17,3 +17,3 @@ var _lodash = _interopRequireDefault(require("lodash")); | ||
var calcAverageRepairAndMaintenanceBudgetPerSquareFoot = function calcAverageRepairAndMaintenanceBudgetPerSquareFoot(stratas) { | ||
var calcRepairAndMaintenanceBudgetPerSquareFoot = function calcRepairAndMaintenanceBudgetPerSquareFoot(stratas) { | ||
var stratasWithBudget = stratas.filter(function (x) { | ||
@@ -24,3 +24,7 @@ return x.repairAndMaintenanceBudget && x.repairAndMaintenanceBudget.length; | ||
}); | ||
if (!stratasWithBudget.length) return null; | ||
if (!stratasWithBudget.length) return { | ||
average: null, | ||
min: null, | ||
max: null | ||
}; | ||
var metrics = stratasWithBudget.map(function (x) { | ||
@@ -32,8 +36,12 @@ var value = _lodash.default.orderBy(x.repairAndMaintenanceBudget, ['at'], ['desc'])[0].value; | ||
}); | ||
return (0, _utils.toFixed)((0, _utils.average)(metrics), 2); | ||
return { | ||
average: (0, _utils.toFixed)((0, _utils.average)(metrics), 2), | ||
min: (0, _utils.toFixed)((0, _utils.min)(metrics), 2), | ||
max: (0, _utils.toFixed)((0, _utils.max)(metrics), 2) | ||
}; | ||
}; | ||
exports.calcAverageRepairAndMaintenanceBudgetPerSquareFoot = calcAverageRepairAndMaintenanceBudgetPerSquareFoot; | ||
exports.calcRepairAndMaintenanceBudgetPerSquareFoot = calcRepairAndMaintenanceBudgetPerSquareFoot; | ||
var calcAverageBudgetPerSquareFoot = function calcAverageBudgetPerSquareFoot(stratas) { | ||
var calcBudgetPerSquareFoot = function calcBudgetPerSquareFoot(stratas) { | ||
var stratasWithBudget = stratas.filter(function (x) { | ||
@@ -44,3 +52,7 @@ return x.budget && x.budget.length; | ||
}); | ||
if (!stratasWithBudget.length) return null; | ||
if (!stratasWithBudget.length) return { | ||
average: null, | ||
min: null, | ||
max: null | ||
}; | ||
var metrics = stratasWithBudget.map(function (x) { | ||
@@ -52,8 +64,12 @@ var value = _lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value; | ||
}); | ||
return (0, _utils.toFixed)((0, _utils.average)(metrics), 2); | ||
return { | ||
average: (0, _utils.toFixed)((0, _utils.average)(metrics), 2), | ||
min: (0, _utils.toFixed)((0, _utils.min)(metrics), 2), | ||
max: (0, _utils.toFixed)((0, _utils.max)(metrics), 2) | ||
}; | ||
}; | ||
exports.calcAverageBudgetPerSquareFoot = calcAverageBudgetPerSquareFoot; | ||
exports.calcBudgetPerSquareFoot = calcBudgetPerSquareFoot; | ||
var calcAverageContingencyReserveFundPerSquareFoot = function calcAverageContingencyReserveFundPerSquareFoot(stratas) { | ||
var calcContingencyReserveFundPerSquareFoot = function calcContingencyReserveFundPerSquareFoot(stratas) { | ||
var stratasWithContingencyReserveFund = stratas.filter(function (x) { | ||
@@ -64,3 +80,7 @@ return x.contingencyReserveFund.length; | ||
}); | ||
if (!stratasWithContingencyReserveFund.length) return null; | ||
if (!stratasWithContingencyReserveFund.length) return { | ||
average: null, | ||
min: null, | ||
max: null | ||
}; | ||
var metrics = stratasWithContingencyReserveFund.map(function (x) { | ||
@@ -72,25 +92,36 @@ var contingencyReserveFund = _lodash.default.orderBy(x.contingencyReserveFund, ['at'], ['desc'])[0].value; | ||
}); | ||
return (0, _utils.toFixed)((0, _utils.average)(metrics), 2); | ||
return { | ||
average: (0, _utils.toFixed)((0, _utils.average)(metrics), 2), | ||
min: (0, _utils.toFixed)((0, _utils.min)(metrics), 2), | ||
max: (0, _utils.toFixed)((0, _utils.max)(metrics), 2) | ||
}; | ||
}; | ||
exports.calcAverageContingencyReserveFundPerSquareFoot = calcAverageContingencyReserveFundPerSquareFoot; | ||
exports.calcContingencyReserveFundPerSquareFoot = calcContingencyReserveFundPerSquareFoot; | ||
var calcAverageContingencyReserveFundPerBudget = function calcAverageContingencyReserveFundPerBudget(stratas) { | ||
var stratasWithContingencyReserveFund = stratas.filter(function (x) { | ||
return x.contingencyReserveFund && x.contingencyReserveFund.length; | ||
var calcContingencyReserveFundContributionsPerSquareFoot = function calcContingencyReserveFundContributionsPerSquareFoot(stratas) { | ||
var stratasWithContingencyReserveFundContributions = stratas.filter(function (x) { | ||
return x.contingencyReserveFundContributions.length; | ||
}).filter(function (x) { | ||
return x.budget && x.budget.length; | ||
return x.area.total; | ||
}); | ||
if (!stratasWithContingencyReserveFund.length) return null; | ||
var metrics = stratasWithContingencyReserveFund.map(function (x) { | ||
var contingencyReserveFund = _lodash.default.orderBy(x.contingencyReserveFund, ['at'], ['desc'])[0].value; | ||
if (!stratasWithContingencyReserveFundContributions.length) return { | ||
average: null, | ||
min: null, | ||
max: null | ||
}; | ||
var metrics = stratasWithContingencyReserveFundContributions.map(function (x) { | ||
var contingencyReserveFundContributions = _lodash.default.orderBy(x.contingencyReserveFundContributions, ['at'], ['desc'])[0].value; | ||
var budget = _lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value; | ||
return new _decimal.Decimal(contingencyReserveFund).dividedBy(budget); | ||
var area = x.area.total; | ||
return new _decimal.Decimal(contingencyReserveFundContributions).dividedBy(area); | ||
}); | ||
return (0, _utils.toFixed)((0, _utils.average)(metrics), 2); | ||
return { | ||
average: (0, _utils.toFixed)((0, _utils.average)(metrics), 2), | ||
min: (0, _utils.toFixed)((0, _utils.min)(metrics), 2), | ||
max: (0, _utils.toFixed)((0, _utils.max)(metrics), 2) | ||
}; | ||
}; | ||
exports.calcAverageContingencyReserveFundPerBudget = calcAverageContingencyReserveFundPerBudget; | ||
exports.calcContingencyReserveFundContributionsPerSquareFoot = calcContingencyReserveFundContributionsPerSquareFoot; | ||
@@ -130,2 +161,21 @@ var calcAverageSalesTurnoverRate = function calcAverageSalesTurnoverRate(stratas) { | ||
var calcAverageContingencyReserveFundPerBudget = function calcAverageContingencyReserveFundPerBudget(stratas) { | ||
var stratasWithContingencyReserveFund = stratas.filter(function (x) { | ||
return x.contingencyReserveFund && x.contingencyReserveFund.length; | ||
}).filter(function (x) { | ||
return x.budget && x.budget.length; | ||
}); | ||
if (!stratasWithContingencyReserveFund.length) return null; | ||
var metrics = stratasWithContingencyReserveFund.map(function (x) { | ||
var contingencyReserveFund = _lodash.default.orderBy(x.contingencyReserveFund, ['at'], ['desc'])[0].value; | ||
var budget = _lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value; | ||
return new _decimal.Decimal(contingencyReserveFund).dividedBy(budget); | ||
}); | ||
return (0, _utils.toFixed)((0, _utils.average)(metrics), 2); | ||
}; | ||
exports.calcAverageContingencyReserveFundPerBudget = calcAverageContingencyReserveFundPerBudget; | ||
var createSchema = function createSchema(Mongoose) { | ||
@@ -205,5 +255,6 @@ var StrataSchema = new Mongoose.Schema({ | ||
var _default = { | ||
calcAverageRepairAndMaintenanceBudgetPerSquareFoot: calcAverageRepairAndMaintenanceBudgetPerSquareFoot, | ||
calcAverageBudgetPerSquareFoot: calcAverageBudgetPerSquareFoot, | ||
calcAverageContingencyReserveFundPerSquareFoot: calcAverageContingencyReserveFundPerSquareFoot, | ||
calcRepairAndMaintenanceBudgetPerSquareFoot: calcRepairAndMaintenanceBudgetPerSquareFoot, | ||
calcBudgetPerSquareFoot: calcBudgetPerSquareFoot, | ||
calcContingencyReserveFundPerSquareFoot: calcContingencyReserveFundPerSquareFoot, | ||
calcContingencyReserveFundContributionsPerSquareFoot: calcContingencyReserveFundContributionsPerSquareFoot, | ||
calcAverageContingencyReserveFundPerBudget: calcAverageContingencyReserveFundPerBudget, | ||
@@ -210,0 +261,0 @@ calcAverageSalesTurnoverRate: calcAverageSalesTurnoverRate, |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.toFixed = exports.average = void 0; | ||
exports.default = exports.toFixed = exports.max = exports.min = exports.average = void 0; | ||
@@ -13,2 +13,10 @@ var _decimal = _interopRequireDefault(require("decimal.js")); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
var average = function average(arr) { | ||
@@ -23,2 +31,14 @@ var sum = arr.reduce(function (acc, x) { | ||
var min = function min(arr) { | ||
return Math.min.apply(Math, _toConsumableArray(arr)); | ||
}; | ||
exports.min = min; | ||
var max = function max(arr) { | ||
return Math.max.apply(Math, _toConsumableArray(arr)); | ||
}; | ||
exports.max = max; | ||
var toFixed = function toFixed(x, number) { | ||
@@ -25,0 +45,0 @@ return Number(new _decimal.default(x).toFixed(number)); |
{ | ||
"name": "@buildingsblock/core", | ||
"version": "0.1.0-alpha.2", | ||
"version": "0.1.0-alpha.3", | ||
"description": "Core code base for Eli", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
import test from 'ava' | ||
import { | ||
calcAverageRepairAndMaintenanceBudgetPerSquareFoot, | ||
calcAverageBudgetPerSquareFoot, | ||
calcAverageContingencyReserveFundPerSquareFoot, | ||
calcRepairAndMaintenanceBudgetPerSquareFoot, | ||
calcBudgetPerSquareFoot, | ||
calcContingencyReserveFundPerSquareFoot, | ||
calcContingencyReserveFundContributionsPerSquareFoot, | ||
calcAverageContingencyReserveFundPerBudget, | ||
@@ -11,3 +13,3 @@ calcAverageSalesTurnoverRate, | ||
test('calcAverageContingencyReserveFundPerSquareFoot', (t) => { | ||
test('calcContingencyReserveFundPerSquareFoot', (t) => { | ||
const stratas = [ | ||
@@ -32,50 +34,10 @@ { | ||
t.is(calcAverageContingencyReserveFundPerSquareFoot(stratas), 33.23, 'should return average CRF/sqft of stratas') | ||
t.is(calcAverageContingencyReserveFundPerSquareFoot(stratas), 33.23, 'should ignore stratas without contingency reserve fund') | ||
t.is(calcAverageContingencyReserveFundPerSquareFoot(stratas), 33.23, 'should ignore stratas without total area') | ||
t.is(calcAverageContingencyReserveFundPerSquareFoot(stratas), 33.23, 'should only use latest contingency reserve fund value') | ||
}) | ||
const data = calcContingencyReserveFundPerSquareFoot(stratas) | ||
test('calcSalesTurnoverRate', (t) => { | ||
const strata = [{ | ||
sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
units: 100, | ||
}] | ||
let result = calcAverageSalesTurnoverRate(strata) | ||
t.is(result.pastYear, 0.1, 'should return turnover rate for past year') | ||
t.is(result.twoYearsAgo, 0.05, 'should return turnover rate for two years ago') | ||
t.is(result.threeYearsAgo, 0.2, 'should return turnover rate for three years ago') | ||
result = calcAverageSalesTurnoverRate([{ sales: [], units: 100 }]) | ||
t.is(result, null, 'should return null if strata has not sales') | ||
t.is(data.average, 33.23, 'should return average CRF/sqft of stratas') | ||
t.is(data.min, 12.62, 'should ignore min CRF/sqft of stratas') | ||
t.is(data.max, 33.23, 'should ignore max CRF/sqft of stratas') | ||
}) | ||
test('calcAverageSalesTurnoverRate', (t) => { | ||
const strata = [ | ||
{ | ||
sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
units: 100, | ||
}, | ||
{ | ||
sales: [{ pastYear: 15, twoYearsAgo: 40, threeYearsAgo: 35 }], | ||
units: 200, | ||
}, | ||
{ | ||
sales: [], | ||
}, | ||
{ | ||
units: null, | ||
}, | ||
] | ||
const result = calcAverageSalesTurnoverRate(strata) | ||
t.is(result.pastYear, 0.09, 'should return average turnover rate for past year') | ||
t.is(result.twoYearsAgo, 0.13, 'should return average turnover rate for two years ago') | ||
t.is(result.threeYearsAgo, 0.19, 'should return average turnover rate for three years ago') | ||
}) | ||
test('calcAverageBudgetPerSquareFoot', (t) => { | ||
test.only('calcBudgetPerSquareFoot', (t) => { | ||
const stratas = [ | ||
@@ -113,28 +75,39 @@ { | ||
const result = calcAverageBudgetPerSquareFoot(stratas) | ||
const oneStrataResult = calcAverageBudgetPerSquareFoot(oneStrata) | ||
const nullStrataResult = calcAverageBudgetPerSquareFoot(nullStrata) | ||
const emptyStrataResult = calcAverageBudgetPerSquareFoot(emptyStrata) | ||
const result = calcBudgetPerSquareFoot(stratas) | ||
const oneStrataResult = calcBudgetPerSquareFoot(oneStrata) | ||
const nullStrataResult = calcBudgetPerSquareFoot(nullStrata) | ||
const emptyStrataResult = calcBudgetPerSquareFoot(emptyStrata) | ||
t.is(result, 210, 'should return average budget per sqft for past year') | ||
t.is(oneStrataResult, 20, 'should return average budget per sqft for past year') | ||
t.is(nullStrataResult, null, 'should return average budget per sqft for past year') | ||
t.is(emptyStrataResult, null, 'should return average budget per sqft for past year') | ||
t.is(result.average, 210, 'should return average budget per sqft for past year') | ||
t.is(result.min, 20, 'should return min budget per sqft for past year') | ||
t.is(result.max, 400, 'should return max budget per sqft for past year') | ||
t.is(oneStrataResult.average, 20, 'should return average budget per sqft for past year') | ||
t.is(oneStrataResult.min, 20, 'should return min budget per sqft for past year') | ||
t.is(oneStrataResult.max, 20, 'should return max budget per sqft for past year') | ||
t.is(nullStrataResult.average, null, 'should return average budget per sqft for past year') | ||
t.is(nullStrataResult.min, null, 'should return min budget per sqft for past year') | ||
t.is(nullStrataResult.max, null, 'should return max budget per sqft for past year') | ||
t.is(emptyStrataResult.average, null, 'should return average budget per sqft for past year') | ||
t.is(emptyStrataResult.min, null, 'should return min budget per sqft for past year') | ||
t.is(emptyStrataResult.max, null, 'should return max budget per sqft for past year') | ||
}) | ||
test('calcAverageContingencyReserveFundPerBudget', (t) => { | ||
test('calcRepairAndMaintenanceBudgetPerSquareFoot', (t) => { | ||
const stratas = [ | ||
{ | ||
contingencyReserveFund: [{ value: 70000, at: '2018-01-11' }, { value: 40000, at: '2018-05-11' }], | ||
budget: [{ value: 2000, at: '2018-01-11' }, { value: 1000, at: '2018-05-11' }], | ||
repairAndMaintenanceBudget: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
area: { total: 1000 }, | ||
}, | ||
{ | ||
contingencyReserveFund: [{ value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 1000, at: '2018-05-11' }], | ||
repairAndMaintenanceBudget: [{ value: 40000 }], | ||
area: { total: 100 }, | ||
}, | ||
{ | ||
contingencyReserveFund: [], | ||
repairAndMaintenanceBudget: [], | ||
}, | ||
{ | ||
budget: null, | ||
area: null, | ||
}, | ||
@@ -145,4 +118,4 @@ ] | ||
{ | ||
contingencyReserveFund: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 2000, at: '2018-01-11' }, { value: 1000, at: '2018-05-11' }], | ||
repairAndMaintenanceBudget: [{ value: 20000 }], | ||
area: { total: 1000 }, | ||
}, | ||
@@ -153,3 +126,3 @@ ] | ||
{ | ||
budget: null, | ||
area: null, | ||
}, | ||
@@ -160,15 +133,26 @@ ] | ||
const result = calcAverageContingencyReserveFundPerBudget(stratas) | ||
const oneStrataResult = calcAverageContingencyReserveFundPerBudget(oneStrata) | ||
const nullStrataResult = calcAverageContingencyReserveFundPerBudget(nullStrata) | ||
const emptyStrataResult = calcAverageContingencyReserveFundPerBudget(emptyStrata) | ||
const result = calcRepairAndMaintenanceBudgetPerSquareFoot(stratas) | ||
const oneStrataResult = calcRepairAndMaintenanceBudgetPerSquareFoot(oneStrata) | ||
const nullStrataResult = calcRepairAndMaintenanceBudgetPerSquareFoot(nullStrata) | ||
const emptyStrataResult = calcRepairAndMaintenanceBudgetPerSquareFoot(emptyStrata) | ||
t.is(result, 30, 'should return average budget per sqft for past year') | ||
t.is(oneStrataResult, 20, 'should return average budget per sqft for past year') | ||
t.is(nullStrataResult, null, 'should return average budget per sqft for past year') | ||
t.is(emptyStrataResult, null, 'should return average budget per sqft for past year') | ||
t.is(result.average, 210, 'should return average for past year') | ||
t.is(result.min, 20, 'should return min for past year') | ||
t.is(result.max, 400, 'should return max for past year') | ||
t.is(oneStrataResult.average, 20, 'should return average for past year') | ||
t.is(oneStrataResult.min, 20, 'should return min for past year') | ||
t.is(oneStrataResult.max, 20, 'should return max for past year') | ||
t.is(nullStrataResult.average, null, 'should return average for past year') | ||
t.is(nullStrataResult.min, null, 'should return min for past year') | ||
t.is(nullStrataResult.max, null, 'should return max for past year') | ||
t.is(emptyStrataResult.average, null, 'should return average for past year') | ||
t.is(emptyStrataResult.min, null, 'should return min for past year') | ||
t.is(emptyStrataResult.max, null, 'should return max for past year') | ||
}) | ||
test('calcAverageRepairAndMaintenanceBudgetPerSquareFoot', (t) => { | ||
test('calcContingencyReserveFundContributionsPerSquareFoot', (t) => { | ||
const stratas = [ | ||
@@ -206,11 +190,108 @@ { | ||
const result = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(stratas) | ||
const oneStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(oneStrata) | ||
const nullStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(nullStrata) | ||
const emptyStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(emptyStrata) | ||
const result = calcContingencyReserveFundContributionsPerSquareFoot(stratas) | ||
const oneStrataResult = calcContingencyReserveFundContributionsPerSquareFoot(oneStrata) | ||
const nullStrataResult = calcContingencyReserveFundContributionsPerSquareFoot(nullStrata) | ||
const emptyStrataResult = calcContingencyReserveFundContributionsPerSquareFoot(emptyStrata) | ||
t.is(result, 210, 'should return average contingency reserve fund per budget for past year') | ||
t.is(oneStrataResult, 20, 'should return average contingency reserve fund per budget for past year') | ||
t.is(nullStrataResult, null, 'should return average contingency reserve fund per budget for past year') | ||
t.is(emptyStrataResult, null, 'should return average contingency reserve fund per budget for past year') | ||
t.is(result.average, 210, 'should return average for past year') | ||
t.is(result.min, 20, 'should return min for past year') | ||
t.is(result.max, 400, 'should return max for past year') | ||
t.is(oneStrataResult.average, 20, 'should return average for past year') | ||
t.is(oneStrataResult.min, 20, 'should return min for past year') | ||
t.is(oneStrataResult.max, 20, 'should return max for past year') | ||
t.is(nullStrataResult.average, null, 'should return average for past year') | ||
t.is(nullStrataResult.min, null, 'should return min for past year') | ||
t.is(nullStrataResult.max, null, 'should return max for past year') | ||
t.is(emptyStrataResult.average, null, 'should return average for past year') | ||
t.is(emptyStrataResult.min, null, 'should return min for past year') | ||
t.is(emptyStrataResult.max, null, 'should return max for past year') | ||
}) | ||
test('calcSalesTurnoverRate', (t) => { | ||
const strata = [{ | ||
sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
units: 100, | ||
}] | ||
let result = calcAverageSalesTurnoverRate(strata) | ||
t.is(result.pastYear, 0.1, 'should return turnover rate for past year') | ||
t.is(result.twoYearsAgo, 0.05, 'should return turnover rate for two years ago') | ||
t.is(result.threeYearsAgo, 0.2, 'should return turnover rate for three years ago') | ||
result = calcAverageSalesTurnoverRate([{ sales: [], units: 100 }]) | ||
t.is(result, null, 'should return null if strata has not sales') | ||
}) | ||
test('calcAverageSalesTurnoverRate', (t) => { | ||
const strata = [ | ||
{ | ||
sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
units: 100, | ||
}, | ||
{ | ||
sales: [{ pastYear: 15, twoYearsAgo: 40, threeYearsAgo: 35 }], | ||
units: 200, | ||
}, | ||
{ | ||
sales: [], | ||
}, | ||
{ | ||
units: null, | ||
}, | ||
] | ||
const result = calcAverageSalesTurnoverRate(strata) | ||
t.is(result.pastYear, 0.09, 'should return average turnover rate for past year') | ||
t.is(result.twoYearsAgo, 0.13, 'should return average turnover rate for two years ago') | ||
t.is(result.threeYearsAgo, 0.19, 'should return average turnover rate for three years ago') | ||
}) | ||
test('calcAverageContingencyReserveFundPerBudget', (t) => { | ||
const stratas = [ | ||
{ | ||
contingencyReserveFund: [{ value: 70000, at: '2018-01-11' }, { value: 40000, at: '2018-05-11' }], | ||
budget: [{ value: 2000, at: '2018-01-11' }, { value: 1000, at: '2018-05-11' }], | ||
}, | ||
{ | ||
contingencyReserveFund: [{ value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 1000, at: '2018-05-11' }], | ||
}, | ||
{ | ||
contingencyReserveFund: [], | ||
}, | ||
{ | ||
budget: null, | ||
}, | ||
] | ||
const oneStrata = [ | ||
{ | ||
contingencyReserveFund: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 2000, at: '2018-01-11' }, { value: 1000, at: '2018-05-11' }], | ||
}, | ||
] | ||
const nullStrata = [ | ||
{ | ||
budget: null, | ||
}, | ||
] | ||
const emptyStrata = [] | ||
const result = calcAverageContingencyReserveFundPerBudget(stratas) | ||
const oneStrataResult = calcAverageContingencyReserveFundPerBudget(oneStrata) | ||
const nullStrataResult = calcAverageContingencyReserveFundPerBudget(nullStrata) | ||
const emptyStrataResult = calcAverageContingencyReserveFundPerBudget(emptyStrata) | ||
t.is(result, 30, 'should return average budget per sqft for past year') | ||
t.is(oneStrataResult, 20, 'should return average budget per sqft for past year') | ||
t.is(nullStrataResult, null, 'should return average budget per sqft for past year') | ||
t.is(emptyStrataResult, null, 'should return average budget per sqft for past year') | ||
}) |
import test from 'ava' | ||
import { average } from '../src/utils' | ||
import { average, min, max } from '../src/utils' | ||
test.only('average', (t) => { | ||
test('average', (t) => { | ||
t.is(average([1, 2, 3]), 2, 'should return average of integers') | ||
t.is(average([0.1, 0.2, 0.3]), 0.2, 'should return average of floats') | ||
}) | ||
test('min', (t) => { | ||
t.is(min([1, 2, 3]), 1, 'should return min of integers') | ||
t.is(min([0.1, 0.2, 0.3]), 0.1, 'should return min of floats') | ||
}) | ||
test('max', (t) => { | ||
t.is(max([1, 2, 3]), 3, 'should return max of integers') | ||
t.is(max([0.1, 0.2, 0.3]), 0.3, 'should return max of floats') | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58709
574