bugfix
This commit is contained in:
@@ -33,7 +33,30 @@ def parse_and_validate_shape(s: Any) -> list[dict]:
|
||||
raise HttpError(400, f'shape[{i}]: optionsCount от 2 до 12.')
|
||||
if n < 2 or n > 12:
|
||||
raise HttpError(400, f'shape[{i}]: optionsCount от 2 до 12.')
|
||||
out.append({'optionsCount': n, 'hasMultipleAnswers': bool(row.get('hasMultipleAnswers'))})
|
||||
has_multi = bool(row.get('hasMultipleAnswers'))
|
||||
raw_min = row.get('minCorrect', 1)
|
||||
raw_max = row.get('maxCorrect', n if has_multi else 1)
|
||||
try:
|
||||
min_c = int(float(raw_min))
|
||||
max_c = int(float(raw_max))
|
||||
except (TypeError, ValueError):
|
||||
raise HttpError(400, f'shape[{i}]: minCorrect/maxCorrect должны быть числами.')
|
||||
if not has_multi:
|
||||
min_c = 1
|
||||
max_c = 1
|
||||
if min_c < 1 or max_c < 1 or min_c > max_c or max_c > n:
|
||||
raise HttpError(
|
||||
400,
|
||||
f'shape[{i}]: корректный диапазон правильных ответов — от 1 до {n}, min<=max.',
|
||||
)
|
||||
out.append(
|
||||
{
|
||||
'optionsCount': n,
|
||||
'hasMultipleAnswers': has_multi,
|
||||
'minCorrect': min_c,
|
||||
'maxCorrect': max_c,
|
||||
}
|
||||
)
|
||||
return out
|
||||
|
||||
|
||||
@@ -51,7 +74,10 @@ def generate_full_test_by_shape(test_title: str, test_description: str, shape: l
|
||||
lines = []
|
||||
for i, sh in enumerate(shape):
|
||||
if sh['hasMultipleAnswers']:
|
||||
tail = 'несколько вариантов помечены как верные (hasMultipleAnswers: true).'
|
||||
tail = (
|
||||
'несколько вариантов помечены как верные (hasMultipleAnswers: true), '
|
||||
f'число правильных от {sh["minCorrect"]} до {sh["maxCorrect"]}.'
|
||||
)
|
||||
else:
|
||||
tail = 'ровно один верный вариант (hasMultipleAnswers: false).'
|
||||
lines.append(f'Вопрос {i + 1}: ровно {sh["optionsCount"]} вариантов ответа; {tail}')
|
||||
|
||||
Reference in New Issue
Block a user