-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdeck_manager_test.go
More file actions
67 lines (54 loc) · 1.62 KB
/
Copy pathdeck_manager_test.go
File metadata and controls
67 lines (54 loc) · 1.62 KB
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
package leaf
import (
"io/ioutil"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDeckManager(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "leaf.db")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
db, err := OpenBoltStore(tmpfile.Name())
require.NoError(t, err)
dm, err := NewDeckManager("./fixtures", db, OutputFormatOrg)
require.NoError(t, err)
t.Run("ReviewDecks", func(t *testing.T) {
decks, err := dm.ReviewDecks()
require.NoError(t, err)
require.Len(t, decks, 2)
deck := decks[0]
assert.Equal(t, "Hiragana", deck.Name)
assert.Equal(t, 46, deck.CardsReady)
assert.InDelta(t, time.Since(deck.NextReviewAt), 0, float64(time.Minute))
})
t.Run("ReviewSession", func(t *testing.T) {
session, err := dm.ReviewSession("Hiragana")
require.NoError(t, err)
assert.Equal(t, 20, session.Total())
assert.Equal(t, []string{"for-tests"}, session.Sides())
question := session.Next()
require.NoError(t, session.Again())
err = db.RangeStats("Hiragana", SRSSupermemo2PlusCustom, func(card string, s *Stats) bool {
if card != question {
return true
}
sm := s.SRSAlgorithm.(*Supermemo2PlusCustom)
assert.InDelta(t, 0.45, sm.Difficulty, 0.01)
assert.InDelta(t, 0.2, sm.Interval, 0.01)
return false
})
require.NoError(t, err)
})
t.Run("DeckStats", func(t *testing.T) {
stats, err := dm.DeckStats("Hiragana")
require.NoError(t, err)
assert.Len(t, stats, 46)
s := stats[0]
assert.NotEmpty(t, s.Question)
sm := s.SRSAlgorithm.(*Supermemo2PlusCustom)
assert.InDelta(t, 0.3, sm.Difficulty, 0.01)
})
}