tests passing for basic scoring

This commit is contained in:
Tyler Renelle
2012-10-11 11:41:47 -04:00
parent bad2f6f5b3
commit 476fb63a0d
3 changed files with 11 additions and 5 deletions
+4 -2
View File
@@ -206,10 +206,12 @@ score = function(taskId, direction, options) {
}
delta = 0;
_.times(options.times, function(n) {
delta = taskDeltaFormula(value, direction);
var nextDelta;
nextDelta = taskDeltaFormula(value, direction);
if (adjustvalue) {
return value += delta;
value += nextDelta;
}
return delta += nextDelta;
});
if (type === 'habit') {
if (taskObj.value !== value) {
+6 -2
View File
@@ -164,8 +164,12 @@ score = (taskId, direction, options={cron:false, times:1}) ->
# If multiple days have passed, multiply times days missed
# TODO integrate this multiplier into the formula, so don't have to loop
_.times options.times, (n) ->
delta = taskDeltaFormula(value, direction)
value += delta if adjustvalue
# Each iteration calculate the delta (nextDelta), which is then accumulated in delta
# (aka, the total delta). This weirdness won't be necessary when calculating mathematically
# rather than iteratively
nextDelta = taskDeltaFormula(value, direction)
value += nextDelta if adjustvalue
delta += nextDelta
if type == 'habit'
# Add habit value to habit-history (if different)
+1 -1
View File
@@ -125,7 +125,7 @@ describe 'User', ->
## Trial 2
freshTask {type: 'habit', text: 'Habit', completed: false}
shouldBe = modificationsLookup({lvl:1,armor:0,weapon:0}, 'down', 10)
_.times 10, -> scoring.score(uuid,'down', {times:10})
scoring.score(uuid,'down', {times:10})
[stats, task] = statsTask()
expect(stats.hp).to.be.eql shouldBe.user.stats.hp
expect(task.value).to.eql shouldBe.value