Skip to content

Commit

Permalink
Refactor/reschedule (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishiko732 authored Oct 11, 2024
1 parent 5de8318 commit 34e59a4
Show file tree
Hide file tree
Showing 10 changed files with 986 additions and 212 deletions.
24 changes: 20 additions & 4 deletions __tests__/algorithm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('next_interval', () => {
(_, i) => (i + 1) / 10
)
const intervals: number[] = desired_retentions.map((r) =>
fsrs({ request_retention: r }).next_interval(1.0, 0, false)
fsrs({ request_retention: r }).next_interval(1.0, 0)
)
expect(intervals).toEqual([422, 102, 43, 22, 13, 8, 4, 2, 1, 1])
})
Expand All @@ -284,14 +284,15 @@ describe('next_interval', () => {
const params = generatorParameters({ maximum_interval: 365 })
const intervalModifier =
(Math.pow(params.request_retention, 1 / DECAY) - 1) / FACTOR
const f: FSRS = fsrs(params)
let f: FSRS = fsrs(params)

const s = 737.47
const next_ivl = f.next_interval(s, 0, false)
const next_ivl = f.next_interval(s, 0)
expect(next_ivl).toEqual(params.maximum_interval)

const t_fuzz = 98
const next_ivl_fuzz = f.next_interval(s, t_fuzz, true)
f = fsrs({ ...params, enable_fuzz: true })
const next_ivl_fuzz = fsrs(params).next_interval(s, t_fuzz)
const { min_ivl, max_ivl } = get_fuzz_range(
Math.round(s * intervalModifier),
t_fuzz,
Expand Down Expand Up @@ -331,6 +332,21 @@ describe('FSRS apply_fuzz', () => {
expect(fuzzedInterval).toBeGreaterThanOrEqual(min_ivl)
expect(fuzzedInterval).toBeLessThanOrEqual(max_ivl)
})

test('return original interval when ivl is less than 3', () => {
const ivl = 3
const enable_fuzz = true
const algorithm = new FSRSAlgorithm({ enable_fuzz: enable_fuzz })
algorithm.seed = 'NegativeS2Seed'
const { min_ivl, max_ivl } = get_fuzz_range(
Math.round(ivl),
0,
default_maximum_interval
)
const fuzzedInterval = algorithm.apply_fuzz(ivl, 0)
expect(fuzzedInterval).toBeGreaterThanOrEqual(min_ivl)
expect(fuzzedInterval).toBeLessThanOrEqual(max_ivl)
})
})

describe('change Params', () => {
Expand Down
Loading

0 comments on commit 34e59a4

Please sign in to comment.