Add level bonus calculation script

This commit is contained in:
Blade Barringer 2015-07-17 17:37:57 -05:00
parent a9757c9dbb
commit 841923e054
2 changed files with 55 additions and 0 deletions

View file

@ -0,0 +1,20 @@
'use strict';
var Content = require('../content.coffee');
function levelBonus(level) {
// Level bonus is derived by taking the level, subtracting one,
// taking the smaller of it or maxLevel (100),
// dividing that by two and then raising it to a whole number
// TODO: 100 is a magic number, extract from script.index into own module and call here
var levelOrMaxLevel = Math.min((level - 1), 100)
var levelDividedByTwo = levelOrMaxLevel / 2
var statBonus = Math.ceil(levelDividedByTwo )
return statBonus;
}
module.exports = {
levelBonus: levelBonus
}

View file

@ -0,0 +1,35 @@
'use strict';
var sinon = require('sinon');
var chai = require("chai");
chai.use(require("sinon-chai"));
var expect = chai.expect;
var statCalc = require('../../common/script/methods/statCalculations');
describe('stat calculation functions', function() {
describe('calculateLevelStatBonus', function() {
it('calculates bonus as half of level for even numbered level under 100', function() {
var level = 50;
var bonus = statCalc.levelBonus(level);
expect(bonus).to.eql(25);
});
it('calculates bonus as half of level, rounded down, for odd numbered level under 100', function() {
var level = 51;
var bonus = statCalc.levelBonus(level);
expect(bonus).to.eql(25);
});
it('calculates bonus as 50 for levels >= 100', function() {
var level = 150;
var bonus = statCalc.levelBonus(level);
expect(bonus).to.eql(50);
});
it('calculates bonus as 0 for level 1', function() {
var level = 1;
var bonus = statCalc.levelBonus(level);
expect(bonus).to.eql(0);
});
});
});