94400d50d4
作为子目录纳入系统,与核心测试管道协同 Co-Authored-By: Claude <noreply@anthropic.com>
40 lines
1.4 KiB
Markdown
40 lines
1.4 KiB
Markdown
# 19-matching-MN-to-N
|
|
|
|
## 电信业务场景
|
|
|
|
套餐适用M:N→N条。多个合同关联多个套餐的组合匹配,输出按套餐件数(N件)的适用明细。
|
|
|
|
**M:N matching — output N records (one per detail match).**
|
|
|
|
Tests the scenario where both input files may contain duplicate keys.
|
|
The program performs a grouped match: for each key where at least one
|
|
master record exists, the program outputs every detail record for that
|
|
key, then skips all master records for that key.
|
|
|
|
## Test data
|
|
|
|
| File | Records | Keys |
|
|
|-------------|---------|-------------------------------|
|
|
| master.dat | 4 | KEY00001 (x2), KEY00002 (x2) |
|
|
| detail.dat | 5 | KEY00001 (x2), KEY00003 (x3) |
|
|
|
|
- **Matched key:** KEY00001 -> 2 output records (2 detail records)
|
|
- **Unmatched master key:** KEY00002 (skipped)
|
|
- **Unmatched detail key:** KEY00003 (skipped)
|
|
|
|
## Algorithm
|
|
|
|
1. Read both files synchronously (both assumed sorted by key).
|
|
2. When keys match: output all detail records in the group, then skip all
|
|
master records in the group.
|
|
3. When master key < detail key: skip all master records with that key
|
|
(no matching detail).
|
|
4. When detail key < master key: skip all detail records with that key
|
|
(no matching master).
|
|
|
|
## Expected output
|
|
|
|
- **output.dat:** 2 records x 45 bytes = 90 bytes
|
|
- Program displays: `19-matching-MN-to-N: PASS`
|
|
- Script displays: `19-matching-MN-to-N: ALL TESTS PASSED`
|