Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Bounds regression tests #4001

Merged
merged 7 commits into from
Dec 19, 2024

Conversation

paulgessinger
Copy link
Member

@paulgessinger paulgessinger commented Dec 19, 2024

This PR adds regression tests based on a grid of sample points. The bounds on a surface are checked, and the result is compared to a reference matrix that is parsed from a string. In case of a mismatch a diff like this is printed:

image

We'll probably extend this to more shapes and tolerance scenarios. This is a proof of concept only.

--- END COMMIT MESSAGE ---

Any further description goes here, @-mentions are ok here!

  • Use a conventional commits prefix: quick summary
    • We mostly use feat, fix, refactor, docs, chore and build types.
  • A milestone will be assigned by one of the maintainers

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for tolerance values in the BoundaryTolerance class.
    • Introduced a new enumeration, ToleranceMode, to define tolerance behaviors.
    • Updated method to retrieve current tolerance mode.
  • Bug Fixes

    • Improved robustness of tolerance handling by enforcing stricter conditions.
  • Tests

    • Added a suite of unit tests for various surface bounds, ensuring expected functionality.
    • Introduced functions for bounding box calculations and test matrix management.
  • Chores

    • Updated CMakeLists.txt to include the new BoundsRegression test suite.

Copy link

coderabbitai bot commented Dec 19, 2024

Walkthrough

Hmm, changes to boundary tolerance and surface bounds testing, we have. In the Core library, modifications to BoundaryTolerance class, introduced. A new enumeration ToleranceMode, added it has. Error handling enhanced, constructor logic strengthened. Unit tests for surface bounds, created in regression test suite. Comprehensive verification of surface boundary behaviors, the goal is.

Changes

File Change Summary
Core/include/Acts/Surfaces/BoundaryTolerance.hpp - Added ToleranceMode enum
- Replaced hasTolerance() with toleranceMode()
- Enhanced constructor error handling
Tests/UnitTests/Core/Surfaces/BoundsRegressionTests.cpp - Added new regression test suite
- Implemented TestMatrix struct
- Created utility functions for bounds testing
Tests/UnitTests/Core/Surfaces/CMakeLists.txt - Added new unit test entry for BoundsRegression

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • andiwand

Poem

Boundaries shift like sand, they do
Tolerance measured, both old and new
Code dances with precision bright
Surface bounds take quantum flight 🚀
Wisdom in each line we view


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added this to the next milestone Dec 19, 2024
@github-actions github-actions bot added the Component - Core Affects the Core module label Dec 19, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
Core/src/Surfaces/BoundaryTolerance.cpp (1)

Line range hint 173-202: Chi2 and Euclidean logic robust, watch negative values you must.
Critical correctness needed, yes.

🧹 Nitpick comments (13)
Tests/UnitTests/Core/Surfaces/CMakeLists.txt (1)

Line range hint 1-31: Organize tests by category, we should.

Group related tests together, a Jedi's path to clarity is. Suggest organizing tests into logical categories, I do:

# Boundary and Bounds Tests
add_unittest(BoundaryTolerance BoundaryToleranceTests.cpp)
add_unittest(BoundsRegression BoundsRegressionTests.cpp)
add_unittest(AnnulusBounds AnnulusBoundsTests.cpp)
# ... other bounds tests

# Surface Tests
add_unittest(ConeSurface ConeSurfaceTests.cpp)
add_unittest(CylinderSurface CylinderSurfaceTests.cpp)
# ... other surface tests

# Helper Tests
add_unittest(IntersectionHelper2D IntersectionHelper2DTests.cpp)
add_unittest(VerticesHelper VerticesHelperTests.cpp)
add_unittest(AlignmentHelper AlignmentHelperTests.cpp)
Core/include/Acts/Surfaces/detail/BoundaryCheckHelper.hpp (1)

129-134: “Check sign” the comment says, a path unknown it is.
Assistance provide, I can, yes.

Core/src/Surfaces/BoundaryTolerance.cpp (1)

115-115: Assert for unsupported types, a cautionary measure it is.
Defensive coding, value it brings.

Core/src/Surfaces/AnnulusBounds.cpp (2)

242-253: Closest point computation, thorough indeed.
Large overhead it might have, carefully watch.


436-436: Logic error thrown, next steps or expansions needed?
Assistance for completion, offer I shall.

Tests/UnitTests/Core/Surfaces/BoundsRegressionTests.cpp (3)

73-174: Matrix-based approach, interesting indeed.
Performance in larger grids, watch carefully you must.


358-371: Reference matrix usage, consistent it is.
Potential for data storage improvement, yes.


373-478: Comparisons to textual reference, thorough indeed.
Future expansions for shapes, wise would be.

Core/include/Acts/Surfaces/BoundaryTolerance.hpp (1)

70-74: More specific error messages, suggest I do.

Hmm, more descriptive the error messages should be, including the actual values that caused the error.

Apply this change, you should:

-            "AbsoluteBound: Tolerance must be non-negative");
+            "AbsoluteBound: Tolerances must be non-negative, but got tolerance0=" +
+            std::to_string(tolerance0) + ", tolerance1=" + std::to_string(tolerance1));
-            "AbsoluteCartesian: Tolerance must be non-negative");
+            "AbsoluteCartesian: Tolerances must be non-negative, but got tolerance0=" +
+            std::to_string(tolerance0) + ", tolerance1=" + std::to_string(tolerance1));

Also applies to: 85-89

Tests/UnitTests/Core/Surfaces/AnnulusBoundsTests.cpp (1)

144-243: Documentation for test cases, improve we should.

Good the test coverage is, but clearer documentation we need. Each test section's purpose and expectations, document we must.

Add documentation blocks like this, you should:

+  // Test positive absolute euclidean tolerance
   {
     auto tolerance = BoundaryTolerance::AbsoluteEuclidean(1);
     // ... existing tests ...
   }

+  // Test negative absolute euclidean tolerance for boundary shrinking
   {
     auto tolerance = BoundaryTolerance::AbsoluteEuclidean(-1);
     // ... existing tests ...
   }

+  // Test positive chi-squared tolerance with identity weight matrix
   {
     auto tolerance =
         BoundaryTolerance::Chi2Bound(SquareMatrix2::Identity(), 0.1);
     // ... existing tests ...
   }
Tests/UnitTests/Core/Surfaces/BoundaryToleranceTests.cpp (3)

30-108: Refactor test helpers, we should.

Repeated patterns in tests, I see. Extract common test logic into helper functions, we must.

Create helper functions like this:

template <typename T>
void checkToleranceMode(const T& tolerance, BoundaryTolerance::ToleranceMode expected) {
  BOOST_CHECK(BoundaryTolerance{tolerance}.toleranceMode() == expected);
}

template <typename T>
void checkNegativeToleranceThrows(std::function<T(double,double)> constructor) {
  BOOST_CHECK_THROW(constructor(-1.0, 2.0), std::invalid_argument);
  BOOST_CHECK_THROW(constructor(1.0, -2.0), std::invalid_argument);
}

289-335: Name test points better, we must.

Clear the test structure is, but meaning of test points, obscure it remains.

Add descriptive names for test points:

-    BOOST_CHECK(!check(tolerance, {2.8, 2}));
+    Vector2 nearUpperBoundary{2.8, 2};
+    BOOST_CHECK(!check(tolerance, nearUpperBoundary));

-    BOOST_CHECK(!check(tolerance, {3.1, 2}));
+    Vector2 outsideUpperBoundary{3.1, 2};
+    BOOST_CHECK(!check(tolerance, outsideUpperBoundary));

337-385: Visual documentation, add we should.

Clear the test cases are, but visual representation would help understanding, it would.

Add ASCII art to document the test points:

