corrected rounding of gold & silver calculations

This commit is contained in:
Dušan Juretić 2013-09-23 22:59:46 -03:00
parent d130989fd9
commit c60f6f1c23
2 changed files with 13 additions and 2 deletions

View file

@ -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]
Math.floor (num - Math.floor(num))*100
else
return "00"

View file

@ -241,3 +241,14 @@ 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()).to.eql 0