Skip to content

Commit

Permalink
fix: update Alphagram retrieval in GetCardInformation and adjust test…
Browse files Browse the repository at this point in the history
…s accordingly
  • Loading branch information
domino14 committed Dec 24, 2024
1 parent 5681e25 commit a90b7b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/wordvault/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *Server) GetCardInformation(ctx context.Context, req *connect.Request[pb
Lexicon: req.Msg.Lexicon,
// Just return the alphagram here. The purpose of this endpoint is for
// its metadata, not to quiz on any of the cards.
Alphagram: &searchpb.Alphagram{Alphagram: req.Msg.Alphagrams[i]},
Alphagram: &searchpb.Alphagram{Alphagram: rows[i].Alphagram},
CardJsonRepr: cardbts,
Retrievability: f.GetRetrievability(fcard.Card, s.Nower.Now()),
ReviewLog: revlogbts,
Expand Down
17 changes: 12 additions & 5 deletions internal/wordvault/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,27 @@ func TestGetCards(t *testing.T) {
is.NoErr(err)
fmt.Println(info)
is.Equal(len(info.Msg.Cards), 2)

cardIndex := make(map[string]int)
for i, card := range info.Msg.Cards {
cardIndex[card.Alphagram.Alphagram] = i
}

is.Equal(info.Msg.Cards[cardIndex["ADEEGMMO"]].Alphagram.Alphagram, "ADEEGMMO")
// Wow still a decent chance of remembering it after 76 years
is.True(info.Msg.Cards[0].Retrievability > 0.3)
is.Equal(info.Msg.Cards[0].Alphagram.Alphagram, "ADEEGMMO")

is.True(info.Msg.Cards[cardIndex["ADEEGMMO"]].Retrievability > 0.3)

card := fsrs.Card{}
err = json.Unmarshal(info.Msg.Cards[0].CardJsonRepr, &card)
err = json.Unmarshal(info.Msg.Cards[cardIndex["ADEEGMMO"]].CardJsonRepr, &card)

is.Equal(card.Reps, uint64(3))
is.Equal(card.Difficulty, float64(1))
is.Equal(card.State, fsrs.Review)

err = json.Unmarshal(info.Msg.Cards[1].CardJsonRepr, &card)
err = json.Unmarshal(info.Msg.Cards[cardIndex["ADEEHMMO"]].CardJsonRepr, &card)

is.Equal(info.Msg.Cards[1].Alphagram.Alphagram, "ADEEHMMO")
is.Equal(info.Msg.Cards[cardIndex["ADEEHMMO"]].Alphagram.Alphagram, "ADEEHMMO")
is.Equal(card.State, fsrs.New)

}
Expand Down

0 comments on commit a90b7b9

Please sign in to comment.