Add variable question distractor pools

This commit is contained in:
hz
2026-07-13 10:15:05 -05:00
parent f2c59388eb
commit 93154d5925
24 changed files with 1040 additions and 247 deletions
+59
View File
@@ -0,0 +1,59 @@
extends SceneTree
var failures := 0
func _initialize() -> void:
var service = load("res://scripts/autoload/block_session_service.gd").new()
var question := _question(9)
var prepared: Dictionary = service._prepare_question_choices(question.duplicate(true))
_check_presented(prepared)
var stable: Dictionary = service._prepare_question_choices(prepared.duplicate(true))
_assert(stable.get("presented_choices", []) == prepared.get("presented_choices", []), "session choices must remain stable")
var observed_sets := {}
for iteration in range(40):
var rerolled: Dictionary = service._prepare_question_choices(question.duplicate(true))
_check_presented(rerolled)
var ids := _ids(rerolled.get("presented_choices", []))
ids.sort()
observed_sets[",".join(ids)] = true
_assert(observed_sets.size() > 1, "future sessions should be able to present different distractors")
var legacy: Dictionary = service._prepare_question_choices(_question(5))
_check_presented(legacy)
_assert(_ids(legacy.get("presented_choices", [])).size() == 5, "legacy five-choice questions must show all choices")
service.free()
quit(1 if failures > 0 else 0)
func _question(count: int) -> Dictionary:
var choices: Array = []
for index in range(count):
choices.append({"id": String.chr(65 + index), "text": "Choice %d" % index})
return {"choices": choices, "correct_choice_id": "A"}
func _check_presented(question: Dictionary) -> void:
var ids := _ids(question.get("presented_choices", []))
_assert(ids.size() == 5, "exactly five choices must be presented")
_assert(ids.has("A"), "the correct answer must be presented")
var unique := {}
for id in ids:
unique[id] = true
_assert(unique.size() == ids.size(), "presented choices must be unique")
func _ids(choices: Array) -> Array:
var ids: Array = []
for choice in choices:
ids.append(str(choice.get("id", "")))
return ids
func _assert(condition: bool, message: String) -> void:
if condition:
return
failures += 1
push_error(message)
+1
View File
@@ -0,0 +1 @@
uid://dphnt1gskhhna