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
|
import pytest
from flashcards import scheduler_brutal
from flashcards.scheduler_brutal import SchedulerBrutal as UUT
from flashcards.card import Card
# Force HISTORY_DEPTH to simplify testing
scheduler_brutal.HISTORY_DEPTH = 3
#--------------------------------------------------------------------------
# Scheduling behaviour
#--------------------------------------------------------------------------
def test_scheduling():
cards = {str(id): Card("", "") for id in range(0, 10)}
state = {
"0": [1, 1, 1],
"1": [0, 0, 0],
"2": [0, 0, 1],
"3": [1, 0, 0],
"4": [None, None, 1 ],
"5": [None, 1, None],
"6": [1, None, None],
"7": [None, None, 0 ],
"8": [0, 0, None],
"9": [None, None, None],
}
expected_priority = ["9", "6", "5", "8", "7", "4", "1", "3", "2", "0"]
uut = UUT(cards, state)
for i in range(0, len(expected_priority)):
assert set(uut.practice(i + 1)) == set(expected_priority[0:i + 1])
#--------------------------------------------------------------------------
# State update
#--------------------------------------------------------------------------
def test_stateUpdate():
cards = {"0": Card("f", "b"), "1": Card("a", "b"), "2": Card("c", "d")}
state = {"0": [1, 0, 1], "1": [1, 0, 0], "2": [0, 0, 1]}
uut = UUT(cards, state)
# Unknown IDs in the result are silently ignored
result = {"0": 1, "1": 0, "3": 0}
expected_state = {"0": [0, 1, 1], "1": [0, 0, 0], "2": [0, 1, None]}
uut.update(result)
assert uut.getState() == expected_state
#--------------------------------------------------------------------------
# State corrections
#--------------------------------------------------------------------------
def test_stateWhenCardsChanged():
cards = {"0": Card("f", "b"), "1": Card("a", "b")}
initial_state = {"0": [1, 0, 1], "2": [0, 0, 0]}
expected_state = {"0": [1, 0, 1], "1": [None, None, None]}
uut = UUT(cards, initial_state)
assert uut.getState() == expected_state
def test_stateWhenHistoryDepthIncreased():
scheduler_brutal.HISTORY_DEPTH = 5
cards = {"0": Card("f", "b"), "1": Card("a", "b"), "2": Card("new", "new")}
initial_state = {"0": [1, 0, 1], "1": [0, 0, 0]}
expected_state = {"0": [None, None, 1, 0, 1], "1": [None, None, 0, 0, 0], "2": [None] * 5}
uut = UUT(cards, initial_state)
assert uut.getState() == expected_state
def test_stateWhenHistoryDepthDecreased():
scheduler_brutal.HISTORY_DEPTH = 1
cards = {"0": Card("f", "b"), "1": Card("a", "b"), "2": Card("new", "new")}
initial_state = {"0": [1, 0, 0], "1": [0, 0, 1]}
expected_state = {"0": [0], "1": [1], "2": [None]}
uut = UUT(cards, initial_state)
assert uut.getState() == expected_state
|