From d4f33e9a886363008385b4d76b475e53c5689cdb Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Wed, 25 Sep 2024 22:19:41 +0200 Subject: Add session class with basic test coverage --- src/session_integrationtest.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/session_integrationtest.py (limited to 'src/session_integrationtest.py') diff --git a/src/session_integrationtest.py b/src/session_integrationtest.py new file mode 100644 index 0000000..2c5d608 --- /dev/null +++ b/src/session_integrationtest.py @@ -0,0 +1,46 @@ +import pytest +import json +from session import Session + +@pytest.fixture +def cardFiles(tmp_path): + card_files = [ + tmp_path / "test1.fcard", + tmp_path / "test2.fcard", + ] + + for i, c in enumerate(card_files): + with open(c, "w") as f: + for j in range(0, 3): + f.write(f"FRONT\nFile {i}, card {j} front\nBACK\nback\n") + + return card_files + +@pytest.fixture +def stateFile(tmp_path): + return tmp_path / "state.json" + +def test_practiceSession(cardFiles, stateFile): + session = Session("brutal", cardFiles, stateFile) + + c = 0 + for card in session.practice(5): + c += 1 + + assert c == 5 + +def test_testSession(cardFiles, stateFile): + session = Session("brutal", cardFiles, stateFile) + + c = 0 + for i, (card, correct) in enumerate(session.test(5)): + c += 1 + correct(i % 2 == 0) + + assert c == 5 + + with open(stateFile, "r") as f: + state = json.load(f) + latest_scores = [history[-1] for id, history in state.items()] + assert latest_scores.count(0) == 2 + assert latest_scores.count(1) == 3 -- cgit v1.2.3