阅读"在对话里找到答案": - 16 道题全部重写,干扰项真实出现在对话里,靠说话人归属或否定句才能作答 - 选项按题目内容确定性打乱,答案不再固定排第一;听力环节同样处理 - 去掉超纲干扰项、重复题干,收紧自由作答匹配(过去单个字母也能判对) AI 情境对话: - 提示词区分"AI 这一句要做什么"与"学习者随后要完成什么",并下发已教词句清单 - JSON 只强制 reply,translation/feedback 可选;不再索要用不上的 slots/evidence - AI 不可用时页面明确提示当前回复来自内置示范脚本 - 删掉按 stage 下标猜中文翻译的兜底,避免译文与英文对不上 - 整课对话改用逐轮必需表达校验,替换"关键词沾边就算过";修正自由场景正则误伤 - 总结的"完成任务"按实际通过的轮次生成;模型点评只在结束页呈现一次 - 自由场景支持草稿续练(独立存储槽);修正回答轮数文案与永不解锁的场景标注 同时提交此前工作区中累积的改动:SenseVoice 本地识别、查词/句型解析卡、 复习与测评页调整等,并补充对话校验、选项分布和句子解析的测试。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
151 lines
5.1 KiB
Dart
151 lines
5.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
||
import 'package:kouyu_english/core/seed_courses.dart';
|
||
|
||
const _digitWords = {
|
||
'0': 'zero',
|
||
'1': 'one',
|
||
'2': 'two',
|
||
'3': 'three',
|
||
'4': 'four',
|
||
'5': 'five',
|
||
'6': 'six',
|
||
'7': 'seven',
|
||
'8': 'eight',
|
||
'9': 'nine',
|
||
};
|
||
|
||
const _skipWords = {'a', 'an', 'the', 'my', 'is', 'it', 'im', 'to', 'you'};
|
||
|
||
String _normalize(String text) =>
|
||
text.toLowerCase().replaceAll(RegExp(r'[^a-z0-9一-龥]'), '');
|
||
|
||
/// 选项在对话里是否真的出现过。数字选项按英文读法展开(138 → onethreeeight),
|
||
/// 逐字母拼写(S-H-E-N)先去掉连字符。
|
||
bool _appearsInReading(String reading, String option) {
|
||
final haystack = _normalize(
|
||
reading.replaceAllMapped(
|
||
RegExp(r'\d'),
|
||
(match) => _digitWords[match[0]]!,
|
||
),
|
||
);
|
||
final tokens = option
|
||
.replaceAll('-', '')
|
||
.replaceAllMapped(RegExp(r'\d'), (match) => _digitWords[match[0]]!)
|
||
.toLowerCase()
|
||
.split(RegExp(r'[^a-z0-9一-龥]+'))
|
||
.where((token) => token.length > 1 && !_skipWords.contains(token));
|
||
return tokens.isNotEmpty && tokens.every(haystack.contains);
|
||
}
|
||
|
||
void main() {
|
||
final activities = <String, LessonActivity>{
|
||
...a0Activities,
|
||
...a0SegmentActivities,
|
||
};
|
||
|
||
group('阅读找答案题', () {
|
||
test('每题三个选项,第一项是标准答案', () {
|
||
for (final entry in activities.entries) {
|
||
final activity = entry.value;
|
||
expect(activity.answers, hasLength(3), reason: entry.key);
|
||
expect(activity.readingOptions, hasLength(3), reason: entry.key);
|
||
expect(
|
||
activity.readingOptions.first,
|
||
activity.readingAnswer,
|
||
reason: '${entry.key}:readingOptions 第一项应是标准答案',
|
||
);
|
||
expect(
|
||
activity.readingOptions.toSet(),
|
||
hasLength(3),
|
||
reason: '${entry.key}:选项不能重复',
|
||
);
|
||
}
|
||
});
|
||
|
||
test('至少两个选项在对话中出现,必须读懂才能选', () {
|
||
for (final entry in activities.entries) {
|
||
final activity = entry.value;
|
||
final present = activity.readingOptions
|
||
.where((option) => _appearsInReading(activity.reading, option))
|
||
.toList();
|
||
expect(
|
||
_appearsInReading(activity.reading, activity.readingAnswer),
|
||
isTrue,
|
||
reason: '${entry.key}:答案必须能在对话里找到',
|
||
);
|
||
expect(
|
||
present.length,
|
||
greaterThanOrEqualTo(2),
|
||
reason:
|
||
'${entry.key}:只有 ${present.length} 个选项出现在对话中,'
|
||
'学习者不读对话也能挑出唯一出现过的那个',
|
||
);
|
||
}
|
||
});
|
||
|
||
test('选项之间不构成子串,避免判分时误判', () {
|
||
for (final entry in activities.entries) {
|
||
final options = entry.value.readingOptions.map(_normalize).toList();
|
||
for (var i = 0; i < options.length; i++) {
|
||
for (var j = i + 1; j < options.length; j++) {
|
||
expect(
|
||
options[i].contains(options[j]) ||
|
||
options[j].contains(options[i]),
|
||
isFalse,
|
||
reason: '${entry.key}:“${entry.value.readingOptions[i]}”与'
|
||
'“${entry.value.readingOptions[j]}”互为子串,会被判分逻辑当成同一个答案',
|
||
);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
|
||
test('打乱后的选项内容不变且顺序稳定', () {
|
||
for (final entry in activities.entries) {
|
||
final activity = entry.value;
|
||
final seed = '${activity.readingQuestion}-reading';
|
||
final first = shuffledOptions(activity.readingOptions, seed);
|
||
final second = shuffledOptions(activity.readingOptions, seed);
|
||
expect(first, second, reason: entry.key);
|
||
expect(
|
||
first.toSet(),
|
||
activity.readingOptions.toSet(),
|
||
reason: entry.key,
|
||
);
|
||
}
|
||
});
|
||
|
||
test('正确答案在三个位置上都出现,不集中在某一位', () {
|
||
final readingSlots = <int, int>{};
|
||
final listeningSlots = <int, int>{};
|
||
for (final activity in activities.values) {
|
||
final reading = shuffledOptions(
|
||
activity.readingOptions,
|
||
'${activity.readingQuestion}-reading',
|
||
);
|
||
final readingSlot = reading.indexOf(activity.readingAnswer);
|
||
readingSlots[readingSlot] = (readingSlots[readingSlot] ?? 0) + 1;
|
||
final listening = shuffledOptions(
|
||
activity.answers,
|
||
'${activity.listening}-listening',
|
||
);
|
||
final listeningSlot = listening.indexOf(activity.answers.first);
|
||
listeningSlots[listeningSlot] = (listeningSlots[listeningSlot] ?? 0) + 1;
|
||
}
|
||
for (final slots in [readingSlots, listeningSlots]) {
|
||
expect(slots.keys.toSet(), {0, 1, 2});
|
||
for (final count in slots.values) {
|
||
expect(count, lessThan(activities.length ~/ 2));
|
||
}
|
||
}
|
||
});
|
||
|
||
test('题干不重复,复习时不会撞题', () {
|
||
final questions = activities.values
|
||
.map((activity) => activity.readingQuestion)
|
||
.toList();
|
||
expect(questions.toSet(), hasLength(questions.length));
|
||
});
|
||
});
|
||
}
|