tworgy-spaced-repetition 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,7 @@ module SuperMemo
16
16
  self.quality_of_last_recall = nil
17
17
  self.repetition_interval = nil
18
18
  self.next_repetition = nil
19
+ self.last_studied = nil
19
20
  end
20
21
 
21
22
  def process_recall_result(quality_of_recall)
@@ -26,23 +27,28 @@ module SuperMemo
26
27
 
27
28
  if quality_of_recall < 3
28
29
  self.number_repetitions = 0
30
+ self.repetition_interval = 0
29
31
  else
30
- self.number_repetitions += 1
31
32
  self.easiness_factor = calculate_easiness_factor(easiness_factor, quality_of_recall)
32
- end
33
33
 
34
- case number_repetitions
35
- when 0
36
- self.repetition_interval = 0
37
- when 1
38
- self.repetition_interval = 1
39
- when 2
40
- self.repetition_interval = 6
41
- else
42
- self.repetition_interval = repetition_interval * easiness_factor
34
+ if quality_of_recall == 3
35
+ self.repetition_interval = 0
36
+ else
37
+ self.number_repetitions += 1
38
+
39
+ case number_repetitions
40
+ when 1
41
+ self.repetition_interval = 1
42
+ when 2
43
+ self.repetition_interval = 6
44
+ else
45
+ self.repetition_interval = repetition_interval * easiness_factor
46
+ end
47
+ end
43
48
  end
44
49
 
45
50
  self.next_repetition = Date.today + repetition_interval
51
+ self.last_studied = Date.today
46
52
  end
47
53
 
48
54
  def scheduled_to_recall?
@@ -56,6 +62,7 @@ module SuperMemo
56
62
  send(:quality_of_last_recall)
57
63
  send(:next_repetition)
58
64
  send(:repetition_interval)
65
+ send(:last_studied)
59
66
  rescue NoMethodError => e
60
67
  DBC.assert(false, e.message)
61
68
  end
@@ -6,7 +6,8 @@ describe SuperMemo::SM2 do
6
6
 
7
7
  it 'should work fine when including' do
8
8
  class Temp
9
- attr_accessor :easiness_factor, :number_repetitions, :quality_of_last_recall, :next_repetition, :repetition_interval
9
+ attr_accessor :easiness_factor, :number_repetitions,
10
+ :quality_of_last_recall, :next_repetition, :repetition_interval, :last_studied
10
11
  include SuperMemo::SM2
11
12
  end
12
13
 
@@ -30,18 +31,19 @@ describe SuperMemo::SM2 do
30
31
  describe 'exclude mixin' do
31
32
 
32
33
  before :each do
33
- @flash_card = {
34
+ @card = {
34
35
  :easiness_factor => nil,
35
36
  :number_repetitions => nil,
36
37
  :quality_of_last_recall => nil,
37
38
  :next_repetition => nil,
38
39
  :repetition_interval => nil,
40
+ :last_studied => nil,
39
41
  :question => "Who is the most awesome of them all?",
40
42
  :answer => 'Me!'
41
43
  }.ostructify
42
44
 
43
- @flash_card.extend SuperMemo::SM2
44
- @flash_card.reset_spaced_repetition_data
45
+ @card.extend SuperMemo::SM2
46
+ @card.reset_spaced_repetition_data
45
47
  end
46
48
 
47
49
  it 'should raise DBC exception if class extended is missing fields' do
@@ -49,49 +51,63 @@ describe SuperMemo::SM2 do
49
51
  end
50
52
 
51
53
  it 'should initialize values' do
52
- @flash_card.easiness_factor.should == 2.5
53
- @flash_card.number_repetitions.should == 0
54
- @flash_card.repetition_interval.should == nil
55
- @flash_card.quality_of_last_recall.should == nil
56
- @flash_card.next_repetition.should == nil
54
+ @card.easiness_factor.should == 2.5
55
+ @card.number_repetitions.should == 0
56
+ @card.repetition_interval.should == nil
57
+ @card.quality_of_last_recall.should == nil
58
+ @card.next_repetition.should == nil
59
+ @card.last_studied.should == nil
57
60
  end
58
61
 
59
62
  it 'should schedule next repetition for tomorrow if repetition_interval = 0 and quality_of_last_recall = 4' do
60
- @flash_card.process_recall_result(4)
63
+ @card.process_recall_result(4)
61
64
 
62
- @flash_card.number_repetitions.should == 1
63
- @flash_card.repetition_interval.should == 1
64
- @flash_card.next_repetition.should == (Date.today + 1)
65
- @flash_card.easiness_factor.should be_close(2.5, 0.01)
65
+ @card.number_repetitions.should == 1
66
+ @card.repetition_interval.should == 1
67
+ @card.last_studied.should == Date.today
68
+ @card.next_repetition.should == (Date.today + 1)
69
+ @card.easiness_factor.should be_close(2.5, 0.01)
66
70
  end
67
71
 
68
72
  it 'should schedule next repetition for 6 days if repetition_interval = 1 and quality_of_last_recall = 4' do
69
- @flash_card.process_recall_result(4)
70
- @flash_card.process_recall_result(4)
73
+ @card.process_recall_result(4)
74
+ @card.process_recall_result(4)
71
75
 
72
- @flash_card.number_repetitions.should == 2
73
- @flash_card.repetition_interval.should == 6
74
- @flash_card.next_repetition.should == (Date.today + 6)
75
- @flash_card.easiness_factor.should be_close(2.5, 0.01)
76
+ @card.number_repetitions.should == 2
77
+ @card.repetition_interval.should == 6
78
+ @card.last_studied.should == Date.today
79
+ @card.next_repetition.should == (Date.today + 6)
80
+ @card.easiness_factor.should be_close(2.5, 0.01)
76
81
  end
77
82
 
78
83
  it 'should report as scheduled to recall (for today)' do
79
- @flash_card.next_repetition = Date.today
80
- @flash_card.scheduled_to_recall?.should == true
84
+ @card.next_repetition = Date.today
85
+ @card.scheduled_to_recall?.should == true
81
86
 
82
- @flash_card.next_repetition = Date.today - 1
83
- @flash_card.scheduled_to_recall?.should == true
87
+ @card.next_repetition = Date.today - 1
88
+ @card.scheduled_to_recall?.should == true
84
89
  end
85
90
 
86
91
  it 'should not be scheduled to recall' do
87
- @flash_card.next_repetition = nil
88
- @flash_card.scheduled_to_recall?.should == false
92
+ @card.next_repetition = nil
93
+ @card.scheduled_to_recall?.should == false
89
94
 
90
- @flash_card.next_repetition = Date.today + 1
91
- @flash_card.scheduled_to_recall?.should == false
95
+ @card.next_repetition = Date.today + 1
96
+ @card.scheduled_to_recall?.should == false
92
97
 
93
- @flash_card.next_repetition = Date.today + 99
94
- @flash_card.scheduled_to_recall?.should == false
98
+ @card.next_repetition = Date.today + 99
99
+ @card.scheduled_to_recall?.should == false
100
+ end
101
+
102
+ it 'should require repeating items that scored 3' do
103
+ @card.process_recall_result(3)
104
+ @card.next_repetition.should == Date.today
105
+
106
+ @card.process_recall_result(3)
107
+ @card.next_repetition.should == Date.today
108
+
109
+ @card.process_recall_result(4)
110
+ @card.next_repetition.should == Date.today + 1
95
111
  end
96
112
 
97
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tworgy-spaced-repetition
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Holroyd
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-22 00:00:00 +11:00
12
+ date: 2010-02-26 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency