Skip to content

BUILD-11114 Add utility math functions#105

Closed
CristianAmbrosini wants to merge 1 commit into
masterfrom
add-utility-functions-20260424
Closed

BUILD-11114 Add utility math functions#105
CristianAmbrosini wants to merge 1 commit into
masterfrom
add-utility-functions-20260424

Conversation

@CristianAmbrosini

Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings April 24, 2026 08:42
@CristianAmbrosini CristianAmbrosini requested a review from a team as a code owner April 24, 2026 08:42
@sonar-review-alpha

sonar-review-alpha Bot commented Apr 24, 2026

Copy link
Copy Markdown

Summary

Adds four utility math functions: multiply(), divide() with zero-check protection, is_even() for parity testing, and clamp() to bound values within a range. These are self-contained helper functions with no external dependencies.

What reviewers should know

Start here: Each function is independent and straightforward — verify the logic matches expected behavior for basic math operations.

Key points:

  • divide() includes a guard clause for division by zero
  • clamp() uses early returns to handle boundary conditions
  • All functions handle their intended use cases without side effects
  • No imports or state management required

Note: The existing add_one() function returns number + 2 (appears intentional or inherited), not number + 1 — unrelated to this PR but worth being aware of.


  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

@CristianAmbrosini

Copy link
Copy Markdown
Author

Mistake

@CristianAmbrosini CristianAmbrosini deleted the add-utility-functions-20260424 branch April 24, 2026 08:44
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Add utility math functions BUILD-11114 Add utility math functions Apr 24, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Apr 24, 2026

Copy link
Copy Markdown

BUILD-11114

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a small set of math utility functions to sonar_dummy_python_oss, expanding the module beyond the existing add_one helper.

Changes:

  • Added multiply(a, b) for multiplication.
  • Added divide(a, b) with a division-by-zero guard.
  • Added is_even(n) and clamp(value, min_val, max_val) helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

divide raises ValueError on division by zero, but native Python division raises ZeroDivisionError. This mismatch can surprise callers who catch ZeroDivisionError (or rely on that standard behavior). Consider raising ZeroDivisionError, or clearly documenting the nonstandard exception type.

Suggested change
raise ValueError("Cannot divide by zero")
raise ZeroDivisionError("Cannot divide by zero")

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +24
def clamp(value, min_val, max_val):
if value < min_val:
return min_val
if value > max_val:
return max_val
return value

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

clamp doesn't validate that min_val <= max_val. If callers pass swapped bounds, the function can return values outside the intended range semantics (or silently mask the error). Consider checking the bound ordering and raising a ValueError when min_val > max_val.

Copilot uses AI. Check for mistakes.
@@ -1,2 +1,24 @@
def add_one(number):
return number + 2

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

add_one currently returns number + 2, which is inconsistent with the function name and will produce incorrect results for callers expecting an increment by 1. Either change the implementation to add 1, or rename the function to reflect the actual behavior.

Suggested change
return number + 2
return number + 1

Copilot uses AI. Check for mistakes.
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