Skip to content

fix(core): toBeOdd fails on negative odd numbers - #209

Open
KeylaMunnoz wants to merge 2 commits into
mainfrom
fix/issue-191-to-be-odd-negative
Open

KeylaMunnoz wants to merge 2 commits into
mainfrom
fix/issue-191-to-be-odd-negative

Conversation

@KeylaMunnoz

Copy link
Copy Markdown
Collaborator

Fixes #191

Description

In JavaScript, the remainder operator (%) retains the sign of the dividend (e.g., -13 % 2 === -1). As a result, NumberAssertion.toBeOdd() was failing for negative odd numbers because it checked this.actual % 2 === 1.

Changes

  • Fixed NumberAssertion.toBeOdd to check Math.abs(this.actual % 2) === 1.
  • Documented parity behavior in JSDoc for both toBeEven and toBeOdd, clarifying that parity applies strictly to integers: non-integers, NaN, and Infinity are neither even nor odd, while 0 and -0 are considered even.
  • Added comprehensive unit tests in NumberAssertion.test.ts covering negative odd numbers (-13), negative even numbers (-2), 0, -0, non-integers (1.5, -1.5), NaN, and Infinity.

This branch has not been deployed

No deployments
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.

toBeOdd fails on negative odd numbers (false pass with .not)

1 participant