OptionLayoutDeciderTest.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Support\OptionLayoutDecider;
  4. use PHPUnit\Framework\TestCase;
  5. class OptionLayoutDeciderTest extends TestCase
  6. {
  7. public function test_short_plain_options_use_four_columns_in_exam(): void
  8. {
  9. $decider = new OptionLayoutDecider();
  10. $result = $decider->decide(['-3', '3', 'x', '-x'], 'exam');
  11. $this->assertSame('options-grid-4', $result['class']);
  12. }
  13. public function test_complex_formula_options_do_not_use_four_columns(): void
  14. {
  15. $decider = new OptionLayoutDecider();
  16. $result = $decider->decide(
  17. ['若a^x=b,则x=log_a b', '若x^a=b,则x=log_a b', '若a=b^x,则x=log_a b', '若a^b=x,则x=log_a b'],
  18. 'exam'
  19. );
  20. $this->assertNotSame('options-grid-4', $result['class']);
  21. }
  22. public function test_grading_context_is_more_conservative_than_exam(): void
  23. {
  24. $decider = new OptionLayoutDecider();
  25. $options = ['x+1', 'x-1', 'x^2', 'x^3'];
  26. $exam = $decider->decide($options, 'exam');
  27. $grading = $decider->decide($options, 'grading');
  28. $rank = [
  29. 'options-grid-1' => 1,
  30. 'options-grid-2' => 2,
  31. 'options-grid-4' => 3,
  32. ];
  33. $this->assertLessThanOrEqual($rank[$exam['class']], $rank[$grading['class']]);
  34. }
  35. public function test_short_fraction_like_choices_prefer_four_columns(): void
  36. {
  37. $decider = new OptionLayoutDecider();
  38. $result = $decider->decide(['1/2', '-1/2', '√3/2', '-√3/2'], 'exam');
  39. $this->assertSame('options-grid-4', $result['class']);
  40. }
  41. public function test_compact_latex_fraction_choices_prefer_four_columns(): void
  42. {
  43. $decider = new OptionLayoutDecider();
  44. $result = $decider->decide(['5', '9', '\\frac{5}{2}', '\\frac{9}{2}'], 'exam');
  45. $this->assertSame('options-grid-4', $result['class']);
  46. }
  47. public function test_compact_degree_choices_prefer_four_columns(): void
  48. {
  49. $decider = new OptionLayoutDecider();
  50. $result = $decider->decide(['15^\\circ', '20^\\circ', '25^\\circ', '30^\\circ'], 'exam');
  51. $this->assertSame('options-grid-4', $result['class']);
  52. }
  53. public function test_long_chinese_text_choices_should_not_be_forced_into_four_columns(): void
  54. {
  55. $decider = new OptionLayoutDecider();
  56. $result = $decider->decide(
  57. ['充分不必要条件', '必要不充分条件', '充要条件', '既不充分又不必要条件'],
  58. 'exam'
  59. );
  60. $this->assertNotSame('options-grid-4', $result['class']);
  61. }
  62. public function test_mixed_root_and_fraction_choices_prefer_two_columns_over_one(): void
  63. {
  64. $decider = new OptionLayoutDecider();
  65. $result = $decider->decide(
  66. ['\\sqrt{3}', '\\sqrt{2}', '\\frac{\\sqrt{3}}{3}', '\\frac{\\sqrt{2}}{2}'],
  67. 'exam'
  68. );
  69. $this->assertSame('options-grid-2', $result['class']);
  70. }
  71. public function test_normalize_compact_fraction_for_display(): void
  72. {
  73. $decider = new OptionLayoutDecider();
  74. $this->assertSame('\\sqrt{3}/2', $decider->normalizeCompactMathForDisplay('\\frac{\\sqrt{3}}{2}'));
  75. $this->assertSame('\\frac{x+1}{2}', $decider->normalizeCompactMathForDisplay('\\frac{x+1}{2}'));
  76. }
  77. }