+  // Test points for trapezoid:
+  //
+  //      (1,3)-----(3,3)
+  //        /         \
+  //       /           \
+  //      /             \
+  // (1.5,1)----------(2.5,1)
+  //
   Vector2 vertices[] = {{1.5, 1}, {2.5, 1}, {3, 3}, {1, 3}};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e430f8 and eeb3782.

📒 Files selected for processing (8)
  • Core/include/Acts/Surfaces/BoundaryTolerance.hpp (4 hunks)
  • Core/include/Acts/Surfaces/detail/BoundaryCheckHelper.hpp (4 hunks)
  • Core/src/Surfaces/AnnulusBounds.cpp (2 hunks)
  • Core/src/Surfaces/BoundaryTolerance.cpp (3 hunks)
  • Tests/UnitTests/Core/Surfaces/AnnulusBoundsTests.cpp (1 hunks)
  • Tests/UnitTests/Core/Surfaces/BoundaryToleranceTests.cpp (2 hunks)
  • Tests/UnitTests/Core/Surfaces/BoundsRegressionTests.cpp (1 hunks)
  • Tests/UnitTests/Core/Surfaces/CMakeLists.txt (1 hunks)
🧰 Additional context used
🪛 cppcheck (2.10-2)
Tests/UnitTests/Core/Surfaces/BoundaryToleranceTests.cpp

[error] 28-28: There is an unknown macro here somewhere. Configuration is required. If BOOST_AUTO_TEST_SUITE is a macro then please configure it.

(unknownMacro)

Tests/UnitTests/Core/Surfaces/BoundsRegressionTests.cpp

[error] 175-175: There is an unknown macro here somewhere. Configuration is required. If BOOST_AUTO_TEST_SUITE is a macro then please configure it.

(unknownMacro)

🔇 Additional comments (16)
Tests/UnitTests/Core/Surfaces/CMakeLists.txt (1)

31-31: Hmmmm, good this addition is, young padawan!

Wise decision to add regression tests for bounds, I sense. Strong with the Force, this change is.

Core/include/Acts/Surfaces/detail/BoundaryCheckHelper.hpp (3)

32-47: Stable the new tolerance usage is.
Implementation consistent, yes.


73-77: Extend mode logic, correct it looks.
Negative tolerances, test carefully you must.


92-112: Clarity improved, handle boundary checks gracefully you do.
Minimal overhead, the code suggests.

Core/src/Surfaces/BoundaryTolerance.cpp (3)

63-70: Shift from boolean to modes, wise you are.
Better clarity it grants.


75-79: Zero tolerance fallback to None, correct that is.
Neat boundary condition logic, yes.


84-111: Multiple tolerance variants well-handled.
Coverage for all types, thorough it seems.

Core/src/Surfaces/AnnulusBounds.cpp (3)

Line range hint 210-236: Integrate BoundaryTolerance well, you do.
Seamless the approach is, hmm.


385-403: Chi2Bound checks in place, well-defined.
Additional tests for edge scenarios, wise would be.


404-433: Absolute Euclidean checks, correct they appear.
Fitting seamlessly with negative tolerance logic, yes.

Tests/UnitTests/Core/Surfaces/BoundsRegressionTests.cpp (4)

1-36: New test harness, good variety it introduces.
Methodical coverage of shapes, nice it is.


37-66: Bounding box generation, margin approach wise.
Corner cases well-handled, see I do.


177-273: Rectangle and trapezoid references, verified they are.
Confidence in comparisons, yes.


480-481: Test suite concludes, heed not the macro confusion.
Macros well-known in Boost they are.

Core/include/Acts/Surfaces/BoundaryTolerance.hpp (2)

111-115: Strong with the Force, this enum is.

Clear and concise, the ToleranceMode enum class is. Good practices it follows, using enum class for type safety.


151-151: Breaking change, this is. Verify all callers, we must.

Changed from boolean to enum return type, this method has. Impact on existing code, we must check.

✅ Verification successful

The previous search for hasTolerance() yielded no results, suggesting the change might have already been propagated. Let me search for the new method and class usage to verify the current state of integration.


