forked from open-spaced-repetition/swift-fsrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFSRSTests.swift
102 lines (82 loc) · 3.11 KB
/
FSRSTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// FSRSTests.swift
// FSRSTests
//
// Created by Ben on 11/08/2023.
//
import XCTest
import FSRS
final class FSRSTests: XCTestCase {
func testExample() throws {
var f = FSRS()
let card = Card()
XCTAssertEqual(card.status, .new)
f.p.w = [
1.0171, 1.8296, 4.4145, 10.9355, 5.0965, 1.3322, 1.017, 0.0, 1.6243, 0.1369, 1.0321,
2.1866, 0.0661, 0.336, 1.7766, 0.1693, 2.9244
]
// Tue Nov 29 2022 12:30:00 UTC+0000
let now = Date(timeIntervalSince1970: 1669681800)
var schedulingCards = f.repeat(card: card, now: now)
print(schedulingCards)
let ratings: [Rating] = [
.good, .good, .good, .good, .good, .good, .again,
.again, .good, .good, .good, .good, .good
]
var ivlHistory: [Double] = []
var statusHistory: [Status] = []
for rating in ratings {
if let s = schedulingCards[rating] {
let card = s.card
ivlHistory.append(card.scheduledDays)
let revlog = s.reviewLog
statusHistory.append(revlog.status)
let now = card.due
schedulingCards = f.repeat(card: card, now: now)
log(schedulingInfo: schedulingCards)
}
}
print(ivlHistory)
print(statusHistory)
XCTAssertEqual(ivlHistory, [0, 4, 15, 49, 143, 379, 0, 0, 15, 37, 85, 184, 376])
XCTAssertEqual(statusHistory, [
.new, .learning, .review, .review, .review, .review, .review,
.relearning, .relearning, .review, .review, .review, .review
])
}
func testMemoState() throws {
var f = FSRS()
var card = Card()
f.p.w = [
1.0171, 1.8296, 4.4145, 10.9355, 5.0965, 1.3322, 1.017, 0.0, 1.6243, 0.1369, 1.0321,
2.1866, 0.0661, 0.336, 1.7766, 0.1693, 2.9244
]
// Tue Nov 29 2022 12:30:00 UTC+0000
var now = Date(timeIntervalSince1970: 1669681800)
var schedulingCards = f.repeat(card: card, now: now)
let ratingIvlList: [(Rating, Int)] = [
(.again, 0),
(.good, 0),
(.good, 1),
(.good, 3),
(.good, 8),
(.good, 21)
]
for (rating, ivl) in ratingIvlList {
card = schedulingCards[rating]!.card
now = Calendar.current.date(byAdding: .day, value: ivl, to: now)!
schedulingCards = f.repeat(card: card, now: now)
}
XCTAssertEqual(schedulingCards[.good]!.card.stability, 43.0554, accuracy: 0.0001)
XCTAssertEqual(schedulingCards[.good]!.card.difficulty, 7.7609, accuracy: 0.0001)
}
func log(schedulingInfo: [Rating: SchedulingInfo]) {
var data = [String: String]()
for key in schedulingInfo.keys {
if let info = schedulingInfo[key] {
data[String(describing: key)] = String(describing: info)
}
}
print("\(data)")
}
}