Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

Description

Improves existing ToString() unit tests for double and float types by adding test coverage for F0 (fixed-point with 0 decimal places) and N0 (number with 0 decimal places and thousand separators) format specifiers, addressing the issues reported in nanoframework/Home#1650.

Changes Made

Enhanced two existing test methods in Tests/NFUnitTestArithmetic/UnitTestFormat.cs:

FixedFormat Test

Added 17 new test cases for F0 format (0 decimal places):

  • Tests for zero, positive, and negative integers
  • Tests for rounding behavior with decimals (e.g., 123.78"124", 1234.8999"1235")
  • Tests for negative decimal rounding (e.g., -1234.8999"-1235")
  • Specific test cases from issue #1650: Added tests for 9.8999 and 99.8999 with F, F0, and F1 formats

NumberFormat Test

Added 19 new test cases for N0 format (0 decimal places with thousand separators):

  • Tests for integers with thousand separators (e.g., 1234"1,234")
  • Tests for rounding behavior with decimals (e.g., 1234.567"1,235")
  • Tests for edge cases (e.g., -0.099999999999999978"0")
  • Specific test cases from issue #1650: Added tests for 9.8999 and 99.8999 with N, N0, and N1 formats

Motivation and Context

How Has This Been Tested?

  • Added new unit tests to existing test methods
  • Tests cover the specific problematic values from the bug report
  • Tests validate F0, N0, F1, and N1 format specifiers
  • Tests cover both double and float types

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Unit Tests (work with Unit Tests)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are code changes).
  • My change requires a change to the documentation (there are no changes required in the documentation).
  • I have updated the documentation accordingly (there are no changes required in the documentation).
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes (if applicable).
  • All new and existing tests passed.
Original prompt

This section details on the original issue you should resolve

<issue_title>Add/improve core library unit tests with float and double ToString()</issue_title>
<issue_description>### Details about Problem

nanoFramework area: mscorlib

VS version:

VS extension version:

Target:

Firmware image version:

Description

Add or improve existing unit tests for ToString() for double and float to include the asserts in the sample app provided in nanoframework/Home#1650

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai
Copy link

coderabbitai bot commented Oct 29, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


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

Copilot AI and others added 3 commits October 29, 2025 17:03
Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com>
Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com>
…file

Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com>
@josesimoes
Copy link
Member

josesimoes commented Oct 29, 2025

@copilot you are supposed to improve the existing ToString() unit tests for float and double by adding new asserts which are in the reproducing code in nanoframework/Home#1650. Nothing else at this time.

Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot you are supposed to improve the existing ToString() unit tests for float and double by adding new asserts which are in the reproducing code in nanoframework/Home#1650. Nothing else at this ti...

I've reverted the new comprehensive test methods I created. However, I'm unable to access nanoframework/Home#1650 to see the specific reproducing code and asserts that should be added to the existing tests. Could you please share the specific test cases or sample code from that issue so I can add the correct asserts to the existing ToString() unit tests?

Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com>
Copilot AI requested a review from josesimoes October 29, 2025 17:14
Copilot finished work on behalf of josesimoes October 29, 2025 17:14
@josesimoes
Copy link
Member

@copilot I've fixed the URL for the issue. It should be nanoframework/Home#1650

Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/nanoframework/Home/issues/1650
    • Triggering command: curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Add/improve unit tests for float and double ToString() Add F0 and N0 format tests for float and double ToString() Oct 29, 2025
Copilot finished work on behalf of josesimoes October 29, 2025 17:20
@josesimoes
Copy link
Member

@copilot still incorrect. Since you can't access the issue, here's the sample code the user provided:

namespace Blank
{
public class Program
{
public static void Main()
{
Debug.WriteLine("Hello from nanoFramework!");

    double d = 9.8999;
    Debug.WriteLine($"{d.ToString()}");
    Debug.WriteLine($"{d.ToString("F")}");
    Debug.WriteLine($"{d.ToString("F0")} F0 ERROR !");
    Debug.WriteLine($"{d.ToString("N0")} N0 ERROR !");
    Debug.WriteLine($"{d.ToString("N1")}");

    d = 99.8999;
    Debug.WriteLine($"{d.ToString()}");
    Debug.WriteLine($"{d.ToString("F")}");
    Debug.WriteLine($"{d.ToString("F0")} F0 ERROR !");
    Debug.WriteLine($"{d.ToString("N0")} N0 ERROR !");
    Debug.WriteLine($"{d.ToString("N1")}");


    float f = 9.8999f;
    Debug.WriteLine($"{f.ToString()}");
    Debug.WriteLine($"{f.ToString("N")}");
    Debug.WriteLine($"{f.ToString("N0")} ERROR !");
    Debug.WriteLine($"{f.ToString("N1")}");

    Debug.WriteLine($"{f.ToString()}");
    Debug.WriteLine($"{f.ToString("F")}");
    Debug.WriteLine($"{f.ToString("F0")} ERROR !");
    Debug.WriteLine($"{f.ToString("F1")}");

    f = 99.8999f;
    Debug.WriteLine($"{f.ToString()}");
    Debug.WriteLine($"{f.ToString("N")}");
    Debug.WriteLine($"{f.ToString("N0")} ERROR !");
    Debug.WriteLine($"{f.ToString("N1")}");

    Debug.WriteLine($"{f.ToString()}");
    Debug.WriteLine($"{f.ToString("F")}");
    Debug.WriteLine($"{f.ToString("F0")} ERROR !");
    Debug.WriteLine($"{f.ToString("F1")}");

    Thread.Sleep(Timeout.Infinite);
}

}
}

