Skip to content

Conversation

github-actions[bot]
Copy link
Contributor

Summary

This PR adds comprehensive unit tests for two previously untested modules in the FsMath library:

  • GenericMath module: 33 new tests covering mathematical functions (sqrt, exp, pow, log, abs, sin, cos, etc.)
  • VectorModule: 36 new tests covering vector utility functions (foldi, mapi, filter, argmax, argmin, split, chunk, windowed, etc.)

Problems Found

  1. GenericMath module had 0% test coverage - all generic mathematical wrapper functions were untested
  2. VectorModule had 0% test coverage - all vector utility functions were untested
  3. Overall project coverage was very low at 4.83% (99/2047 lines)

Actions Taken

  1. Created GenericMathTests.fs with 33 comprehensive tests covering:

    • Basic constants (zero, one, pi, e, tau, epsilon)
    • Type conversion functions
    • Mathematical operations (sqrt, exp, pow, log, abs)
    • Trigonometric functions (sin, cos)
    • Rounding functions (floor)
  2. Created VectorModuleTests.fs with 36 comprehensive tests covering:

    • Functional operations (foldi, mapi, filter, init)
    • Search operations (argmax, argmin, argmaxBy, argminBy, tryFindIndex, findIndex)
    • Transformation operations (slice, padRight, zip, split, chunk, windowed)
    • Utility functions (enumerateNonZero, splitVector, permuteBy, ofSeq, pow, sub)
  3. Updated FsMath.Tests.fsproj to include both new test files

  4. All 201 tests pass (132 original + 69 new tests)

Test Coverage Results

Metric Before After Change
Overall Line Coverage 4.83% 5.61% +0.78%
Lines Covered 99/2047 115/2047 +16 lines
Total Tests 132 201 +69 tests
VectorModule Coverage 0% 17.77% +17.77%

Note on GenericMath coverage: GenericMath functions are marked as inline in F#, which means they get compiled directly into calling code. Coverage tools may not accurately reflect their execution since they don't exist as separate callable functions in the compiled assembly. The tests do execute and validate these functions work correctly, but coverage metrics may show 0% due to how inline functions are instrumented.

Replicating the Test Coverage Measurements

To replicate these measurements:

# Clean previous coverage
rm -rf ./coverage

# Build the project
dotnet build

# Run tests with coverage
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj \
  --no-build \
  --collect:"XPlat Code Coverage" \
  --results-directory ./coverage \
  -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura

# Find and display coverage summary
COVERAGE_FILE=$(find ./coverage -name "coverage.cobertura.xml" | head -n 1)
LINE_RATE=$(grep -oP 'line-rate="\K[^"]*' "$COVERAGE_FILE" | head -n 1)
LINES_COVERED=$(grep -oP 'lines-covered="\K[^"]*' "$COVERAGE_FILE" | head -n 1)
LINES_VALID=$(grep -oP 'lines-valid="\K[^"]*' "$COVERAGE_FILE" | head -n 1)
echo "Line Coverage: $(awk "BEGIN {printf \"%.2f\", $LINE_RATE * 100}")% ($LINES_COVERED/$LINES_VALID lines)"

Possible Other Areas for Future Improvement

Based on the coverage report, the following areas have 0% or very low coverage and could benefit from additional tests:

  1. SpanPrimitives.fs (0% coverage) - SIMD-accelerated span operations
  2. SpanMath.fs (0% coverage) - Mathematical operations on spans
  3. SIMDUtils.fs (0% coverage) - SIMD utility functions
  4. VectorOps.fs (0% coverage) - Vector operations and operators
  5. Algebra/LinearAlgebra.fs (0% coverage) - Linear algebra operations (QR decomposition, etc.)
  6. Algebra/SVD.fs (0% coverage) - Singular Value Decomposition
  7. Algebra/EVD.fs (0% coverage) - Eigenvalue Decomposition
  8. MatrixModule.fs (0% coverage) - Matrix utility functions
  9. Permutation.fs (0% coverage) - Permutation operations

The next logical step would be to add tests for the more fundamental operations in VectorOps.fs since many other parts of the codebase likely depend on these operations.


Execution Details (bash commands, web searches, web pages fetched)

Bash Commands Run:

  • git checkout -b test-coverage/generic-math-and-vector-module-20251010
  • dotnet build tests/FsMath.Tests/FsMath.Tests.fsproj
  • dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build
  • dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build --collect:"XPlat Code Coverage" --results-directory ./coverage-new
  • git add tests/FsMath.Tests/GenericMathTests.fs tests/FsMath.Tests/VectorModuleTests.fs tests/FsMath.Tests/FsMath.Tests.fsproj
  • git commit -m "Add comprehensive tests for GenericMath and VectorModule"
  • Coverage extraction commands to calculate before/after metrics

Web Searches:

None performed

Web Pages Fetched:

None fetched

AI generated by Daily Test Coverage Improver

This commit adds 69 new unit tests to improve test coverage:
- 33 tests for GenericMath module (mathematical functions)
- 36 tests for VectorModule (vector utility functions)

Coverage improved from 4.83% to 5.61% (99 to 115 lines covered).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@dsyme dsyme closed this Oct 10, 2025
@dsyme dsyme reopened this Oct 10, 2025
@dsyme dsyme marked this pull request as ready for review October 12, 2025 12:40
@dsyme dsyme merged commit 26c3cfe into main Oct 12, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant