mirror of
https://github.com/saymrwulf/QuantumLearning.git
synced 2026-05-14 20:58:00 +00:00
138 lines
3.6 KiB
Python
138 lines
3.6 KiB
Python
import ipywidgets as widgets
|
|
|
|
from quantum_learning import load_assessment_blueprint
|
|
from qiskit import QuantumCircuit
|
|
|
|
from quantum_learning.interactive import (
|
|
editable_circuit_lab,
|
|
evidence_checklist,
|
|
feedback_iteration_panel,
|
|
multiple_choice_quiz,
|
|
quiz_block,
|
|
reflection_box,
|
|
rubric_scorecard,
|
|
step_reference_table,
|
|
)
|
|
|
|
|
|
def test_multiple_choice_quiz_returns_widget():
|
|
widget = multiple_choice_quiz(
|
|
prompt="What does H do in the simplest story?",
|
|
options=["Prepare superposition", "Measure the qubit", "Delete the wire"],
|
|
correct_index=0,
|
|
explanation="H is used here as a preparation step.",
|
|
)
|
|
assert widget.children
|
|
|
|
|
|
def test_quiz_block_returns_widget_group():
|
|
widget = quiz_block(
|
|
[
|
|
{
|
|
"prompt": "Is this a quiz?",
|
|
"options": ["Yes", "No"],
|
|
"correct_index": 0,
|
|
"explanation": "Yes.",
|
|
}
|
|
],
|
|
heading="Check",
|
|
)
|
|
assert widget.children
|
|
|
|
|
|
def test_step_reference_table_returns_html_widget():
|
|
widget = step_reference_table(
|
|
[
|
|
{
|
|
"marker": "[1]",
|
|
"code_focus": "Apply H",
|
|
"diagram_effect": "Create branching",
|
|
"why_it_matters": "Preparation matters",
|
|
}
|
|
]
|
|
)
|
|
assert "[1]" in widget.value
|
|
|
|
|
|
def test_reflection_box_returns_widget():
|
|
widget = reflection_box("What changed in your mental model?")
|
|
assert widget.children
|
|
|
|
|
|
def test_editable_circuit_lab_builds_widget():
|
|
widget = editable_circuit_lab(
|
|
initial_code="""
|
|
circuit = QuantumCircuit(1, 1, name="demo")
|
|
circuit.h(0)
|
|
circuit.measure(0, 0)
|
|
""",
|
|
context={"QuantumCircuit": QuantumCircuit},
|
|
title="Demo Lab",
|
|
)
|
|
assert widget.children
|
|
|
|
|
|
def test_rubric_scorecard_builds_widget():
|
|
rubric = load_assessment_blueprint().get_rubric("module_self_review")
|
|
widget = rubric_scorecard(rubric, title="Review")
|
|
assert widget.children
|
|
|
|
|
|
def test_rubric_scorecard_updates_summary_when_sliders_change():
|
|
rubric = load_assessment_blueprint().get_rubric("capstone_design_review")
|
|
widget = rubric_scorecard(rubric, title="Capstone Review")
|
|
|
|
sliders = [child for child in widget.children if isinstance(child, widgets.IntSlider)]
|
|
summary = widget.children[-1]
|
|
|
|
assert len(sliders) == 7
|
|
assert "Total:</b> 0/28" in summary.value
|
|
|
|
for slider in sliders:
|
|
slider.value = slider.max
|
|
|
|
assert "Total:</b> 28/28" in summary.value
|
|
assert "Band:</b> mastery-ready" in summary.value
|
|
|
|
|
|
def test_feedback_iteration_panel_builds_widget():
|
|
widget = feedback_iteration_panel(
|
|
title="Revision Loop",
|
|
prompt="State the claim, evidence, risk, and next step.",
|
|
)
|
|
assert widget.children
|
|
|
|
|
|
def test_evidence_checklist_builds_widget():
|
|
widget = evidence_checklist(
|
|
[
|
|
"Objective stated",
|
|
"Evidence cited",
|
|
"Risk named",
|
|
],
|
|
title="Checklist",
|
|
)
|
|
assert widget.children
|
|
|
|
|
|
def test_evidence_checklist_updates_summary_when_boxes_change():
|
|
widget = evidence_checklist(
|
|
[
|
|
"Objective stated",
|
|
"Evidence cited",
|
|
"Risk named",
|
|
],
|
|
title="Checklist",
|
|
)
|
|
|
|
checkboxes = [child for child in widget.children if isinstance(child, widgets.Checkbox)]
|
|
summary = widget.children[-1]
|
|
|
|
assert len(checkboxes) == 3
|
|
assert "Completion:</b> 0%" in summary.value
|
|
|
|
for checkbox in checkboxes:
|
|
checkbox.value = True
|
|
|
|
assert "Completion:</b> 100%" in summary.value
|
|
assert "Ready for review:</b> Yes" in summary.value
|