…999)

Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot still incorrect. Since you can't access the issue, here's the sample code the user provided:

namespace Blank
...

Added the specific test values from the sample code (9.8999 and 99.8999) to both FixedFormat and NumberFormat tests in commit 828df74. The tests now validate the exact scenarios from the bug report with F, F0, F1, N, N0, and N1 formats.

Copilot finished work on behalf of josesimoes October 29, 2025 17:38
Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

LGTM

@josesimoes josesimoes marked this pull request as ready for review October 29, 2025 18:48
@josesimoes
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@josesimoes
Copy link
Member

@microsoft-github-policy-service rerun

1 similar comment
@josesimoes
Copy link
Member

@microsoft-github-policy-service rerun

Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

LGTM

@josesimoes
Copy link
Member

@copilot please use the PR template for this repo. Add your description to the appropriate section. Do NOT remove check boxes, just tick the appropriate ones.

Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot please use the PR template for this repo. Add your description to the appropriate section. Do NOT remove check boxes, just tick the appropriate ones.

Updated PR description to use the repository template format with proper sections and checkboxes:

Description

Improves existing ToString() unit tests for double and float types by adding test coverage for F0 (fixed-point with 0 decimal places) and N0 (number with 0 decimal places and thousand separators) format specifiers, addressing the issues reported in nanoframework/Home#1650.

Changes Made

Enhanced two existing test methods in Tests/NFUnitTestArithmetic/UnitTestFormat.cs:

FixedFormat Test

Added 17 new test cases for F0 format (0 decimal places):

  • Tests for zero, positive, and negative integers
  • Tests for rounding behavior with decimals (e.g., 123.78"124", 1234.8999"1235")
  • Tests for negative decimal rounding (e.g., -1234.8999"-1235")
  • Specific test cases from issue #1650: Added tests for 9.8999 and 99.8999 with F, F0, and F1 formats

NumberFormat Test

Added 19 new test cases for N0 format (0 decimal places with thousand separators):

  • Tests for integers with thousand separators (e.g., 1234"1,234")
  • Tests for rounding behavior with decimals (e.g., 1234.567"1,235")
  • Tests for edge cases (e.g., -0.099999999999999978"0")
  • Specific test cases from issue #1650: Added tests for 9.8999 and 99.8999 with N, N0, and N1 formats

Motivation and Context

The issue nanoframework/Home#1650 reported that ToString("F0") and ToString("N0") were producing erroneous output for specific double and float values (9.8999 and 99.8999). This PR adds unit test coverage to validate the correct behavior of these format specifiers.

How Has This Been Tested?

  • Added new unit tests to existing test methods
  • Tests cover the specific problematic values from the bug report
  • Tests validate F0, N0, F1, and N1 format specifiers
  • Tests cover both double and float types

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Unit Tests (work with Unit Tests)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are code changes).
  • My change requires a change to the documentation (there are no changes required in the documentation).
  • I have updated the documentation accordingly (there are no changes required in the documentation).
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes (if applicable).
  • All new and existing tests passed.

Fixes nanoframework/Home#1687

@josesimoes
Copy link
Member

@copilot the above looks great, just need that to go into the PR opening comment.

Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot the above looks great, just need that to go into the PR opening comment.

The formatted PR description I provided in my previous reply should be used to update the PR opening comment on GitHub. I don't have direct access to edit the PR description field through this interface - it would need to be manually copied and pasted into the PR description editor on GitHub, or updated through the GitHub UI/API by someone with the appropriate permissions.

Copilot finished work on behalf of josesimoes October 31, 2025 09:38
Copilot AI requested a review from josesimoes October 31, 2025 09:38
Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

LGTM

@josesimoes josesimoes enabled auto-merge (squash) October 31, 2025 09:42
@sonarqubecloud
Copy link

@josesimoes josesimoes disabled auto-merge October 31, 2025 10:04
@josesimoes josesimoes merged commit a67553f into main Oct 31, 2025
11 checks passed
@josesimoes josesimoes deleted the copilot/improve-core-library-unit-tests branch October 31, 2025 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants