2
0

RelatedParagraphCheckerTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. use App\Services\RelatedParagraph\RelatedParagraphChecker;
  3. /**
  4. * @param array<int, array{0: int, 1: int, 2?: int}> $paras 段落号 => [begin, end, sn]
  5. */
  6. function checkedBook(array $paras, string $layer = 'mula'): array
  7. {
  8. $rows = [];
  9. foreach ($paras as $para => $value) {
  10. $rows[$para] = ['book_name' => 'kn12', 'begin' => $value[0], 'end' => $value[1], 'book_id' => $value[2] ?? 1];
  11. }
  12. return (new RelatedParagraphChecker)->summarize([145 => $rows], [1 => $layer, 2 => $layer])['kn12']['books'][145];
  13. }
  14. it('counts a wrap only when the number repeats within the same sn', function () {
  15. expect(checkedBook([1 => [1, 1], 2 => [81, 81], 3 => [1, 1]])['wraps'])->toBe(['81→1@3'])
  16. ->and(checkedBook([1 => [162, 162], 2 => [335, 335], 3 => [1, 1]])['wraps'])->toBe([])
  17. ->and(checkedBook([1 => [1, 1], 2 => [33, 33], 3 => [1, 1, 2]])['wraps'])->toBe([]);
  18. });
  19. it('counts small drops as back references', function () {
  20. expect(checkedBook([1 => [1, 7], 2 => [7, 7], 3 => [5, 5]]))->toMatchArray(['wraps' => [], 'backs' => 1]);
  21. });
  22. it('lists commentary numbers missing from the mula side', function () {
  23. $rows = [
  24. 164 => [1 => ['book_name' => 'mn1', 'begin' => 1, 'end' => 2, 'book_id' => 1]],
  25. 130 => [1 => ['book_name' => 'mn1', 'begin' => 2, 'end' => 3, 'book_id' => 2]],
  26. ];
  27. $summary = (new RelatedParagraphChecker)->summarize($rows, [1 => 'mula', 2 => 'atthakatha']);
  28. expect($summary['mn1']['books'][130]['orphans'])->toBe([3])
  29. ->and($summary['mn1']['mula_max'])->toBe(2);
  30. });