AnswerSolutionStepMarkerInjectorTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Support\AnswerSolutionStepMarkerInjector;
  4. use PHPUnit\Framework\TestCase;
  5. class AnswerSolutionStepMarkerInjectorTest extends TestCase
  6. {
  7. public function test_inserts_chinese_step_labels_before_two_subquestions(): void
  8. {
  9. $raw = '(1)因为 $f(x)=x$,所以 $f\'(x)=1$。(2)故结论成立。';
  10. $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
  11. $this->assertStringStartsWith('步骤一:', $out);
  12. $this->assertStringContainsString('步骤二:', $out);
  13. }
  14. public function test_skips_when_step_markers_already_present(): void
  15. {
  16. $raw = '步骤1:(1)略 (2)略';
  17. $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
  18. $this->assertSame($raw, $out);
  19. }
  20. public function test_skips_single_subquestion(): void
  21. {
  22. $raw = '(1)唯一小问';
  23. $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
  24. $this->assertSame($raw, $out);
  25. }
  26. public function test_skips_choice_type(): void
  27. {
  28. $raw = '(1)A (2)B';
  29. $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'choice');
  30. $this->assertSame($raw, $out);
  31. }
  32. public function test_does_not_trigger_on_function_value_f1(): void
  33. {
  34. $raw = '故$f(1)=0$,且 $g(2)=1$。';
  35. $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
  36. $this->assertSame($raw, $out);
  37. }
  38. public function test_ordered_chain_skips_later_paren_one_so_no_step_three(): void
  39. {
  40. $raw = '(1)求$m$。(1)继续第一问。(2)第二问收尾。';
  41. $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
  42. $this->assertStringStartsWith('步骤一:', $out);
  43. $this->assertStringContainsString('步骤二:(2)', $out);
  44. $this->assertStringNotContainsString('步骤三:', $out);
  45. }
  46. public function test_subquestion_on_newline_after_first(): void
  47. {
  48. $raw = "(1)第一问。\n(2)第二问。";
  49. $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
  50. $this->assertStringStartsWith('步骤一:', $out);
  51. $this->assertStringContainsString('步骤二:(2)', $out);
  52. }
  53. public function test_fullwidth_paren_arabic_subquestions_get_step_labels(): void
  54. {
  55. $raw = '(1)当$a=2$时求得集合。(2)若选择①,则取值范围为……';
  56. $out = AnswerSolutionStepMarkerInjector::enrichIfNeeded($raw, 'answer');
  57. $this->assertStringStartsWith('步骤一:', $out);
  58. $this->assertStringContainsString('步骤二:(2)', $out);
  59. }
  60. }