| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace Tests\Unit;
- use App\Support\AnswerSolutionStepMarkerInjector;
- use PHPUnit\Framework\TestCase;
- class AnswerSolutionStepMarkerInjectorTest extends TestCase
- {
- public function test_inserts_chinese_step_labels_before_two_subquestions(): void
- {
- $raw = '(1)因为 $f(x)=x$,所以 $f\'(x)=1$。(2)故结论成立。';
- $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
- $this->assertStringStartsWith('步骤一:', $out);
- $this->assertStringContainsString('步骤二:', $out);
- }
- public function test_skips_when_step_markers_already_present(): void
- {
- $raw = '步骤1:(1)略 (2)略';
- $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
- $this->assertSame($raw, $out);
- }
- public function test_skips_single_subquestion(): void
- {
- $raw = '(1)唯一小问';
- $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
- $this->assertSame($raw, $out);
- }
- public function test_skips_choice_type(): void
- {
- $raw = '(1)A (2)B';
- $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'choice');
- $this->assertSame($raw, $out);
- }
- public function test_does_not_trigger_on_function_value_f1(): void
- {
- $raw = '故$f(1)=0$,且 $g(2)=1$。';
- $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
- $this->assertSame($raw, $out);
- }
- public function test_ordered_chain_skips_later_paren_one_so_no_step_three(): void
- {
- $raw = '(1)求$m$。(1)继续第一问。(2)第二问收尾。';
- $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
- $this->assertStringStartsWith('步骤一:', $out);
- $this->assertStringContainsString('步骤二:(2)', $out);
- $this->assertStringNotContainsString('步骤三:', $out);
- }
- public function test_subquestion_on_newline_after_first(): void
- {
- $raw = "(1)第一问。\n(2)第二问。";
- $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
- $this->assertStringStartsWith('步骤一:', $out);
- $this->assertStringContainsString('步骤二:(2)', $out);
- }
- public function test_fullwidth_paren_arabic_subquestions_get_step_labels(): void
- {
- $raw = '(1)当$a=2$时求得集合。(2)若选择①,则取值范围为……';
- $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
- $this->assertStringStartsWith('步骤一:', $out);
- $this->assertStringContainsString('步骤二:(2)', $out);
- }
- }
|