Permalink
Browse files

Test simulating multiple months

  • Loading branch information...
1 parent 3128841 commit f4a68160cbc5dbe33bdd34ada2d29722099ad080 @r00k committed Jan 25, 2012
Showing with 23 additions and 5 deletions.
  1. +3 −3 lib/calculator.rb
  2. +20 −2 spec/calculator_spec.rb
View
@@ -18,18 +18,18 @@ def simulate_one_month
private
def update_trial_users
- self.trial_users = @visitors * (@conversion_to_trial_percentage / 100.0)
+ self.trial_users = (@visitors * (@conversion_to_trial_percentage / 100.0)).floor
end
def update_paid_users
self.paid_users = paid_users + new_users_count - cancelled_users_count
end
def new_users_count
- trial_users * (@conversion_to_paid_percentage / 100.0)
+ (trial_users * (@conversion_to_paid_percentage / 100.0)).floor
end
def cancelled_users_count
- paid_users * (@cancellation_percentage / 100.0)
+ (paid_users * (@cancellation_percentage / 100.0)).floor
end
end
View
@@ -1,20 +1,38 @@
require 'spec_helper'
describe "#simulate_one_month" do
- let(:calculator) { Calculator.new(visitors: 100, conversion_to_trial_percentage: 5,
+ let(:calculator) { Calculator.new(visitors: 100, conversion_to_trial_percentage: 20,
conversion_to_paid_percentage: 10,
cancellation_percentage: 5, trial_users: 100,
paid_users: 100) }
it "updates the trial_users count" do
calculator.simulate_one_month
- calculator.trial_users.should == 5
+ calculator.trial_users.should == 20
end
it "updates the paid_users count" do
calculator.simulate_one_month
calculator.paid_users.should == 105
end
+
+ context "simulating multiple months" do
+ it "reaches keeps the number of trial_users constant after month 1" do
+ 2.times { calculator.simulate_one_month }
+ calculator.trial_users.should == 20
+
+ calculator.simulate_one_month
+ calculator.trial_users.should == 20
+ end
+
+ it "updates paid_users continuously" do
+ 2.times { calculator.simulate_one_month }
+ calculator.paid_users.should == 102
+
+ calculator.simulate_one_month
+ calculator.paid_users.should == 99
+ end
+ end
end

0 comments on commit f4a6816

Please sign in to comment.