-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/set same seed should return the same interval (#114)
* Fix/wrong get seed * Test/add same seed test * bump version to 4.1.2
- Loading branch information
Showing
4 changed files
with
48 additions
and
3 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,45 @@ | ||
import { createEmptyCard, fsrs, Rating } from '../../src/fsrs' | ||
|
||
describe('fuzz same seed', () => { | ||
const MOCK_NOW = new Date(2024, 7, 15) | ||
const size = 100 | ||
|
||
// https://github.com/open-spaced-repetition/ts-fsrs/issues/113 | ||
it('should be the same[short-term]', () => { | ||
const { card } = fsrs().next(createEmptyCard(), MOCK_NOW, Rating.Good) | ||
const scheduler = fsrs({ enable_fuzz: true }) | ||
const MOCK_TOMORROW = new Date(2024, 7, 16) | ||
|
||
const timestamp: number[] = [] | ||
for (let count = 0; count < size; count++) { | ||
setTimeout(() => { | ||
const _card = scheduler.next(card, MOCK_TOMORROW, Rating.Good).card | ||
timestamp.push(_card.due.getTime()) | ||
if (timestamp.length === size) { | ||
expect(timestamp.every((value) => value === timestamp[0])).toBe(true) | ||
} | ||
}, 50) | ||
} | ||
}) | ||
|
||
it('should be the same[long-term]', () => { | ||
const { card } = fsrs({ enable_short_term: false }).next( | ||
createEmptyCard(), | ||
MOCK_NOW, | ||
Rating.Good | ||
) | ||
const scheduler = fsrs({ enable_fuzz: true, enable_short_term: false }) | ||
const MOCK_TOMORROW = new Date(2024, 7, 18) | ||
|
||
const timestamp: number[] = [] | ||
for (let count = 0; count < size; count++) { | ||
setTimeout(() => { | ||
const _card = scheduler.next(card, MOCK_TOMORROW, Rating.Good).card | ||
timestamp.push(_card.due.getTime()) | ||
if (timestamp.length === size) { | ||
expect(timestamp.every((value) => value === timestamp[0])).toBe(true) | ||
} | ||
}, 50) | ||
} | ||
}) | ||
}) |
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
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
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