From c9edf64d7fbf8c987235273d574ac6040c5e68e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Sat, 28 Sep 2013 17:30:32 -0300 Subject: [PATCH 1/4] remove console.log in test --- tests/algos.mocha.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/algos.mocha.coffee b/tests/algos.mocha.coffee index 779ac9ac78..958c1dd1b4 100644 --- a/tests/algos.mocha.coffee +++ b/tests/algos.mocha.coffee @@ -239,7 +239,6 @@ describe 'Cron', -> now = helpers.startOfDay {dayStart: dayStart-1} expect(helpers.daysSince(yesterday, {now, dayStart})).to.eql 0 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', -> From db8723f0d2ae28e3448ea812b0e4e4d3368931c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Sat, 28 Sep 2013 18:36:23 -0300 Subject: [PATCH 2/4] add tests for store operations --- tests/algos.mocha.coffee | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/algos.mocha.coffee b/tests/algos.mocha.coffee index 958c1dd1b4..ce9c9e25c6 100644 --- a/tests/algos.mocha.coffee +++ b/tests/algos.mocha.coffee @@ -83,6 +83,33 @@ describe 'User', -> expectStrings(user.tags[1], ['name','id']) expectStrings(user.tags[2], ['name','id']) + describe 'store', -> + it 'recovers hp buying potions', -> + user = helpers.newUser() + user.stats.hp = 30 + user.stats.gp = 50 + expect(items.buyItem user, 'potion').to.be true + expect(user.stats.hp).to.eql 45 + expect(user.stats.gp).to.eql 25 + + expect(items.buyItem user, 'potion').to.be true + expect(user.stats.hp).to.eql 50 # don't exceed max hp + expect(user.stats.gp).to.eql 0 + + it 'buys equipment', -> + user = helpers.newUser() + user.stats.gp = 31 + expect(items.buyItem user, 'armor').to.be true + expect(user.items.armor).to.eql 1 + expect(user.stats.gp).to.eql 1 + + it 'do not buy equipment without enough money', -> + user = helpers.newUser() + user.stats.gp = 1 + expect(items.buyItem user, 'armor').to.be false + expect(user.items.armor).to.eql 0 + expect(user.stats.gp).to.eql 1 + describe 'Simple Scoring', -> it 'Habits : Up', -> From 49d73543e06c9ade904e84660ad005e72c90de1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Sat, 28 Sep 2013 19:19:40 -0300 Subject: [PATCH 3/4] add test for revival --- tests/algos.mocha.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/algos.mocha.coffee b/tests/algos.mocha.coffee index ce9c9e25c6..853a303341 100644 --- a/tests/algos.mocha.coffee +++ b/tests/algos.mocha.coffee @@ -83,6 +83,14 @@ describe 'User', -> expectStrings(user.tags[1], ['name','id']) expectStrings(user.tags[2], ['name','id']) + it 'revives correctly', -> + user = helpers.newUser() + user.stats = { gp: 10, exp: 100, lvl: 2, hp: 1 } + user.weapon = 1 + algos.revive user + expect(user.stats).to.eql { gp: 0, exp: 0, lvl: 1, hp: 50 } + expect(user.items).to.eql { weapon: 0, armor: 0, head: 0, shield: 0 } + describe 'store', -> it 'recovers hp buying potions', -> user = helpers.newUser() From f9d39103ed223f86b77e17a4e9bab9f8fcd15b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Sat, 28 Sep 2013 19:25:46 -0300 Subject: [PATCH 4/4] add test of 'to next level' experience --- tests/algos.mocha.coffee | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/algos.mocha.coffee b/tests/algos.mocha.coffee index 853a303341..3cd6a62cd9 100644 --- a/tests/algos.mocha.coffee +++ b/tests/algos.mocha.coffee @@ -287,3 +287,10 @@ describe 'Helper', -> expect(helpers.silver(1.957)).to.eql 95 expect(helpers.silver(0.01)).to.eql "01" expect(helpers.silver()).to.eql "00" + + it 'calculates experience to next level', -> + expect(algos.tnl 1).to.eql 150 + expect(algos.tnl 2).to.eql 160 + expect(algos.tnl 10).to.eql 260 + expect(algos.tnl 99).to.eql 3580 + expect(algos.tnl 100).to.eql 0