Running Tests
Run all tests in the project:Test Coverage
The project includes comprehensive unit tests for core functionality:Stats Package Tests
Location:internal/stats/stats_test.go
Tests statistical calculation functions:
- Average - Mean calculation with empty, single, and multiple values
- Median - Median calculation for odd and even counts, including mutation safety
- Quartile - Percentile calculations (p50, p90, p0, p100)
- Jitter - Average absolute difference between consecutive samples
- Empty input handling
- Single value scenarios
- Edge cases (sorted/unsorted data)
- Non-mutation guarantees (functions don’t modify input arrays)
Cloudflare Package Tests
Location:internal/cloudflare/measure_test.go
Tests speed measurement calculations:
- MeasureSpeed - Converts bytes and duration to Mbps
- Various throughput scenarios (0.8 Mbps to 800 Mbps)
- Different time windows (500ms to 1000ms)
- Byte count variations (100kB to 100MB)
Reporter Package Tests
Location:internal/reporter/quality_test.go
Tests network quality evaluation logic:
- EvaluateQuality - Determines suitability for different use cases
- Streaming thresholds (download speed, packet loss)
- Gaming thresholds (latency, jitter, packet loss)
- Video chatting thresholds (download, upload, latency, jitter, packet loss)
- Excellent connections passing all criteria
- High latency affecting gaming
- High jitter affecting different use cases
- Slow speeds failing streaming or chatting
- Packet loss affecting all quality scores
Writing Tests
When contributing new functionality:-
Follow Go testing conventions
- Test files end with
_test.go - Test functions start with
Test - Use table-driven tests for multiple scenarios
- Test files end with
-
Use the existing test patterns:
-
Test edge cases
- Empty inputs
- Single element inputs
- Boundary values
- Error conditions
- Ensure tests don’t mutate inputs when functions should be pure
Contributing Tests
When submitting pull requests:- Add tests for new functionality
- Ensure existing tests pass:
- Consider adding benchmark tests for performance-critical code
- Document test expectations with clear test case names