Skip to content

test: add white-box unit tests for Luhn.luhnCheck - #7641

Merged
DenizAltunkapan merged 2 commits into
TheAlgorithms:masterfrom
datpp:test/luhn-white-box-tests
Oct 9, 2026
Merged

DenizAltunkapan merged 2 commits into
TheAlgorithms:masterfrom
datpp:test/luhn-white-box-tests

Conversation

@datpp

@datpp datpp commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Luhn had no test class. This PR adds LuhnTest with white-box tests for Luhn.luhnCheck(int[]).

The method has one loop and two decisions (i % 2 == 0, temp > 9). The tests cover:

  • loop executed zero, one and many times
  • both outcomes of each decision, including boundary values (digit 4 -> 8, digit 5 -> 10)
  • valid and invalid checksums (including single-digit errors in doubled and non-doubled positions)
  • input array is not modified

JaCoCo: 100% instruction and 100% branch coverage for luhnCheck.

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations. (no new algorithm)
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Cover the loop (zero, one and many iterations), both outcomes of the
`i % 2 == 0` and `temp > 9` decisions, boundary values (8 / 10 after
doubling), valid and invalid checksums, input immutability and null input.
@codecov-commenter

codecov-commenter commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.04%. Comparing base (9d9e348) to head (75af89e).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7641      +/-   ##
============================================
+ Coverage     82.00%   82.04%   +0.03%     
- Complexity     8280     8285       +5     
============================================
  Files           840      840              
  Lines         25872    25872              
  Branches       5053     5053              
============================================
+ Hits          21216    21226      +10     
+ Misses         3866     3856      -10     
  Partials        790      790              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Infer reports NULLPTR_DEREFERENCE for passing null to luhnCheck on purpose. The method does not document null handling, so the case is removed.
@datpp
datpp marked this pull request as ready for review October 9, 2026 09:02
@DenizAltunkapan
DenizAltunkapan merged commit cb6f438 into TheAlgorithms:master Oct 9, 2026
7 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.

3 participants