Safe, this change is. No impact on existing code, I sense.

Through the Force, I have observed that hasTolerance() method no longer exists in the codebase, and all usages already utilize the new toleranceMode() API. The change appears to be part of a completed transition, hmm.

The search results show:

  • No remaining calls to hasTolerance()
  • Extensive test coverage for the new toleranceMode() API
  • All code using the new enum-based approach consistently

Complete, this transition already is. No further changes needed, I sense.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all calls to hasTolerance() that need updating
rg -l "hasTolerance\(\)" | while read -r file; do
  if [[ "$file" =~ .*\.(cpp|hpp|h)$ ]]; then
    echo "=== $file ==="
    rg -A 2 "hasTolerance\(\)" "$file"
  fi
done

Length of output: 41


Script:

#!/bin/bash
# Search for all usages of toleranceMode() in the codebase
rg -A 2 "toleranceMode\(\)" 

# Also search for BoundaryTolerance class usage
rg -A 2 "BoundaryTolerance"

Length of output: 66038

Tests/UnitTests/Core/Surfaces/BoundsRegressionTests.cpp Outdated Show resolved Hide resolved
@andiwand
Copy link
Contributor

@paulgessinger can you rebase and change the title?

@paulgessinger paulgessinger changed the title generalize hasTolerance to toleranceMode test: Bounds regression tests Dec 19, 2024
Copy link

github-actions bot commented Dec 19, 2024

📊: Physics performance monitoring for 725a15a

Full contents

physmon summary

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
Core/include/Acts/Surfaces/BoundaryTolerance.hpp (1)

Line range hint 134-138: Documentation for ToleranceMode enum, improve we must.

Clear the purpose is, but documentation for each mode value, missing it is. Add comments to explain when each mode is used and its impact on boundary calculations, we should.

Apply this enhancement, you should:

 enum class ToleranceMode {
-    Extend,  // Extend the boundary
-    None,    // No tolerance
-    Shrink   // Shrink the boundary
+    Extend,  /// Extends the boundary outward by the tolerance value
+    None,    /// No modification to the boundary, exact checks performed
+    Shrink   /// Shrinks the boundary inward by the tolerance value
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eeb3782 and 725a15a.

📒 Files selected for processing (1)
  • Core/include/Acts/Surfaces/BoundaryTolerance.hpp (1 hunks)
🔇 Additional comments (2)
Core/include/Acts/Surfaces/BoundaryTolerance.hpp (2)

90-93: Wisdom in validation, I sense.

Balance in the tolerances, there must be. Either both zero or both non-zero, they should be. Well-crafted error handling, this is.


Line range hint 134-138: Verify the impact of ToleranceMode changes, we must.

From hasTolerance() to toleranceMode(), the path leads. Ensure all callers updated are, we must.

✅ Verification successful

Hmmmm, clear the path forward is. No traces of 'hasTolerance()' remain, I sense.

Through the Force, observed I have:

  • All usages of toleranceMode() properly aligned are
  • No lingering hasTolerance() calls exist in the codebase
  • Test cases updated correctly they are, showing proper usage of new API
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of hasTolerance()
rg "hasTolerance\(\)" 

# Search for new toleranceMode() usage
rg "toleranceMode\(\)"

Length of output: 1916

Copy link
Contributor

@andiwand andiwand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fancy stuff! Great to have this validated and checked against regressions 🚀

@kodiakhq kodiakhq bot merged commit 87439ad into acts-project:main Dec 19, 2024
45 checks passed
@acts-project-service
Copy link
Collaborator

🔴 Athena integration test results [87439ad]

Build job with this PR failed!

Please investigate the build job for the pipeline!

@acts-project-service acts-project-service added the Breaks Athena build This PR breaks the Athena build label Dec 19, 2024
@paulgessinger paulgessinger deleted the boundary-regression-test branch December 19, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaks Athena build This PR breaks the Athena build Component - Core Affects the Core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants