Skip to content

V10.3.1/get statistical region fix#151

Merged
gimlichael merged 2 commits intomainfrom
v10.3.1/get-statistical-region-fix
Feb 25, 2026
Merged

V10.3.1/get statistical region fix#151
gimlichael merged 2 commits intomainfrom
v10.3.1/get-statistical-region-fix

Conversation

@gimlichael
Copy link
Copy Markdown
Member

@gimlichael gimlichael commented Feb 24, 2026

This pull request updates the logic for retrieving statistical region information in the World class and adds comprehensive unit tests to ensure correct behavior for all valid UN M49 codes. The main focus is on improving the robustness and test coverage of the GetStatisticalRegion method.

Improvements to region lookup logic

  • Enhanced the World.GetStatisticalRegion method to check both RegionsByCode and, if not found, fall back to CountriesByCode when looking up a code, ensuring that both regions and countries can be retrieved by their UN M49 code.

Test coverage enhancements

  • Added a parameterized unit test GetStatisticalRegion_ShouldReturnNonNullResult_ForAllUnM49Codes to WorldTest.cs, verifying that GetStatisticalRegion returns a non-null result for a comprehensive list of UN M49 codes, significantly improving test coverage for this method.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced globalization region resolution to support UN M.49 codes with improved input validation and fallback mechanisms.
  • Tests

    • Added extensive test coverage for UN M.49 code resolution across multiple scenarios.

@gimlichael gimlichael self-assigned this Feb 24, 2026
Copilot AI review requested due to automatic review settings February 24, 2026 23:11
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 24, 2026

📝 Walkthrough

Walkthrough

The GetStatisticalRegion method is enhanced to fall back to UN M.49 code resolution from CountriesByCode when not found in RegionsByCode, with added null/empty input validation. Comprehensive parameterized test coverage added for all UN M49 codes.

Changes

Cohort / File(s) Summary
Implementation Enhancement
src/Cuemon.Core/Globalization/World.cs
Modified GetStatisticalRegion method to include fallback lookup of UN M.49 codes from CountriesByCode and added early return for null/empty input validation.
Test Coverage Expansion
test/Cuemon.Core.Tests/Globalization/WorldTest.cs
Added new parameterized test GetStatisticalRegion_ShouldReturnNonNullResult_ForAllUnM49Codes with extensive InlineData covering all UN M49 codes to assert non-null results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

  • V10.3.1/service update #150: Modifies World.cs UN M.49 code handling and region population logic, sharing similar domain focus on statistical region resolution.

Poem

🐰 A fallback path for codes unfound,
Through M.49 lands we now abound,
With tests so thorough, coverage bright,
Regional queries now get it right! 🌍✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references the main change (GetStatisticalRegion fix) but includes a version/branch prefix that adds noise and reduces clarity.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v10.3.1/get-statistical-region-fix

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 and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enhances the World.GetStatisticalRegion method to support both UN M49 region codes and country codes, and adds comprehensive test coverage for all valid UN M49 codes. The change improves the method's robustness by implementing a fallback mechanism that checks the countries dictionary when a code is not found in the regions dictionary.

Changes:

  • Modified GetStatisticalRegion to first check RegionsByCode, then fall back to CountriesByCode if not found
  • Added parameterized unit test covering 249 UN M49 codes to ensure all valid codes return non-null results

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Cuemon.Core/Globalization/World.cs Enhanced GetStatisticalRegion method with fallback logic to check both RegionsByCode and CountriesByCode dictionaries
test/Cuemon.Core.Tests/Globalization/WorldTest.cs Added comprehensive parameterized test with 249 InlineData attributes to verify all UN M49 codes return valid results

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
test/Cuemon.Core.Tests/Globalization/WorldTest.cs (1)

137-416: Consider moving the UN M49 list out of InlineData into a shared data source.

This test is valid, but the very large attribute block is expensive to maintain. A MemberData source keeps the same behavior with easier updates.

♻️ Suggested refactor
-        [Theory]
-        [InlineData("001")]
-        [InlineData("002")]
-        // ... many more InlineData entries ...
-        [InlineData("894")]
+        private static readonly string[] UnM49Codes =
+        {
+            "001",
+            "002",
+            // ... keep the current full list here ...
+            "894"
+        };
+
+        public static IEnumerable<object[]> GetUnM49Codes()
+        {
+            foreach (string code in UnM49Codes)
+            {
+                yield return new object[] { code };
+            }
+        }
+
+        [Theory]
+        [MemberData(nameof(GetUnM49Codes))]
         public void GetStatisticalRegion_ShouldReturnNonNullResult_ForAllUnM49Codes(string code)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/Cuemon.Core.Tests/Globalization/WorldTest.cs` around lines 137 - 416,
The test GetStatisticalRegion_ShouldReturnNonNullResult_ForAllUnM49Codes
contains a huge InlineData block; extract the UN M49 codes into a shared data
provider and switch the test to use MemberData (or ClassData) instead: create a
static IEnumerable<object[]> property or method (e.g. UnM49Codes or UnM49Data)
that yields each code string, update the Theory attribute to
[MemberData(nameof(UnM49Codes), MemberType = typeof(YourTestClassOrHelper))],
and remove the InlineData entries so the test behavior remains identical but the
data list is maintained in one place for easier updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/Cuemon.Core.Tests/Globalization/WorldTest.cs`:
- Around line 137-416: The test
GetStatisticalRegion_ShouldReturnNonNullResult_ForAllUnM49Codes contains a huge
InlineData block; extract the UN M49 codes into a shared data provider and
switch the test to use MemberData (or ClassData) instead: create a static
IEnumerable<object[]> property or method (e.g. UnM49Codes or UnM49Data) that
yields each code string, update the Theory attribute to
[MemberData(nameof(UnM49Codes), MemberType = typeof(YourTestClassOrHelper))],
and remove the InlineData entries so the test behavior remains identical but the
data list is maintained in one place for easier updates.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5dc10dc and 26fb687.

📒 Files selected for processing (2)
  • src/Cuemon.Core/Globalization/World.cs
  • test/Cuemon.Core.Tests/Globalization/WorldTest.cs

@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.68%. Comparing base (32af67f) to head (26fb687).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #151      +/-   ##
==========================================
+ Coverage   80.66%   80.68%   +0.02%     
==========================================
  Files         600      600              
  Lines       18932    18938       +6     
  Branches     1949     1951       +2     
==========================================
+ Hits        15272    15281       +9     
+ Misses       3592     3589       -3     
  Partials       68       68              

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gimlichael gimlichael merged commit 5f70ee9 into main Feb 25, 2026
911 of 913 checks passed
@gimlichael gimlichael deleted the v10.3.1/get-statistical-region-fix branch February 25, 2026 17:01
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