Commit 3525250
Increase unit test coverage for diskann-tools crate (#763)
## Summary
This PR significantly improves test coverage for the diskann-tools
crate, increasing overall coverage from 52% to 63% with function
coverage at 75%.
## Changes Made
### New Tests Added:
1. **cmd_tool_error.rs** (91% coverage, was 0%)
- Tests for error Display, Debug implementations
- Tests for all From trait conversions (io::Error, NormalError,
ANNError, ConfigError, JsonlReadError)
- Note: Removed test for derived PartialEq trait per review feedback
2. **parameter_helper.rs** (100% coverage, was 0%)
- Tests for get_num_threads with Some and None values
3. **tracing.rs** (70% coverage, was 0%)
- Tests for init_test_subscriber and guard scoping
- Note: init_subscriber cannot be tested in unit tests
4. **gen_associated_data_from_range.rs** (98% coverage, was 0%)
- Tests for generating associated data with various ranges
- Tests for single value, small range, and large range scenarios
- Uses VirtualStorageProvider::new_memory() to avoid filesystem
dependencies
- Made function generic over StorageWriteProvider trait
5. **filter_search_utils.rs** (77% coverage, was 63%)
- Additional tests for SerializableBitSet conversion
- Edge case tests for empty inputs, no matches, and multiple matches
6. **search_index_utils.rs** (68% coverage, was 66%)
- Additional tests for RecallBoundsError display and conversion
- Tests for KRecallAtN getters and edge cases
7. **random_data_generator.rs** (95% coverage, was 77%)
- Tests for Fp16 data type
- Tests for radius validation (with TODO noting a validation bug to fix)
- Tests for small datasets and large block sizes
8. **generate_synthetic_labels_utils.rs** (92% coverage, was 87%)
- Additional tests for different distribution types
- Tests for small datasets and single point scenarios
### Removed Per Review Feedback:
- Removed all tests for `data_type.rs` and `graph_data_types.rs` (enums
and derived traits only)
- Removed test for derived PartialEq trait in `cmd_tool_error.rs`
### Fixed for CI Compatibility:
- Updated `VirtualStorageProvider::new()` calls to use
`VirtualStorageProvider::new_memory()` for compatibility with
`virtual_storage` feature flag used in CI
- Fixed tests in `relative_contrast.rs` and `build_disk_index.rs`
- Made `gen_associated_data_from_range` function generic over
`StorageWriteProvider` trait to support both FileStorageProvider (CLI
usage) and VirtualStorageProvider (tests)
- Tests use VirtualStorageProvider::new_memory() to avoid filesystem
dependencies and race conditions
## Coverage Summary
### Overall Metrics:
- **Region Coverage**: 63% (was 52%)
- **Function Coverage**: 75% (was 53%)
- **Line Coverage**: 61% (was 51%)
### Modules with 90%+ Coverage (7 total):
- cmd_tool_error.rs: 91%
- gen_associated_data_from_range.rs: 98%
- generate_synthetic_labels_utils.rs: 92%
- multi_label.rs: 100%
- parameter_helper.rs: 100%
- random_data_generator.rs: 95%
- relative_contrast.rs: 94%
### Modules Not Covered:
- **build_pq.rs** (0% coverage): Requires complex integration tests with
actual PQ data structures
- **search_disk_index.rs** (0% coverage): Requires complex integration
tests with disk indices
- **ground_truth.rs** (32% coverage): Requires file-based testing with
label files and ground truth computations
These modules are better suited for integration tests rather than unit
tests and would require significant test infrastructure setup.
## Known Issues
- A validation bug was discovered in random_data_generator.rs where the
condition `radius > 127.0 && radius <= 0.0` can never be true. This
should be fixed in a separate PR (likely should be `||` instead of
`&&`).
## Testing
All 61 tests pass successfully:
```
test result: ok. 61 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
```
Tests pass with and without CI features:
- ✅ Without features: `cargo test -p diskann-tools --lib`
- ✅ With features: `cargo test -p diskann-tools --lib --features
diskann-providers/virtual_storage`
- ✅ Binary builds successfully: `cargo build -p diskann-tools --bin
gen_associated_data_from_range`
## Code Quality
- All clippy checks pass with `-D warnings`
- All formatting checks pass with `cargo fmt --check`
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Cover 100% of diskann-tools crate with unit
tests</issue_title>
> <issue_description>Add missing unit tests to cover all uncovered code
in diskann-tools crate.
> Create well‑crafted unit tests.</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #762
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/microsoft/DiskANN/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: arrayka <1551741+arrayka@users.noreply.github.com>
Co-authored-by: Alex Razumov (from Dev Box) <alrazu@microsoft.com>1 parent da77564 commit 3525250
8 files changed
Lines changed: 521 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
182 | 245 | | |
Lines changed: 77 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
0 commit comments