Permalink
Browse files

making scoring more consistant - closes #4

  • Loading branch information...
1 parent dd2ef31 commit 0c89d028c3d90de92cf5f943243a865a4701efe4 @ryanb committed Sep 5, 2009
Showing with 15 additions and 4 deletions.
  1. +4 −1 app/models/score_tracker.rb
  2. +10 −2 spec/models/score_tracker_spec.rb
  3. +1 −1 spec/models/stamp_spec.rb
@@ -9,7 +9,10 @@ def initialize(options = {})
end
def mark
- @negative_points = 0
+ if @negative_points > 0
+ @negative_points = 0
+ @position = 0
+ end
if @position >= @positive_points
@positive_points += 1
@position = 0
@@ -25,7 +25,7 @@
it "should slowly deduct positive points when misses" do
4.times { @tracker.mark }
2.times { @tracker.miss }
- @tracker.mark.should == 2
+ @tracker.mark.should == 1
end
it "should reset position when mark is after misses" do
@@ -40,7 +40,7 @@
it "should handle complex scenarios" do
[@tracker.mark, @tracker.mark, @tracker.mark, @tracker.miss, @tracker.mark, @tracker.mark,
@tracker.miss, @tracker.miss, @tracker.miss, @tracker.miss, @tracker.mark].should ==
- [1, 2, 2, -1, 2, 2, -1, -2, -2, -3, 1]
+ [1, 2, 2, -1, 1, 2, -1, -2, -2, -2, 1]
end
it "skip should continue on as if nothing happened" do
@@ -57,4 +57,12 @@
tracker.miss.should == -1
tracker.score.should == 0
end
+
+ it "should go down one positive point when missing a day" do
+ tracker = ScoreTracker.new(:score => 1, :positive_points => 4, :position => 2)
+ tracker.miss.should == -1
+ tracker.mark.should == 3
+ tracker.positive_points.should == 3
+ tracker.position.should == 1
+ end
end
@@ -20,7 +20,7 @@
["2009-04-01", "2009-04-02", "2009-04-03", "2009-04-04", "2009-04-07"].each do |date|
@stamp.marks.create!(:marked_on => date)
end
- @stamp.month_points(Date.new(2009, 4, 3)).should == [1, 2, 2, 3, -1, -2, 2, -1, -2, -2, -2] + [0]*19
+ @stamp.month_points(Date.new(2009, 4, 3)).should == [1, 2, 2, 3, -1, -2, 1, -1, -2, -2, -1] + [0]*19
end
it "should apply score to previous month" do

0 comments on commit 0c89d02

Please sign in to comment.