Test Overview
This test simulates a risk analysis process for a software feature. It verifies that high-risk areas are identified and prioritized for testing to reduce potential failures.
This test simulates a risk analysis process for a software feature. It verifies that high-risk areas are identified and prioritized for testing to reduce potential failures.
def risk_analysis(features): # Assign risk scores based on impact and likelihood risk_scores = {} for feature, data in features.items(): impact = data.get('impact', 0) likelihood = data.get('likelihood', 0) risk_scores[feature] = impact * likelihood # Sort features by risk descending prioritized = sorted(risk_scores.items(), key=lambda x: x[1], reverse=True) return prioritized def test_risk_analysis(): features = { 'login': {'impact': 9, 'likelihood': 8}, 'search': {'impact': 6, 'likelihood': 5}, 'profile_update': {'impact': 7, 'likelihood': 3}, 'notifications': {'impact': 4, 'likelihood': 2} } result = risk_analysis(features) expected_first = ('login', 72) # 9*8 assert result[0] == expected_first, f"Expected highest risk feature to be {expected_first}, got {result[0]}" assert result[-1][0] == 'notifications', "Expected lowest risk feature to be 'notifications'"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test environment ready, risk_analysis function and test_risk_analysis defined | - | PASS |
| 2 | test_risk_analysis() is called | Features dictionary with impact and likelihood values passed to risk_analysis | - | PASS |
| 3 | risk_analysis calculates risk scores for each feature | Risk scores computed: login=72, search=30, profile_update=21, notifications=8 | - | PASS |
| 4 | risk_analysis sorts features by risk descending | Sorted list: [('login', 72), ('search', 30), ('profile_update', 21), ('notifications', 8)] | - | PASS |
| 5 | test_risk_analysis asserts highest risk feature is 'login' with score 72 | First item in result is ('login', 72) | assert result[0] == ('login', 72) | PASS |
| 6 | test_risk_analysis asserts lowest risk feature is 'notifications' | Last item in result is ('notifications', 8) | assert result[-1][0] == 'notifications' | PASS |
| 7 | Test ends successfully | All assertions passed, risk analysis prioritization verified | - | PASS |