diff --git a/script/helpers.coffee b/script/helpers.coffee index c39aae9a3e..b5fbdf330f 100644 --- a/script/helpers.coffee +++ b/script/helpers.coffee @@ -260,7 +260,7 @@ module.exports = ### gold: (num) -> if num - return (num).toFixed(1).split('.')[0] + return Math.floor num else return "0" @@ -269,7 +269,7 @@ module.exports = ### silver: (num) -> if num - (num).toFixed(2).split('.')[1] + ("0" + Math.floor (num - Math.floor(num))*100).slice -2 else return "00" diff --git a/tests/algos.mocha.coffee b/tests/algos.mocha.coffee index 2692b6e5ea..779ac9ac78 100644 --- a/tests/algos.mocha.coffee +++ b/tests/algos.mocha.coffee @@ -241,3 +241,15 @@ describe 'Cron', -> now = moment().startOf('day').add('h', dayStart).add('m', 1) console.log {yesterday,now} expect(helpers.daysSince(yesterday, {now, dayStart})).to.eql 1 + +describe 'Helper', -> + it 'calculates gold coins', -> + expect(helpers.gold(10)).to.eql 10 + expect(helpers.gold(1.957)).to.eql 1 + expect(helpers.gold()).to.eql 0 + + it 'calculates silver coins', -> + expect(helpers.silver(10)).to.eql 0 + expect(helpers.silver(1.957)).to.eql 95 + expect(helpers.silver(0.01)).to.eql "01" + expect(helpers.silver()).to.eql "00"