协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
interval-difference-analyzer【开发与工程】Analyze differences in program intervals between two versions of a program (old and new) to identify added, removed, or modified intervals. Use when comparing program versions, analyzing variable ranges, detecting behavioral changes in numeric computations, validating refactorings, or assessing migration impacts. Supports optional test suite integrat…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Analyze differences in program intervals (variable value ranges) between two versions of a program to detect behavioral changes, identify potential bugs, and guide testing efforts.
Prepare both program versions for analysis:
OLD_VERSION=/path/to/old/program
NEW_VERSION=/path/to/new/program
TEST_SUITE=/path/to/tests # Optional
Extract interval information from both versions:
python scripts/interval_analyzer.py \
--program $OLD_VERSION \
--output old_intervals.json
python scripts/interval_analyzer.py \
--program $NEW_VERSION \
--output new_intervals.json
Compare intervals and identify differences:
python scripts/compare_intervals.py \
--old old_intervals.json \
--new new_intervals.json \
--output interval_diff_report.json
Examine the generated report for:
Program intervals represent the possible ranges of values that variables can take during program execution.
Example:
def calculate_discount(price, discount_rate):
# Intervals:
# price: [0, 10000]
# discount_rate: [0.0, 1.0]
# discount: [0, 10000]
discount = price * discount_rate
return discount
Why intervals matter:
Analyze code to infer possible value ranges without execution.
Execute program with test inputs and observe actual ranges.
Use abstract domains to compute sound interval approximations.
Pattern: New variables or wider ranges in new version
Implications:
Pattern: Deleted variables or narrower ranges in new version
Implications:
Pattern: Changed bounds for existing variables
Example:
# Old version: age: [0, 120]
# New version: age: [0, 150] # Widened!
Implications:
Check if new intervals exceed type bounds.
Example:
# Old: result: [0, 1000000] ✓ Safe (int32)
# New: result: [0, 10000000000] ✗ Overflow risk!
Check if new intervals lose precision.
Example:
# Old: result: [0.0, 100.0] (float)
# New: result: [0, 100] (int) - precision loss!
Check if interval boundaries change critically.
Example:
# Old: index: [0, 99]
# New: index: [-1, 99] # Negative index possible!
Critical: Test immediately
High: Test soon
Medium: Test when convenient
Low: Optional testing
Generate test cases targeting interval boundaries:
# Interval: x: [0, 100]
test_cases = [0, 1, 50, 99, 100]
# For modified interval: [0, 100] → [0, 150]
additional_tests = [101, 125, 149, 150]
The analyzer generates a comprehensive JSON report:
{
"summary": {
"total_intervals_old": 45,
"total_intervals_new": 48,
"added_intervals": 5,
"removed_intervals": 2,
"modified_intervals": 8
},
"differences": [
{
"type": "modified",
"variable": "age",
"old_interval": "[0, 120]",
"new_interval": "[0, 150]",
"severity": "high",
"implications": ["Accepts wider range"],
"testing_priority": "high",
"suggested_tests": [121, 135, 149, 150]
}
],
"recommendations": [
"Test modified intervals with boundary values",
"Verify no overflow in calculations"
]
}
Run existing tests and verify intervals:
python scripts/validate_intervals.py \
--program $NEW_VERSION \
--intervals new_intervals.json \
--test-suite $TEST_SUITE
Automatically generate tests for interval boundaries:
python scripts/generate_interval_tests.py \
--intervals interval_diff_report.json \
--output generated_tests.py