""" Working unit tests for particle modules based on actual module structure. """ import pytest from src.heurams.kernel.particles.atom import Atom from src.heurams.kernel.particles.electron import Electron from src.heurams.kernel.particles.nucleon import Nucleon from src.heurams.kernel.particles.orbital import Orbital class TestNucleon: """Test cases for Nucleon class based on actual implementation.""" def test_nucleon_creation(self): """Test basic Nucleon creation.""" payload = { "content": "Test content", "answer": "Test answer" } nucleon = Nucleon("test_id", payload) assert nucleon.ident == "test_id" assert nucleon.payload == payload def test_nucleon_getitem(self): """Test Nucleon item access.""" payload = {"content": "Question", "answer": "Answer"} nucleon = Nucleon("test_id", payload) assert nucleon["ident"] == "test_id" assert nucleon["content"] == "Question" assert nucleon["answer"] == "Answer" def test_nucleon_iteration(self): """Test Nucleon iteration over payload keys.""" payload = {"content": "Q", "answer": "A", "notes": "N"} nucleon = Nucleon("test_id", payload) keys = list(nucleon) assert "content" in keys assert "answer" in keys assert "notes" in keys def test_nucleon_length(self): """Test Nucleon length.""" payload = {"content": "Q", "answer": "A"} nucleon = Nucleon("test_id", payload) assert len(nucleon) == 2 def test_nucleon_placeholder(self): """Test Nucleon placeholder creation.""" nucleon = Nucleon.placeholder() assert isinstance(nucleon, Nucleon) assert nucleon.ident == "核子对象样例内容" assert nucleon.payload == {} class TestElectron: """Test cases for Electron class based on actual implementation.""" def test_electron_creation(self): """Test basic Electron creation.""" electron = Electron("test_id") assert electron.ident == "test_id" assert isinstance(electron.algodata, dict) def test_electron_with_algodata(self): """Test Electron creation with algorithm data.""" algodata = {"supermemo2": {"efactor": 2.5, "rept": 0}} electron = Electron("test_id", algodata) assert electron.ident == "test_id" assert electron.algodata == algodata def test_electron_activate(self): """Test Electron activation.""" electron = Electron("test_id") # Should not raise an exception electron.activate() def test_electron_modify(self): """Test Electron modification.""" electron = Electron("test_id") # Should not raise an exception electron.modify("efactor", 2.8) def test_electron_is_activated(self): """Test Electron activation status.""" electron = Electron("test_id") # Should not raise an exception result = electron.is_activated() assert isinstance(result, (bool, int)) def test_electron_getitem(self): """Test Electron item access.""" electron = Electron("test_id") assert electron["ident"] == "test_id" # Should be able to access algorithm data after initialization assert "efactor" in electron.algodata[electron.algo] def test_electron_placeholder(self): """Test Electron placeholder creation.""" electron = Electron.placeholder() assert isinstance(electron, Electron) assert electron.ident == "电子对象样例内容" class TestOrbital: """Test cases for Orbital TypedDict.""" def test_orbital_creation(self): """Test basic Orbital creation.""" orbital = Orbital( quick_view=[["cloze", 1], ["mcq", 0.5]], recognition=[["recognition", 1]], final_review=[["cloze", 0.7], ["mcq", 0.7]], puzzle_config={"cloze": {"from": "content"}, "mcq": {"from": "keyword_note"}} ) assert isinstance(orbital, dict) assert "quick_view" in orbital assert "recognition" in orbital assert "final_review" in orbital assert "puzzle_config" in orbital def test_orbital_quick_view(self): """Test Orbital quick_view configuration.""" orbital = Orbital( quick_view=[["cloze", 1], ["mcq", 0.5]], recognition=[], final_review=[], puzzle_config={} ) assert len(orbital["quick_view"]) == 2 assert orbital["quick_view"][0] == ["cloze", 1] class TestAtom: """Test cases for Atom class based on actual implementation.""" def test_atom_creation(self): """Test basic Atom creation.""" atom = Atom("test_atom") assert atom.ident == "test_atom" assert isinstance(atom.registry, dict) def test_atom_link(self): """Test Atom linking components.""" atom = Atom("test_atom") nucleon = Nucleon("nucleon_id", {"content": "Test"}) # Link nucleon atom.link("nucleon", nucleon) assert atom["nucleon"] == nucleon def test_atom_getitem(self): """Test Atom item access.""" atom = Atom("test_atom") # Should be able to access register items assert atom["nucleon"] is None assert atom["electron"] is None assert atom["orbital"] is None def test_atom_setitem(self): """Test Atom item assignment.""" atom = Atom("test_atom") nucleon = Nucleon("nucleon_id", {"content": "Test"}) # Set nucleon atom["nucleon"] = nucleon assert atom["nucleon"] == nucleon def test_atom_placeholder(self): """Test Atom placeholder creation.""" placeholder = Atom.placeholder() assert isinstance(placeholder, tuple) assert len(placeholder) == 3 assert isinstance(placeholder[0], Electron) assert isinstance(placeholder[1], Nucleon)