Work on this exercise locally
This web app is a reference guide — you can read instructions, browse starter code, and view tests here. To actually complete the exercise, you need to work in your local development environment.
git clone https://github.com/weihaoqu/program-analysis-bootcamp-studentfailwith "TODO" with your implementation.dune runtest modules/module6-tools-integration/exercises/analysis-findingAnalysis Finding
2. Exercise 1: Analysis Finding (20 tests)
Goal: Define utility functions on the unified finding type -- conversion, comparison, filtering, deduplication, formatting, and counting.
Time: ~20 minutes
File to edit: exercises/analysis-finding/starter/analysis_finding.ml
Dependencies: None (self-contained)
Types provided (not a TODO)
The severity, category, and finding types are already defined at the top
of the file. You implement the functions that operate on them.
What to implement (in order)
| # | Function | Hint |
|---|---|---|
| 1 | severity_to_string s | Pattern match: Critical -> "Critical", etc. |
| 2 | category_to_string c | Pattern match: Security -> "Security", CodeQuality -> "CodeQuality", etc. |
| 3 | severity_to_int s | Critical=4, High=3, Medium=2, Low=1, Info=0 |
| 4 | compare_by_severity a b | Higher severity first: compare severity_to_int b - severity_to_int a (negative means a is more severe) |
| 5 | compare_by_location a b | String.compare a.location b.location |
| 6 | filter_by_severity threshold findings | Keep findings where severity_to_int f.severity >= severity_to_int threshold |
| 7 | filter_by_category cat findings | Keep findings where f.category = cat |
| 8 | deduplicate findings | Remove duplicates with same message AND same location; preserve first occurrence |
| 9 | format_finding f | Format: "[Severity] Category - message in location". If suggestion is Some s, append "\n Suggestion: s" |
| 10 | format_findings_list findings | Return "No findings." for empty list; otherwise one formatted finding per line |
| 11 | count_by_severity findings | Return (severity * int) list ordered Critical..Info, excluding zero-count entries |
| 12 | count_by_category findings | Return (category * int) list ordered Security..Performance, excluding zero-count entries |
Run tests
dune runtest modules/module6-tools-integration/exercises/analysis-finding/
Starter output (all 20 tests error):
EEEEEEEEEEEEEEEEEEEE
Hints:
- For
deduplicate, fold through the list keeping a set of(message, location)pairs you have already seen.List.revat the end to preserve order. - For
count_by_severity, iterate over[Critical; High; Medium; Low; Info], count how many findings match each, and drop entries with count 0.
Starter Files
Test Files
Work on this exercise locally
This web app is a reference guide — you can read instructions, browse starter code, and view tests here. To actually complete the exercise, you need to work in your local development environment.
git clone https://github.com/weihaoqu/program-analysis-bootcamp-studentfailwith "TODO" with your implementation.dune runtest modules/module6-tools-integration/exercises/analysis-findingAnalysis Finding
2. Exercise 1: Analysis Finding (20 tests)
Goal: Define utility functions on the unified finding type -- conversion, comparison, filtering, deduplication, formatting, and counting.
Time: ~20 minutes
File to edit: exercises/analysis-finding/starter/analysis_finding.ml
Dependencies: None (self-contained)
Types provided (not a TODO)
The severity, category, and finding types are already defined at the top
of the file. You implement the functions that operate on them.
What to implement (in order)
| # | Function | Hint |
|---|---|---|
| 1 | severity_to_string s | Pattern match: Critical -> "Critical", etc. |
| 2 | category_to_string c | Pattern match: Security -> "Security", CodeQuality -> "CodeQuality", etc. |
| 3 | severity_to_int s | Critical=4, High=3, Medium=2, Low=1, Info=0 |
| 4 | compare_by_severity a b | Higher severity first: compare severity_to_int b - severity_to_int a (negative means a is more severe) |
| 5 | compare_by_location a b | String.compare a.location b.location |
| 6 | filter_by_severity threshold findings | Keep findings where severity_to_int f.severity >= severity_to_int threshold |
| 7 | filter_by_category cat findings | Keep findings where f.category = cat |
| 8 | deduplicate findings | Remove duplicates with same message AND same location; preserve first occurrence |
| 9 | format_finding f | Format: "[Severity] Category - message in location". If suggestion is Some s, append "\n Suggestion: s" |
| 10 | format_findings_list findings | Return "No findings." for empty list; otherwise one formatted finding per line |
| 11 | count_by_severity findings | Return (severity * int) list ordered Critical..Info, excluding zero-count entries |
| 12 | count_by_category findings | Return (category * int) list ordered Security..Performance, excluding zero-count entries |
Run tests
dune runtest modules/module6-tools-integration/exercises/analysis-finding/
Starter output (all 20 tests error):
EEEEEEEEEEEEEEEEEEEE
Hints:
- For
deduplicate, fold through the list keeping a set of(message, location)pairs you have already seen.List.revat the end to preserve order. - For
count_by_severity, iterate over[Critical; High; Medium; Low; Info], count how many findings match each, and drop entries with count 0.