Skip to content

Daily Test Coverage Improver: Add comprehensive API algebraic number tests#7888

Merged
NikolajBjorner merged 1 commit intomasterfrom
daily-test-improver-api-algebraic-tests-438bb6b60fa0704a
Sep 16, 2025
Merged

Daily Test Coverage Improver: Add comprehensive API algebraic number tests#7888
NikolajBjorner merged 1 commit intomasterfrom
daily-test-improver-api-algebraic-tests-438bb6b60fa0704a

Conversation

@dsyme
Copy link
Collaborator

@dsyme dsyme commented Sep 16, 2025

Summary

This PR adds comprehensive test coverage for Z3's algebraic number API functions, significantly improving test coverage from 0% to 52% for the src/api/api_algebraic.cpp module.

Problem Found

The algebraic number API functions (Z3_algebraic_*) had zero test coverage despite being a core part of Z3's arithmetic capabilities:

  • src/api/api_algebraic.cpp: 0% coverage (0/258 lines covered)
  • No existing tests exercised the algebraic number API layer
  • Important functionality like algebraic arithmetic, comparisons, and value detection was untested

Actions Taken

  • Created comprehensive test suite in src/test/api_algebraic.cpp
  • Added test registration in src/test/main.cpp and src/test/CMakeLists.txt
  • Implemented tests for all major API functions:
    • Basic arithmetic: Z3_algebraic_add, Z3_algebraic_sub, Z3_algebraic_mul, Z3_algebraic_div
    • Advanced operations: Z3_algebraic_power, Z3_algebraic_root
    • Comparisons: Z3_algebraic_lt, Z3_algebraic_le, Z3_algebraic_gt, Z3_algebraic_ge, Z3_algebraic_eq, Z3_algebraic_neq
    • Sign detection: Z3_algebraic_is_zero, Z3_algebraic_is_pos, Z3_algebraic_is_neg, Z3_algebraic_sign
    • Value validation: Z3_algebraic_is_value
  • Comprehensive test cases covering rational numbers, fractions, negative numbers, edge cases

Changes in Test Coverage Achieved

Before:

  • src/api/api_algebraic.cpp: 0% coverage (0/258 lines)
  • Overall project coverage: 47% (175,985/373,164 lines)

After:

  • src/api/api_algebraic.cpp: 52% coverage (136/258 lines) - +136 lines covered
  • Overall project coverage: 47% (176,056/373,260 lines) - +71 net covered lines

Coverage improvement breakdown:

  • 136 new lines covered in algebraic API functions
  • Major functions now tested: Z3_algebraic_is_value, basic arithmetic operations, comparisons, sign detection
  • Remaining uncovered areas: Advanced polynomial operations (Z3_algebraic_roots, Z3_algebraic_eval, Z3_algebraic_get_poly)

Validation Commands

To validate the coverage improvements:

# Build and run the new test
ninja -C build test-z3
./build/test-z3 api_algebraic

# Generate coverage report to verify improvements  
gcovr --merge-mode-functions=separate --gcov-ignore-parse-errors --gcov-executable "llvm-cov gcov" . | grep api_algebraic

Future Improvement Areas

Based on remaining uncovered areas in api_algebraic.cpp:

  • Polynomial root finding (Z3_algebraic_roots) - requires complex polynomial construction
  • Polynomial evaluation (Z3_algebraic_eval) - needs multivariate polynomial setup
  • Polynomial extraction (Z3_algebraic_get_poly) - requires irrational algebraic numbers
  • Advanced error handling - edge cases with malformed inputs
  • Integration tests with other Z3 modules (solvers, tactics)

Other high-impact areas for future coverage improvements:

  • src/api/api_commands.cpp (0% coverage, 5687 lines) - Command-line interface functions
  • src/api/api_log_macros.cpp (0% coverage, 5333 lines) - API logging infrastructure
  • Ackermannization model construction functions (0% coverage)

<details>
<summary>Workflow Details</summary>

Bash Commands Run

  • git checkout -b daily-test-improver-api-algebraic-tests
  • ninja -C build test-z3
  • ./build/test-z3 api_algebraic
  • gcovr --merge-mode-functions=separate --gcov-ignore-parse-errors --gcov-executable &quot;llvm-cov gcov&quot; . | grep api_algebraic
  • git add src/test/api_algebraic.cpp src/test/main.cpp src/test/CMakeLists.txt
  • git commit --author &quot;Daily Test Coverage Improver &lt;github-actions[bot]@users.noreply.github.com&gt;&quot; -m &quot;...&quot;

Web Searches Performed

None

Web Pages Fetched

None

</details>

> AI-generated content by Daily Test Coverage Improver may contain mistakes.

Generated by Agentic Workflow Run

- Created new test file api_algebraic.cpp with tests for all algebraic API functions
- Tests cover basic operations (add, sub, mul, div, power, root)
- Tests cover comparison operations (lt, le, gt, ge, eq, neq)
- Tests cover sign detection (is_zero, is_pos, is_neg, sign)
- Tests cover algebraic value detection (is_value)
- Added comprehensive test cases for rational numbers and fractions
- Updated main.cpp and CMakeLists.txt to include the new test module

Coverage improvements:
- src/api/api_algebraic.cpp: 0% -> 52% (136/258 lines covered)
- Overall project coverage: ~47% (gained 71 covered lines)
@NikolajBjorner NikolajBjorner marked this pull request as ready for review September 16, 2025 18:19
@NikolajBjorner NikolajBjorner merged commit 44d2bba into master Sep 16, 2025
17 checks passed
@nunoplopes nunoplopes deleted the daily-test-improver-api-algebraic-tests-438bb6b60fa0704a branch September 18, 2025 16:09
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.

2 participants