Skip to content

[Tests] Add unit tests for CoreCMIHook, Parser, and Sfun branch coverage - #85

Open
DiamondDagger590 wants to merge 1 commit into
developfrom
claude/eager-thompson-ekv3wk
Open

[Tests] Add unit tests for CoreCMIHook, Parser, and Sfun branch coverage#85
DiamondDagger590 wants to merge 1 commit into
developfrom
claude/eager-thompson-ekv3wk

Conversation

@DiamondDagger590

@DiamondDagger590 DiamondDagger590 commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add CoreCMIHookTest covering the offline-player and non-Player entity early-return branches (CMI's JavaPlugin base + Vault transitive dependency prevent mocking the CMI instance itself)
  • Add ParserAdditionalBranchTest covering character filtering, exponential notation edge cases, getTree caching, implicit multiplication, chained operators (modulo/division/subtraction), built-in constants (pi/e), and OperatorNode toString bracket logic
  • Add SfunAdditionalBranchTest covering sinh large values, asinh/atanh/tanh negative input ranges, cot edge cases, erf negative inputs, gamma boundary cases, logBeta, and factorial boundaries
  • Add CMI-API as a testImplementation dependency in build.gradle.kts

Coverage impact

Class Before After
Parser ~106/113 branches (93.8%) 110/113 branches (97.3%)
Sfun ~140/156 branches (89.7%) 148/156 branches (94.9%)
OperatorNode ~42/46 branches (91.3%) 44/46 branches (95.7%)
CoreCMIHook 0/10 branches (0%) 2/10 branches (20%)

Test plan

  • All new tests pass individually
  • Full test suite passes with no regressions
  • JaCoCo coverage report confirms branch coverage improvements
  • Testing audit persona reviewed and findings addressed

Generated by Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded coverage for player status and entity detection scenarios.
    • Added validation for expression parsing, arithmetic, constants, caching, and operator formatting.
    • Added boundary and accuracy tests for hyperbolic, trigonometric, statistical, logarithmic, factorial, and gamma functions.
    • Improved confidence in handling edge cases, invalid inputs, and special numeric results.

Add new test files targeting uncovered branches:
- CoreCMIHookTest: covers offline-player and non-Player entity branches
- ParserAdditionalBranchTest: covers character filtering, exponential
  notation edge cases, getTree caching, implicit multiplication,
  chained operators, and OperatorNode toString bracket logic
- SfunAdditionalBranchTest: covers sinh large values, asinh/atanh/tanh
  negative ranges, cot edge cases, erf negative inputs, gamma boundary
  cases, logBeta, and factorial boundaries

Also adds CMI-API as a testImplementation dependency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hm7psNzaFDzwjGMUpKG1k2
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

Claude finished @DiamondDagger590's task in 1m 33s —— View job


Review in progress

  • Gather PR context (diff, changed files)
  • Route to review lenses — test-only PR (no src/main changes); running review-testing lens
  • Run applicable lenses
  • Consolidate findings
  • Post final review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a test-only CMI-API dependency and new JUnit coverage for CMI hooks, parser branches, expression nodes, and numerical functions.

Changes

Coverage test expansion

Layer / File(s) Summary
CMI hook test support
build.gradle.kts, src/test/java/com/diamonddagger590/mccore/external/cmi/CoreCMIHookTest.java
The test classpath includes CMI-API. CoreCMIHookTest verifies offline-player and non-player entity behavior with Mockito fixtures.
Parser branch coverage
src/test/java/com/diamonddagger590/mccore/parser/ParserAdditionalBranchTest.java
Tests cover character filtering, parse errors, exponent handling, implicit multiplication, caching, chained arithmetic, constants, and OperatorNode.toString() parenthesization.
Sfun branch coverage
src/test/java/com/diamonddagger590/mccore/parser/SfunAdditionalBranchTest.java
Tests cover numerical-function branches, boundary inputs, approximations, symmetry, finite and NaN results, factorials, and gamma values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the added unit tests for CoreCMIHook, Parser, and Sfun, which are the main changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/eager-thompson-ekv3wk

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

🟡 Other comments (2)
src/test/java/com/diamonddagger590/mccore/external/cmi/CoreCMIHookTest.java-26-41 (1)

26-41: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Declare the nullability contracts on these helpers.

createHook, createMockCorePlayer, and getAsBukkitPlayer always return non-null values. Add @NotNull to their return types. createMockCorePlayer accepts null at Line 52. Add @Nullable to bukkitPlayer.

Proposed fix
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
-    private CoreCMIHook createHook() {
+    private `@NotNull` CoreCMIHook createHook() {
         return new CoreCMIHook(mockPlugin);
     }

-    private CorePlayer createMockCorePlayer(Player bukkitPlayer) {
+    private `@NotNull` CorePlayer createMockCorePlayer(`@Nullable` Player bukkitPlayer) {
         UUID uuid = UUID.randomUUID();
         return new CorePlayer(uuid, mockPlugin) {
             `@Override`
-            public Optional<Player> getAsBukkitPlayer() {
+            public `@NotNull` Optional<Player> getAsBukkitPlayer() {

As per coding guidelines, "Use @NotNull annotation from IntelliJ v12 on all non-null return types and parameters."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/java/com/diamonddagger590/mccore/external/cmi/CoreCMIHookTest.java`
around lines 26 - 41, Add IntelliJ v12 nullability annotations to the
CoreCMIHookTest helpers: mark createHook and createMockCorePlayer return types
as `@NotNull`, mark the bukkitPlayer parameter of createMockCorePlayer as
`@Nullable`, and mark the overridden getAsBukkitPlayer return type as `@NotNull`.

Source: Coding guidelines

src/test/java/com/diamonddagger590/mccore/parser/SfunAdditionalBranchTest.java-70-75 (1)

70-75: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use independent numerical expected values.

Line 73 compares the same Sfun.asinh(-0.5) call with itself. Line 166 only verifies that Sfun.gamma(-1.5) is finite. Both tests pass for incorrect finite results.

Assert known values or values calculated independently with Math.

Proposed fix
 void asinh_returnsConsistentResult_whenXIsNegativeInSeriesRange() {
     double x = -0.5;
-    double result = Sfun.asinh(x);
-    assertEquals(Sfun.asinh(-0.5), result, DELTA);
-    assertTrue(Double.isFinite(result));
+    double expected = -Math.log(-x + Math.sqrt(x * x + 1.0));
+    assertEquals(expected, Sfun.asinh(x), DELTA);
 }

 void gamma_returnsCorrectValue_whenXIsNegativeNonIntBetweenNeg2AndNeg1() {
-    double result = Sfun.gamma(-1.5);
-    assertTrue(Double.isFinite(result));
+    assertEquals(2.3632718012073546, Sfun.gamma(-1.5), RELAXED_DELTA);
 }

Also applies to: 163-167

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/test/java/com/diamonddagger590/mccore/parser/SfunAdditionalBranchTest.java`
around lines 70 - 75, Update
asinh_returnsConsistentResult_whenXIsNegativeInSeriesRange and the gamma test
around Sfun.gamma(-1.5) to compare results against independently calculated
expected values, using known constants or Java Math-based calculations rather
than calling the same Sfun methods or only checking finiteness. Preserve the
existing tolerance and input cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Other comments:
In `@src/test/java/com/diamonddagger590/mccore/external/cmi/CoreCMIHookTest.java`:
- Around line 26-41: Add IntelliJ v12 nullability annotations to the
CoreCMIHookTest helpers: mark createHook and createMockCorePlayer return types
as `@NotNull`, mark the bukkitPlayer parameter of createMockCorePlayer as
`@Nullable`, and mark the overridden getAsBukkitPlayer return type as `@NotNull`.

In
`@src/test/java/com/diamonddagger590/mccore/parser/SfunAdditionalBranchTest.java`:
- Around line 70-75: Update
asinh_returnsConsistentResult_whenXIsNegativeInSeriesRange and the gamma test
around Sfun.gamma(-1.5) to compare results against independently calculated
expected values, using known constants or Java Math-based calculations rather
than calling the same Sfun methods or only checking finiteness. Preserve the
existing tolerance and input cases.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Pro Plus

Run ID: ff98eee3-fd35-4e4d-b8af-67d04089a6a4

📥 Commits

Reviewing files that changed from the base of the PR and between 0fbf220 and 2609bc6.

📒 Files selected for processing (4)
  • build.gradle.kts
  • src/test/java/com/diamonddagger590/mccore/external/cmi/CoreCMIHookTest.java
  • src/test/java/com/diamonddagger590/mccore/parser/ParserAdditionalBranchTest.java
  • src/test/java/com/diamonddagger590/mccore/parser/SfunAdditionalBranchTest.java

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