Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SM2 interval calculation to match standard algorithm #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ PATH
remote: .
specs:
active_recall (2.0.2)
activerecord (>= 6.0, <= 7.2)
activesupport (>= 6.0, <= 7.2)
activerecord (>= 6.0, <= 8.0.0.beta1)
activesupport (>= 6.0, <= 8.0.0.beta1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -248,7 +248,7 @@ PLATFORMS
DEPENDENCIES
active_recall!
appraisal
rails (>= 6.0, <= 7.2)
rails (>= 6.0, <= 8.0.0.beta1)
rake (>= 12.0)
rdoc
rspec (>= 3.0)
Expand Down
6 changes: 3 additions & 3 deletions active_recall.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_development_dependency "appraisal"
spec.add_development_dependency "rails", ">= 6.0", "<= 7.2"
spec.add_development_dependency "rails", ">= 6.0", "< 9.0"
spec.add_development_dependency "rake", ">= 12.0"
spec.add_development_dependency "rdoc"
spec.add_development_dependency "rspec", ">= 3.0"
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "standard"
spec.add_runtime_dependency "activerecord", ">= 6.0", "<= 7.2"
spec.add_runtime_dependency "activesupport", ">= 6.0", "<= 7.2"
spec.add_runtime_dependency "activerecord", ">= 6.0", "< 9.0"
spec.add_runtime_dependency "activesupport", ">= 6.0", "< 9.0"
spec.required_ruby_version = ">= 3.0"
end
3 changes: 2 additions & 1 deletion lib/active_recall/algorithms/sm2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def update_repetition_and_interval
when 2
6
else
(@interval || 1) * @easiness_factor
6 * (@easiness_factor ** (@box - 1))
end
else
@box = 0
Expand All @@ -90,6 +90,7 @@ def update_repetition_and_interval
end
end


def next_review
@current_time + @interval.days
end
Expand Down
25 changes: 25 additions & 0 deletions spec/active_recall/algorithms/sm2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,30 @@
expect { subject }.to raise_error
end
end

context "with different box values" do
[
{ box: 1, expected_interval: 1 },
{ box: 2, expected_interval: 6 },
{ box: 3, expected_interval: 15 },
{ box: 4, expected_interval: 37 },
{ box: 5, expected_interval: 93 },
].each do |test_case|
context "when box is #{test_case[:box]}" do
before do
params[:box] = test_case[:box]
params[:times_right] = test_case[:box] - 1
end

it "calculates the correct interval" do
result = subject
expect(result[:box]).to eq(test_case[:box] + 1)
expect(result[:next_review]).to be_within(1.day).of(current_time + test_case[:expected_interval].days)
end
end
end
end


end
end