-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import { | ||
AbstractScheduler, | ||
Card, | ||
createEmptyCard, | ||
DefaultInitSeedStrategy, | ||
fsrs, | ||
GenSeedStrategyWithCardId, | ||
Rating, | ||
StrategyMode, | ||
} from '../../src/fsrs' | ||
|
||
interface ICard extends Card { | ||
card_id: number | ||
} | ||
|
||
describe('seed strategy', () => { | ||
it('default seed strategy', () => { | ||
const seedStrategy = DefaultInitSeedStrategy | ||
const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy) | ||
const now = Date.UTC(2022, 11, 29, 12, 30, 0, 0) | ||
|
||
const card = createEmptyCard<ICard>(now, (card: Card) => { | ||
Object.assign(card, { card_id: 555 }) | ||
return card as ICard | ||
}) | ||
|
||
const record = f.repeat(card, now) | ||
const scheduler = new f['Scheduler'](card, now, f, { | ||
seed: seedStrategy, | ||
}) as AbstractScheduler | ||
|
||
const seed = seedStrategy.bind(scheduler)() | ||
console.debug('seed', seed) | ||
|
||
expect(f['_seed']).toBe(seed) | ||
}) | ||
}) | ||
|
||
describe('seed strategy with card ID', () => { | ||
it('use seedStrategy', () => { | ||
const seedStrategy = GenSeedStrategyWithCardId('card_id') | ||
const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy) | ||
|
||
expect(f['strategyHandler'].get(StrategyMode.SEED)).toBe(seedStrategy) | ||
|
||
f.clearStrategy() | ||
expect(f['strategyHandler'].get(StrategyMode.SEED)).toBeUndefined() | ||
}) | ||
it('clear seedStrategy', () => { | ||
const seedStrategy = GenSeedStrategyWithCardId('card_id') | ||
const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy) | ||
const now = Date.UTC(2022, 11, 29, 12, 30, 0, 0) | ||
|
||
const card = createEmptyCard<ICard>(now, (card: Card) => { | ||
Object.assign(card, { card_id: 555 }) | ||
return card as ICard | ||
}) | ||
|
||
f.repeat(card, now) | ||
let scheduler = new f['Scheduler'](card, now, f, { | ||
seed: seedStrategy, | ||
}) as AbstractScheduler | ||
|
||
const seed_with_card_id = seedStrategy.bind(scheduler)() | ||
console.debug('seed with card_id=555', seed_with_card_id) | ||
|
||
f.clearStrategy(StrategyMode.SEED) | ||
|
||
f.repeat(card, now) | ||
scheduler = new f['Scheduler'](card, now, f, { | ||
seed: DefaultInitSeedStrategy, | ||
}) as AbstractScheduler | ||
const basic_seed = DefaultInitSeedStrategy.bind(scheduler)() | ||
console.debug('basic_seed with card_id=555', basic_seed) | ||
|
||
expect(f['_seed']).toBe(basic_seed) | ||
|
||
expect(seed_with_card_id).not.toBe(basic_seed) | ||
}) | ||
|
||
it('exist card_id', () => { | ||
const seedStrategy = GenSeedStrategyWithCardId('card_id') | ||
const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy) | ||
const now = Date.UTC(2022, 11, 29, 12, 30, 0, 0) | ||
|
||
const card = createEmptyCard<ICard>(now, (card: Card) => { | ||
Object.assign(card, { card_id: 555 }) | ||
return card as ICard | ||
}) | ||
|
||
const record = f.repeat(card, now) | ||
const scheduler = new f['Scheduler'](card, now, f, { | ||
seed: seedStrategy, | ||
}) as AbstractScheduler | ||
|
||
const seed = seedStrategy.bind(scheduler)() | ||
console.debug('seed with card_id=555', seed) | ||
|
||
expect(f['_seed']).toBe(seed) | ||
}) | ||
|
||
it('not exist card_id', () => { | ||
const seedStrategy = GenSeedStrategyWithCardId('card_id') | ||
const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy) | ||
const now = Date.UTC(2022, 11, 29, 12, 30, 0, 0) | ||
|
||
const card = createEmptyCard<ICard>(now) | ||
|
||
const record = f.repeat(card, now) | ||
const scheduler = new f['Scheduler'](card, now, f, { | ||
seed: seedStrategy, | ||
}) as AbstractScheduler | ||
|
||
const seed = seedStrategy.bind(scheduler)() | ||
console.debug('seed with card_id=undefined(default)', seed) | ||
|
||
expect(f['_seed']).toBe(seed) | ||
}) | ||
|
||
it('card_id = -1', () => { | ||
const seedStrategy = GenSeedStrategyWithCardId('card_id') | ||
const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy) | ||
const now = Date.UTC(2022, 11, 29, 12, 30, 0, 0) | ||
|
||
const card = createEmptyCard<ICard>(now, (card: Card) => { | ||
Object.assign(card, { card_id: -1 }) | ||
return card as ICard | ||
}) | ||
|
||
const record = f.repeat(card, now) | ||
const scheduler = new f['Scheduler'](card, now, f, { | ||
seed: seedStrategy, | ||
}) as AbstractScheduler | ||
|
||
const seed = seedStrategy.bind(scheduler)() | ||
console.debug('with card_id=-1', seed) | ||
|
||
expect(f['_seed']).toBe(seed) | ||
expect(f['_seed']).toBe('0') | ||
}) | ||
|
||
it('card_id is undefined', () => { | ||
const seedStrategy = GenSeedStrategyWithCardId('card_id') | ||
const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy) | ||
const now = Date.UTC(2022, 11, 29, 12, 30, 0, 0) | ||
|
||
const card = createEmptyCard<ICard>(now, (card: Card) => { | ||
Object.assign(card, { card_id: undefined }) | ||
return card as ICard | ||
}) | ||
|
||
const item = f.next(card, now, Rating.Good) | ||
const scheduler = new f['Scheduler'](card, now, f, { | ||
seed: seedStrategy, | ||
}) as AbstractScheduler | ||
|
||
const seed = seedStrategy.bind(scheduler)() | ||
console.debug('seed with card_id=undefined', seed) | ||
|
||
expect(f['_seed']).toBe(seed) | ||
expect(f['_seed']).toBe(`${item.card.reps}`) | ||
}) | ||
|
||
it('card_id is null', () => { | ||
const seedStrategy = GenSeedStrategyWithCardId('card_id') | ||
const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy) | ||
const now = Date.UTC(2022, 11, 29, 12, 30, 0, 0) | ||
|
||
const card = createEmptyCard<ICard>(now, (card: Card) => { | ||
Object.assign(card, { card_id: null }) | ||
return card as ICard | ||
}) | ||
|
||
const item = f.next(card, now, Rating.Good) | ||
const scheduler = new f['Scheduler'](card, now, f, { | ||
seed: seedStrategy, | ||
}) as AbstractScheduler | ||
|
||
const seed = seedStrategy.bind(scheduler)() | ||
console.debug('seed with card_id=null', seed) | ||
|
||
expect(f['_seed']).toBe(seed) | ||
expect(f['_seed']).toBe(`${item.card.reps}`) | ||
}) | ||
}) |