Anki/tests/test_sched.py
Damien Elmes b0b4074cbd start work on learn mode, change models, more
- model config is now stored as a json-serialized dict, which allows us to
  quickly gather the info and allows for adding extra options more easily in
  the future
- denormalize modelId into the cards table, so we can get the model scheduling
  information without having to hit the facts table
- remove position - since we will handle spacing differently we don't need a
  separate variable to due to define sort order
- remove lastInterval from cards; the new cram mode and review early shouldn't
  need it
- successive->streak
- add new columns for learn mode
- move cram mode into new file; learn more and review early need more thought
- initial work on learn mode
- initial unit tests
2011-04-28 09:23:28 +09:00

62 lines
1.6 KiB
Python

# coding: utf-8
import time
from tests.shared import assertException, getDeck
from anki.stdmodels import BasicModel
#from anki.db import *
def getEmptyDeck():
d = getDeck()
d.addModel(BasicModel())
d.db.commit()
return d
def test_basics():
d = getEmptyDeck()
assert not d.getCard()
def test_learn():
d = getEmptyDeck()
# add a fact
f = d.newFact()
f['Front'] = u"one"; f['Back'] = u"two"
f = d.addFact(f)
d.db.flush()
# set as a learn card and rebuild queues
d.db.statement("update cards set queue=0, type=2")
d.reset()
# getCard should return it, since it's due in the past
c = d.getCard()
assert c
# it should have no cycles and a grade of 0
assert c.grade == c.cycles == 0
# fail it
d.answerCard(c, 1)
# it should by due in 30 seconds
assert round(c.due - time.time()) == 30
# and have 1 cycle, but still a zero grade
assert c.grade == 0
assert c.cycles == 1
# pass it once
d.answerCard(c, 2)
# it should by due in 3 minutes
assert round(c.due - time.time()) == 180
# and it should be grade 1 now
assert c.grade == 1
assert c.cycles == 2
# pass again
d.answerCard(c, 2)
# it should by due in 10 minutes
assert round(c.due - time.time()) == 600
# and it should be grade 1 now
assert c.grade == 2
assert c.cycles == 3
# the next pass should graduate the card
assert c.queue == 0
assert c.type == 2
d.answerCard(c, 2)
assert c.queue == 1
assert c.type == 1
print "test intervals, check early removal, etc"